public function CustomBlockCreationTest::testCustomBlockCreation

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

File

drupal/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php, line 49
Contains \Drupal\custom_block\Tests\CustomBlockCreationTest.

Class

CustomBlockCreationTest
Tests creating and saving a block.

Namespace

Drupal\custom_block\Tests

Code

public function testCustomBlockCreation() {

  // Create a block.
  $edit = array();
  $langcode = Language::LANGCODE_NOT_SPECIFIED;
  $edit['info'] = $this
    ->randomName(8);
  $edit["block_body[{$langcode}][0][value]"] = $this
    ->randomName(16);
  $this
    ->drupalPost('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 block',
    '%name' => $edit["info"],
  )), 'Basic block created.');

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