BlockConfigSchemaTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Drupal\Tests\block\Kernel;
  3. use Drupal\block\Entity\Block;
  4. use Drupal\Tests\SchemaCheckTestTrait;
  5. use Drupal\KernelTests\KernelTestBase;
  6. /**
  7. * Tests the block config schema.
  8. *
  9. * @group block
  10. */
  11. class BlockConfigSchemaTest extends KernelTestBase {
  12. use SchemaCheckTestTrait;
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public static $modules = [
  17. 'block',
  18. 'aggregator',
  19. 'book',
  20. 'block_content',
  21. 'comment',
  22. 'forum',
  23. 'node',
  24. 'statistics',
  25. // BlockManager->getModuleName() calls system_get_info().
  26. 'system',
  27. 'taxonomy',
  28. 'user',
  29. 'text',
  30. ];
  31. /**
  32. * The typed config manager.
  33. *
  34. * @var \Drupal\Core\Config\TypedConfigManagerInterface
  35. */
  36. protected $typedConfig;
  37. /**
  38. * The block manager.
  39. *
  40. * @var \Drupal\Core\Block\BlockManagerInterface
  41. */
  42. protected $blockManager;
  43. /**
  44. * {@inheritdoc}
  45. */
  46. protected function setUp() {
  47. parent::setUp();
  48. $this->typedConfig = \Drupal::service('config.typed');
  49. $this->blockManager = \Drupal::service('plugin.manager.block');
  50. $this->installEntitySchema('block_content');
  51. $this->installEntitySchema('taxonomy_term');
  52. $this->installEntitySchema('node');
  53. $this->installSchema('book', ['book']);
  54. }
  55. /**
  56. * Tests the block config schema for block plugins.
  57. */
  58. public function testBlockConfigSchema() {
  59. foreach ($this->blockManager->getDefinitions() as $block_id => $definition) {
  60. $id = strtolower($this->randomMachineName());
  61. $block = Block::create([
  62. 'id' => $id,
  63. 'theme' => 'classy',
  64. 'weight' => 00,
  65. 'status' => TRUE,
  66. 'region' => 'content',
  67. 'plugin' => $block_id,
  68. 'settings' => [
  69. 'label' => $this->randomMachineName(),
  70. 'provider' => 'system',
  71. 'label_display' => FALSE,
  72. ],
  73. 'visibility' => [],
  74. ]);
  75. $block->save();
  76. $config = $this->config("block.block.$id");
  77. $this->assertEqual($config->get('id'), $id);
  78. $this->assertConfigSchema($this->typedConfig, $config->getName(), $config->get());
  79. }
  80. }
  81. }