View source
<?php
namespace Drupal\Tests\page_manager\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\page_manager\Entity\Page;
use Drupal\page_manager\Entity\PageVariant;
use Drupal\Tests\SchemaCheckTestTrait;
class PageConfigSchemaTest extends KernelTestBase {
use SchemaCheckTestTrait;
public static $modules = [
'page_manager',
'block',
'node',
'user',
];
protected function setUp() {
parent::setUp();
$this
->installConfig([
'page_manager',
]);
}
public function testValidPageConfigSchema() {
$id = 'node_view';
$label = 'Node view';
$description = 'When enabled, this overrides the default Drupal behavior for displaying nodes at <em>/node/{node}</em>. If you add variants, you may use selection criteria such as node type or language or user access to provide different views of nodes. If no variant is selected, the default Drupal node view will be used. This page only affects nodes viewed as pages, it will not affect nodes viewed in lists or at other locations.';
$page = Page::load($id);
$page
->addAccessCondition([
'id' => 'node_type',
'bundles' => [
'article' => 'article',
],
'negate' => TRUE,
'context_mapping' => [
'node' => 'node',
],
]);
$page
->save();
$page_variant_id = 'block_page';
$page_variant = PageVariant::create([
'variant' => 'block_display',
'id' => $page_variant_id,
'label' => 'Block page',
'page' => $page
->id(),
]);
$page_variant
->save();
$page
->addVariant($page_variant);
$variant_plugin = $page_variant
->getVariantPlugin();
$page_variant
->addSelectionCondition([
'id' => 'node_type',
'bundles' => [
'page' => 'page',
],
'context_mapping' => [
'node' => 'node',
],
]);
$variant_plugin
->addBlock([
'id' => 'entity_view:node',
'label' => 'View the node',
'provider' => 'page_manager',
'label_display' => 'visible',
'view_mode' => 'default',
]);
$page_variant
->save();
$page_config = \Drupal::config("page_manager.page.{$id}");
$this
->assertSame($page_config
->get('id'), $id);
$this
->assertSame($page_config
->get('label'), $label);
$this
->assertSame($page_config
->get('description'), $description);
$variant_config = \Drupal::config("page_manager.page_variant.{$page_variant_id}");
$this
->assertSame($variant_config
->get('id'), $page_variant_id);
$this
->assertConfigSchema(\Drupal::service('config.typed'), $page_config
->getName(), $page_config
->get());
$this
->assertConfigSchema(\Drupal::service('config.typed'), $variant_config
->getName(), $variant_config
->get());
}
}