function BlockContentTypeTest::testBlockContentTypeDeletion

Same name and namespace in other branches
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeDeletion()
  2. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeDeletion()
  3. 10 core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeDeletion()

Tests deleting a block type that still has content.

File

core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php, line 177

Class

BlockContentTypeTest
Ensures that block type functions work correctly.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testBlockContentTypeDeletion() : void {
    // Now create an initial block-type.
    $this->createBlockContentType('basic', TRUE);
    // Create a block type programmatically.
    $type = $this->createBlockContentType('foo');
    $this->drupalLogin($this->adminUser);
    // Add a new block of this type.
    $block = $this->createBlockContent(FALSE, 'foo');
    // Attempt to delete the block type, which should not be allowed.
    $this->drupalGet('admin/structure/block-content/manage/' . $type->id() . '/delete');
    $this->assertSession()
        ->pageTextContains($type->label() . ' is used by 1 content block on your site. You can not remove this block type until you have removed all of the ' . $type->label() . ' blocks.');
    $this->assertSession()
        ->pageTextNotContains('This action cannot be undone.');
    // Delete the block.
    $block->delete();
    // Attempt to delete the block type, which should now be allowed.
    $this->drupalGet('admin/structure/block-content/manage/' . $type->id() . '/delete');
    $this->assertSession()
        ->pageTextContains('Are you sure you want to delete the block type ' . $type->id() . '?');
    $this->assertSession()
        ->pageTextContains('This action cannot be undone.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.