BlockContentDeriverTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Drupal\Tests\block_content\Kernel;
  3. use Drupal\block_content\Entity\BlockContent;
  4. use Drupal\block_content\Entity\BlockContentType;
  5. use Drupal\Component\Plugin\PluginBase;
  6. use Drupal\KernelTests\KernelTestBase;
  7. /**
  8. * Tests block content plugin deriver.
  9. *
  10. * @group block_content
  11. */
  12. class BlockContentDeriverTest extends KernelTestBase {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public static $modules = ['block', 'block_content', 'system', 'user'];
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function setUp() {
  21. parent::setUp();
  22. $this->installSchema('system', ['sequence']);
  23. $this->installEntitySchema('user');
  24. $this->installEntitySchema('block_content');
  25. }
  26. /**
  27. * Tests that only reusable blocks are derived.
  28. */
  29. public function testReusableBlocksOnlyAreDerived() {
  30. // Create a block content type.
  31. $block_content_type = BlockContentType::create([
  32. 'id' => 'spiffy',
  33. 'label' => 'Mucho spiffy',
  34. 'description' => "Provides a block type that increases your site's spiffiness by up to 11%",
  35. ]);
  36. $block_content_type->save();
  37. // And a block content entity.
  38. $block_content = BlockContent::create([
  39. 'info' => 'Spiffy prototype',
  40. 'type' => 'spiffy',
  41. ]);
  42. $block_content->save();
  43. // Ensure the reusable block content is provided as a derivative block
  44. // plugin.
  45. /** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */
  46. $block_manager = $this->container->get('plugin.manager.block');
  47. $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid();
  48. $this->assertTrue($block_manager->hasDefinition($plugin_id));
  49. // Set the block not to be reusable.
  50. $block_content->setNonReusable();
  51. $block_content->save();
  52. // Ensure the non-reusable block content is not provided a derivative block
  53. // plugin.
  54. $this->assertFalse($block_manager->hasDefinition($plugin_id));
  55. }
  56. }