Same filename and directory in other branches
- 8.9.x core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php
- 9 core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php
Namespace
Drupal\Tests\block_content\Kernel
File
core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php
View source
<?php
namespace Drupal\Tests\block_content\Kernel;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\Component\Plugin\PluginBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\block\Traits\BlockCreationTrait;
class BlockContentDeletionTest extends KernelTestBase {
use BlockCreationTrait;
protected static $modules = [
'block',
'block_content',
'system',
'user',
];
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('block_content');
$this->container
->get('theme_installer')
->install([
'stark',
]);
}
public function testDeletingBlockContentShouldClearPluginCache() {
$block_content_type = BlockContentType::create([
'id' => 'spiffy',
'label' => 'Mucho spiffy',
'description' => "Provides a block type that increases your site's spiffiness by upto 11%",
]);
$block_content_type
->save();
$block_content = BlockContent::create([
'info' => 'Spiffy prototype',
'type' => 'spiffy',
]);
$block_content
->save();
$block_manager = $this->container
->get('plugin.manager.block');
$plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content
->uuid();
$this
->assertTrue($block_manager
->hasDefinition($plugin_id));
$block_content
->delete();
$this
->assertFalse($block_manager
->hasDefinition($plugin_id));
$block_content = BlockContent::create([
'info' => 'Spiffy prototype',
'type' => 'spiffy',
]);
$block_content
->save();
$plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content
->uuid();
$block = $this
->placeBlock($plugin_id, [
'region' => 'content',
'theme' => 'stark',
]);
$storage = $this->container
->get('entity_type.manager')
->getStorage('block_content');
$storage
->delete([
$block_content,
]);
$this
->assertFalse($block_manager
->hasDefinition($plugin_id));
$this
->assertNull($this->container
->get('entity_type.manager')
->getStorage('block')
->loadUnchanged($block
->id()));
}
}
Classes