public function BlockContentCreationTest::testDefaultBlockContentCreation in Drupal 9
Same name and namespace in other branches
- 8 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 171
Class
- BlockContentCreationTest
- Create a block and test saving it.
Namespace
Drupal\Tests\block_content\FunctionalCode
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
->drupalGet('block/add');
$this
->submitForm($edit, 'Save');
// Check that the block has been created and that it is a basic block.
$this
->assertSession()
->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been 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.');
}