View source
<?php
namespace Drupal\block\Tests;
use Drupal\block\Entity\Block;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\simpletest\KernelTestBase;
class BlockConfigSchemaTest extends KernelTestBase {
use SchemaCheckTestTrait;
public static $modules = array(
'block',
'aggregator',
'book',
'block_content',
'comment',
'forum',
'node',
'statistics',
'system',
'taxonomy',
'user',
'text',
);
protected $typedConfig;
protected $blockManager;
protected function setUp() {
parent::setUp();
$this->typedConfig = \Drupal::service('config.typed');
$this->blockManager = \Drupal::service('plugin.manager.block');
$this
->installEntitySchema('block_content');
$this
->installEntitySchema('taxonomy_term');
$this
->installEntitySchema('node');
$this
->installSchema('book', array(
'book',
));
}
public function testBlockConfigSchema() {
foreach ($this->blockManager
->getDefinitions() as $block_id => $definition) {
$id = strtolower($this
->randomMachineName());
$block = Block::create(array(
'id' => $id,
'theme' => 'classy',
'weight' => 00,
'status' => TRUE,
'region' => 'content',
'plugin' => $block_id,
'settings' => array(
'label' => $this
->randomMachineName(),
'provider' => 'system',
'label_display' => FALSE,
),
'visibility' => array(),
));
$block
->save();
$config = $this
->config("block.block.{$id}");
$this
->assertEqual($config
->get('id'), $id);
$this
->assertConfigSchema($this->typedConfig, $config
->getName(), $config
->get());
}
}
}