function BlockContentTypeTest::testBlockContentTypeDeletion

Same name and namespace in other branches
  1. 11.x core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeDeletion()
  2. 10 core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeDeletion()
  3. 9 core/modules/block_content/tests/src/Functional/BlockContentTypeTest.php \Drupal\Tests\block_content\Functional\BlockContentTypeTest::testBlockContentTypeDeletion()
  4. main 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 151

Class

BlockContentTypeTest
Ensures that custom block type functions work correctly.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testBlockContentTypeDeletion() {
  // 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/block-content/manage/' . $type->id() . '/delete');
  $this->assertRaw(t('%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', [
    '%label' => $type->label(),
  ]), 'The block type will not be deleted until all blocks of that type are removed.');
  $this->assertNoText(t('This action cannot be undone.'), 'The block type deletion confirmation form is not available.');
  // Delete the block.
  $block->delete();
  // Attempt to delete the block type, which should now be allowed.
  $this->drupalGet('admin/structure/block/block-content/manage/' . $type->id() . '/delete');
  $this->assertRaw(t('Are you sure you want to delete the custom block type %type?', [
    '%type' => $type->id(),
  ]), 'The block type is available for deletion.');
  $this->assertText(t('This action cannot be undone.'), 'The custom block type deletion confirmation form is available.');
}

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