eab53ff2edb863cbc0a52271078a5c3518f10de6
[yaffs-website] / web / modules / contrib / layout_plugin / tests / src / Kernel / LayoutTest.php
1 <?php
2
3 namespace Drupal\Tests\layout_plugin\Kernel;
4
5 use Drupal\KernelTests\KernelTestBase;
6
7 /**
8  * Tests Layout functionality.
9  *
10  * @group LayoutPlugin
11  */
12 class LayoutTest extends KernelTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['system', 'layout_plugin', 'layout_test'];
18
19   /**
20    * The layout plugin manager.
21    *
22    * @var \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface
23    */
24   protected $layoutManager;
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function setUp() {
30     parent::setUp();
31
32     $this->layoutManager = $this->container->get('plugin.manager.layout_plugin');
33   }
34
35   /**
36    * Test listing the available layouts.
37    */
38   public function testLayoutDefinitions() {
39     $expected_layouts = [
40       'layout_test_1col',
41       'layout_test_2col',
42       'layout_test_plugin',
43     ];
44     $this->assertEquals($expected_layouts, array_keys($this->layoutManager->getDefinitions()));
45   }
46
47   /**
48    * Test rendering a layout.
49    *
50    * @dataProvider renderLayoutData
51    */
52   public function testRenderLayout($layout_id, $config, $regions, $html) {
53     /** @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface $layout */
54     $layout = $this->layoutManager->createInstance($layout_id, $config);
55     $built = $layout->build($regions);
56     $this->render($built);
57     $this->assertRaw($html);
58   }
59
60   /**
61    * Data provider for testRenderLayout().
62    */
63   public function renderLayoutData() {
64     $data = [
65       'layout_test_1col' => [
66         'layout_test_1col',
67         [],
68         [
69           'top' => [
70             '#markup' => 'This is the top',
71           ],
72           'bottom' => [
73             '#markup' => 'This is the bottom',
74           ],
75         ],
76       ],
77
78       'layout_test_2col' => [
79         'layout_test_2col',
80         [],
81         [
82           'left' => [
83             '#markup' => 'This is the left',
84           ],
85           'right' => [
86             '#markup' => 'This is the right',
87           ],
88         ],
89       ],
90
91       'layout_test_plugin' => [
92         'layout_test_plugin',
93         [
94           'setting_1' => 'Config value'
95         ],
96         [
97           'main' => [
98             '#markup' => 'Main region',
99           ],
100         ]
101       ],
102     ];
103
104     $data['layout_test_1col'][] = <<<'EOD'
105 <div class="layout-example-1col clearfix">
106   <div class="region-top">
107     This is the top
108   </div>
109   <div class="region-bottom">
110     This is the bottom
111   </div>
112 </div>
113 EOD;
114
115     $data['layout_test_2col'][] = <<<'EOD'
116 <div class="layout-example-2col clearfix">
117   <div class="region-left">
118     This is the left
119   </div>
120   <div class="region-right">
121     This is the right
122   </div>
123 </div>
124 EOD;
125
126     $data['layout_test_plugin'][] = <<<'EOD'
127 <div class="layout-test-plugin clearfix">
128   <div>
129     <span class="setting-1-label">Blah: </span>
130     Config value
131   </div>
132   <div class="region-main">
133     Main region
134   </div>
135 </div>
136 EOD;
137
138     return $data;
139   }
140
141 }