You are here

public function BlockContentCreationTest::testBlockDelete in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/block_content/src/Tests/BlockContentCreationTest.php \Drupal\block_content\Tests\BlockContentCreationTest::testBlockDelete()

Test deleting a block.

File

core/modules/block_content/src/Tests/BlockContentCreationTest.php, line 230
Contains \Drupal\block_content\Tests\BlockContentCreationTest.

Class

BlockContentCreationTest
Create a block and test saving it.

Namespace

Drupal\block_content\Tests

Code

public function testBlockDelete() {

  // Create a block.
  $edit = array();
  $edit['info[0][value]'] = $this
    ->randomMachineName(8);
  $body = $this
    ->randomMachineName(16);
  $edit['body[0][value]'] = $body;
  $this
    ->drupalPostForm('block/add/basic', $edit, t('Save'));

  // Place the block.
  $instance = array(
    'id' => Unicode::strtolower($edit['info[0][value]']),
    'settings[label]' => $edit['info[0][value]'],
    'region' => 'sidebar_first',
  );
  $block = BlockContent::load(1);
  $url = 'admin/structure/block/add/block_content:' . $block
    ->uuid() . '/' . $this
    ->config('system.theme')
    ->get('default');
  $this
    ->drupalPostForm($url, $instance, t('Save block'));
  $block = BlockContent::load(1);

  // Test getInstances method.
  $this
    ->assertEqual(1, count($block
    ->getInstances()));

  // Navigate to home page.
  $this
    ->drupalGet('');
  $this
    ->assertText($body);

  // Delete the block.
  $this
    ->drupalGet('block/1/delete');
  $this
    ->assertText(\Drupal::translation()
    ->formatPlural(1, 'This will also remove 1 placed block instance.', 'This will also remove @count placed block instance.'));
  $this
    ->drupalPostForm(NULL, array(), 'Delete');
  $this
    ->assertRaw(t('The custom block %name has been deleted.', array(
    '%name' => $edit['info[0][value]'],
  )));

  // Create another block and force the plugin cache to flush.
  $edit2 = array();
  $edit2['info[0][value]'] = $this
    ->randomMachineName(8);
  $body2 = $this
    ->randomMachineName(16);
  $edit2['body[0][value]'] = $body2;
  $this
    ->drupalPostForm('block/add/basic', $edit2, t('Save'));
  $this
    ->assertNoRaw('Error message');

  // Create another block with no instances, and test we don't get a
  // confirmation message about deleting instances.
  $edit3 = array();
  $edit3['info[0][value]'] = $this
    ->randomMachineName(8);
  $body = $this
    ->randomMachineName(16);
  $edit3['body[0][value]'] = $body;
  $this
    ->drupalPostForm('block/add/basic', $edit3, t('Save'));

  // Show the delete confirm form.
  $this
    ->drupalGet('block/3/delete');
  $this
    ->assertNoText('This will also remove');
}