3 namespace Drupal\Tests\block_content\Kernel;
5 use Drupal\block_content\Entity\BlockContent;
6 use Drupal\block_content\Entity\BlockContentType;
7 use Drupal\Component\Plugin\PluginBase;
8 use Drupal\KernelTests\KernelTestBase;
11 * Tests that deleting a block clears the cached definitions.
13 * @group block_content
15 class BlockContentDeletionTest extends KernelTestBase {
20 public static $modules = ['block', 'block_content', 'system', 'user'];
25 public function setUp() {
27 $this->installSchema('system', ['sequence']);
28 $this->installEntitySchema('user');
29 $this->installEntitySchema('block_content');
33 * Tests deleting a block_content updates the discovered block plugin.
35 public function testDeletingBlockContentShouldClearPluginCache() {
36 // Create a block content type.
37 $block_content_type = BlockContentType::create([
39 'label' => 'Mucho spiffy',
40 'description' => "Provides a block type that increases your site's spiffiness by upto 11%",
42 $block_content_type->save();
43 // And a block content entity.
44 $block_content = BlockContent::create([
45 'info' => 'Spiffy prototype',
48 $block_content->save();
50 // Make sure the block content provides a derivative block plugin in the
52 /** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */
53 $block_manager = $this->container->get('plugin.manager.block');
54 $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid();
55 $this->assertTrue($block_manager->hasDefinition($plugin_id));
57 // Now delete the block content entity.
58 $block_content->delete();
59 // The plugin should no longer exist.
60 $this->assertFalse($block_manager->hasDefinition($plugin_id));