You are here

public function BlockContentTypeTest::testBlockContentTypeDeletion in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block_content/src/Tests/BlockContentTypeTest.php \Drupal\block_content\Tests\BlockContentTypeTest::testBlockContentTypeDeletion()

Tests deleting a block type that still has content.

File

core/modules/block_content/src/Tests/BlockContentTypeTest.php, line 140
Contains \Drupal\block_content\Tests\BlockContentTypeTest.

Class

BlockContentTypeTest
Ensures that custom block type functions work correctly.

Namespace

Drupal\block_content\Tests

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.', array(
    '%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?', array(
    '%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.');
}