function NodeTypeTest::testNodeTypeDeletion in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Tests/NodeTypeTest.php \Drupal\node\Tests\NodeTypeTest::testNodeTypeDeletion()
Tests deleting a content type that still has content.
File
- core/
modules/ node/ src/ Tests/ NodeTypeTest.php, line 139 - Contains \Drupal\node\Tests\NodeTypeTest.
Class
- NodeTypeTest
- Ensures that node type functions work correctly.
Namespace
Drupal\node\TestsCode
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
->id(),
));
// Attempt to delete the content type, which should not be allowed.
$this
->drupalGet('admin/structure/types/manage/' . $type
->label() . '/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
->label(),
)), '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
->label() . '/delete');
$this
->assertRaw(t('Are you sure you want to delete the content type %type?', array(
'%type' => $type
->label(),
)), 'The content type is available for deletion.');
$this
->assertText(t('This action cannot be undone.'), 'The node type deletion confirmation form is available.');
// Test that a locked node type could not be deleted.
$this->container
->get('module_installer')
->install(array(
'node_test_config',
));
// Lock the default node type.
$locked = \Drupal::state()
->get('node.type.locked');
$locked['default'] = 'default';
\Drupal::state()
->set('node.type.locked', $locked);
// Call to flush all caches after installing the forum module in the same
// way installing a module through the UI does.
$this
->resetAll();
$this
->drupalGet('admin/structure/types/manage/default');
$this
->assertNoLink(t('Delete'));
$this
->drupalGet('admin/structure/types/manage/default/delete');
$this
->assertResponse(403);
$this->container
->get('module_installer')
->uninstall(array(
'node_test_config',
));
$this->container = \Drupal::getContainer();
unset($locked['default']);
\Drupal::state()
->set('node.type.locked', $locked);
$this
->drupalGet('admin/structure/types/manage/default');
$this
->clickLink(t('Delete'));
$this
->assertResponse(200);
$this
->drupalPostForm(NULL, array(), t('Delete'));
$this
->assertFalse((bool) NodeType::load('default'), 'Node type with machine default deleted.');
}