Pull merge.
[yaffs-website] / web / core / modules / block_content / tests / src / Kernel / BlockContentDeletionTest.php
1 <?php
2
3 namespace Drupal\Tests\block_content\Kernel;
4
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;
9
10 /**
11  * Tests that deleting a block clears the cached definitions.
12  *
13  * @group block_content
14  */
15 class BlockContentDeletionTest extends KernelTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['block', 'block_content', 'system', 'user'];
21
22   /**
23    * {@inheritdoc}
24    */
25   public function setUp() {
26     parent::setUp();
27     $this->installSchema('system', ['sequence']);
28     $this->installEntitySchema('user');
29     $this->installEntitySchema('block_content');
30   }
31
32   /**
33    * Tests deleting a block_content updates the discovered block plugin.
34    */
35   public function testDeletingBlockContentShouldClearPluginCache() {
36     // Create a block content type.
37     $block_content_type = BlockContentType::create([
38       'id' => 'spiffy',
39       'label' => 'Mucho spiffy',
40       'description' => "Provides a block type that increases your site's spiffiness by upto 11%",
41     ]);
42     $block_content_type->save();
43     // And a block content entity.
44     $block_content = BlockContent::create([
45       'info' => 'Spiffy prototype',
46       'type' => 'spiffy',
47     ]);
48     $block_content->save();
49
50     // Make sure the block content provides a derivative block plugin in the
51     // block repository.
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));
56
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));
61   }
62
63 }