From 292a4c56a84eaaab6dfdb9df74c9afb46f2b7d77 Mon Sep 17 00:00:00 2001 From: catch Date: Wed, 15 Aug 2012 15:22:38 +0100 Subject: [PATCH] Issue #232327 by tizzo, jhedstrom, sumitk, NicolasH, disasm, tim.plunkett: Fixed Deleting node type leaves orphan nodes. --- core/modules/node/content_types.inc | 8 ++-- .../lib/Drupal/node/Tests/NodeTypeTest.php | 42 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index ede377704f2..88495f466b1 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -446,14 +446,16 @@ function node_type_delete_confirm($form, &$form_state, $type) { $form['name'] = array('#type' => 'value', '#value' => $type->name); $message = t('Are you sure you want to delete the content type %type?', array('%type' => $type->name)); - $caption = ''; $num_nodes = db_query("SELECT COUNT(*) FROM {node} WHERE type = :type", array(':type' => $type->type))->fetchField(); if ($num_nodes) { - $caption .= '

' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. If you remove this content type, you will not be able to edit the %type content and it may not display correctly.', '%type is used by @count pieces of content on your site. If you remove %type, you will not be able to edit the %type content and it may not display correctly.', array('%type' => $type->name)) . '

'; + drupal_set_title($message, PASS_THROUGH); + $caption = '

' . format_plural($num_nodes, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', array('%type' => $type->name)) . '

'; + $form['description'] = array('#markup' => $caption); + return $form; } - $caption .= '

' . t('This action cannot be undone.') . '

'; + $caption = '

' . t('This action cannot be undone.') . '

'; return confirm_form($form, $message, 'admin/structure/types', $caption, t('Delete')); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index a2ef01aac5b..bf925c4c88e 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php @@ -167,4 +167,46 @@ class NodeTypeTest extends NodeTestBase { $this->assertTrue(isset($types[$type]->disabled) && empty($types[$type]->disabled), t('%type type is enabled.', array('%type' => $type))); } } + + /** + * Tests deleting a content type that still has content. + */ + function testNodeTypeDeletion() { + // Create a content type programmatically. + $type = $this->drupalCreateContentType(); + + // Log in a test user. + $web_user = $this->drupalCreateUser(array( + 'bypass node access', + 'administer content types', + )); + $this->drupalLogin($web_user); + + // Add a new node of this type. + $node = $this->drupalCreateNode(array('type' => $type->type)); + // Attempt to delete the content type, which should not be allowed. + $this->drupalGet('admin/structure/types/manage/' . $type->name . '/delete'); + $this->assertRaw( + t( + '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', + array('%type' => $type->name) + ), + 'The content type will not be deleted until all nodes of that type are removed.' + ); + $this->assertNoText(t('This action cannot be undone.'), 'The node type deletion confirmation form is not available.'); + + // Delete the node. + $node->delete(); + // Attempt to delete the content type, which should now be allowed. + $this->drupalGet('admin/structure/types/manage/' . $type->name . '/delete'); + $this->assertRaw( + t( + 'Are you sure you want to delete the content type %type?', + array('%type' => $type->name) + ), + 'The content type is available for deletion.' + ); + $this->assertText(t('This action cannot be undone.'), 'The node type deletion confirmation form is available.'); + } + }