protected function BlockStorageUnitTest::createTests in Drupal 9
Same name and namespace in other branches
- 8 core/modules/block/tests/src/Kernel/BlockStorageUnitTest.php \Drupal\Tests\block\Kernel\BlockStorageUnitTest::createTests()
- 10 core/modules/block/tests/src/Kernel/BlockStorageUnitTest.php \Drupal\Tests\block\Kernel\BlockStorageUnitTest::createTests()
Tests the creation of blocks.
1 call to BlockStorageUnitTest::createTests()
- BlockStorageUnitTest::testBlockCRUD in core/
modules/ block/ tests/ src/ Kernel/ BlockStorageUnitTest.php - Tests CRUD operations.
File
- core/
modules/ block/ tests/ src/ Kernel/ BlockStorageUnitTest.php, line 56
Class
- BlockStorageUnitTest
- Tests the storage of blocks.
Namespace
Drupal\Tests\block\KernelCode
protected function createTests() {
// Attempt to create a block without a plugin.
try {
$entity = $this->controller
->create([]);
$entity
->getPlugin();
$this
->fail('A block without a plugin was created with no exception thrown.');
} catch (PluginException $e) {
$this
->assertEquals('The block \'\' did not specify a plugin.', $e
->getMessage(), 'An exception was thrown when a block was created without a plugin.');
}
// Create a block with only required values.
$entity = $this->controller
->create([
'id' => 'test_block',
'theme' => 'stark',
'region' => 'content',
'plugin' => 'test_html',
]);
$entity
->save();
$this
->assertInstanceOf(Block::class, $entity);
// Verify all of the block properties.
$actual_properties = $this
->config('block.block.test_block')
->get();
$this
->assertTrue(!empty($actual_properties['uuid']), 'The block UUID is set.');
unset($actual_properties['uuid']);
// Ensure that default values are filled in.
$expected_properties = [
'langcode' => \Drupal::languageManager()
->getDefaultLanguage()
->getId(),
'status' => TRUE,
'dependencies' => [
'module' => [
'block_test',
],
'theme' => [
'stark',
],
],
'id' => 'test_block',
'theme' => 'stark',
'region' => 'content',
'weight' => NULL,
'provider' => NULL,
'plugin' => 'test_html',
'settings' => [
'id' => 'test_html',
'label' => '',
'provider' => 'block_test',
'label_display' => BlockPluginInterface::BLOCK_LABEL_VISIBLE,
],
'visibility' => [],
];
$this
->assertSame($expected_properties, $actual_properties);
$this
->assertInstanceOf(TestHtmlBlock::class, $entity
->getPlugin());
}