comparison core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php @ 0:c75dbcec494b

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