You are here

public function BlockContentCreationTest::testDefaultBlockContentCreation in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testDefaultBlockContentCreation()

Create a default custom block.

Creates a custom block from defaults and ensures that the 'basic block' type is being used.

File

core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php, line 176

Class

BlockContentCreationTest
Create a block and test saving it.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testDefaultBlockContentCreation() {
  $edit = [];
  $edit['info[0][value]'] = $this
    ->randomMachineName(8);
  $edit['body[0][value]'] = $this
    ->randomMachineName(16);

  // Don't pass the custom block type in the url so the default is forced.
  $this
    ->drupalPostForm('block/add', $edit, t('Save'));

  // Check that the block has been created and that it is a basic block.
  $this
    ->assertRaw(new FormattableMarkup('@block %name has been created.', [
    '@block' => 'basic',
    '%name' => $edit['info[0][value]'],
  ]), 'Basic block created.');

  // Check that the block exists in the database.
  $blocks = \Drupal::entityTypeManager()
    ->getStorage('block_content')
    ->loadByProperties([
    'info' => $edit['info[0][value]'],
  ]);
  $block = reset($blocks);
  $this
    ->assertNotEmpty($block, 'Default Custom Block found in database.');
}