You are here

public function BlockContentCreationTest::testBlockContentCreation in Zircon Profile 8

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

Creates a "Basic page" block and verifies its consistency in the database.

File

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

Class

BlockContentCreationTest
Create a block and test saving it.

Namespace

Drupal\block_content\Tests

Code

public function testBlockContentCreation() {
  $this
    ->drupalLogin($this->adminUser);

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

  // Check that the Basic block has been created.
  $this
    ->assertRaw(format_string('@block %name has been created.', array(
    '@block' => 'basic',
    '%name' => $edit['info[0][value]'],
  )), 'Basic block created.');

  // Check that the view mode setting is hidden because only one exists.
  $this
    ->assertNoFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting hidden because only one exists');

  // Check that the block exists in the database.
  $blocks = entity_load_multiple_by_properties('block_content', array(
    'info' => $edit['info[0][value]'],
  ));
  $block = reset($blocks);
  $this
    ->assertTrue($block, 'Custom Block found in database.');

  // Check that attempting to create another block with the same value for
  // 'info' returns an error.
  $this
    ->drupalPostForm('block/add/basic', $edit, t('Save'));

  // Check that the Basic block has been created.
  $this
    ->assertRaw(format_string('A custom block with block description %value already exists.', array(
    '%value' => $edit['info[0][value]'],
  )));
  $this
    ->assertResponse(200);
}