BlockContentDeriverTest.php in Drupal 9
File
core/modules/block_content/tests/src/Kernel/BlockContentDeriverTest.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;
class BlockContentDeriverTest extends KernelTestBase {
protected static $modules = [
'block',
'block_content',
'system',
'user',
];
public function setUp() : void {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('block_content');
}
public function testReusableBlocksOnlyAreDerived() {
$block_content_type = BlockContentType::create([
'id' => 'spiffy',
'label' => 'Mucho spiffy',
'description' => "Provides a block type that increases your site's spiffiness by up to 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
->setNonReusable();
$block_content
->save();
$this
->assertFalse($block_manager
->hasDefinition($plugin_id));
}
}