92ac3cec7a25d41705d926daf5ef9a85895c7d81
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Layout / IconBuilderTest.php
1 <?php
2
3 namespace Drupal\KernelTests\Core\Layout;
4
5 use Drupal\Core\Layout\Icon\SvgIconBuilder;
6 use Drupal\Core\Render\RenderContext;
7 use Drupal\KernelTests\KernelTestBase;
8
9 /**
10  * @coversDefaultClass \Drupal\Core\Layout\Icon\SvgIconBuilder
11  * @group Layout
12  */
13 class IconBuilderTest extends KernelTestBase {
14
15   /**
16    * @covers ::build
17    * @covers ::buildRenderArray
18    * @covers ::calculateSvgValues
19    * @covers ::getLength
20    * @covers ::getOffset
21    *
22    * @dataProvider providerTestBuild
23    */
24   public function testBuild(SvgIconBuilder $icon_builder, $icon_map, $expected) {
25     $renderer = $this->container->get('renderer');
26
27     $build = $icon_builder->build($icon_map);
28
29     $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use ($build, $renderer) {
30       return $renderer->render($build);
31     });
32     $this->assertSame($expected, $output);
33   }
34
35   public function providerTestBuild() {
36     $data = [];
37     $data['empty'][] = (new SvgIconBuilder());
38     $data['empty'][] = [];
39     $data['empty'][] = <<<'EOD'
40 <svg width="125" height="150" class="layout-icon"></svg>
41
42 EOD;
43
44     $data['two_column'][] = (new SvgIconBuilder())
45       ->setId('two_column')
46       ->setLabel('Two Column')
47       ->setWidth(250)
48       ->setHeight(300)
49       ->setStrokeWidth(2);
50     $data['two_column'][] = [['left', 'right']];
51     $data['two_column'][] = <<<'EOD'
52 <svg width="250" height="300" class="layout-icon layout-icon--two-column"><title>Two Column</title>
53 <g><title>left</title>
54 <rect x="1" y="1" width="121" height="298" stroke-width="2" class="layout-icon__region layout-icon__region--left" />
55 </g>
56 <g><title>right</title>
57 <rect x="128" y="1" width="121" height="298" stroke-width="2" class="layout-icon__region layout-icon__region--right" />
58 </g>
59 </svg>
60
61 EOD;
62
63     $data['two_column_no_stroke'][] = (new SvgIconBuilder())
64       ->setWidth(250)
65       ->setHeight(300)
66       ->setStrokeWidth(NULL);
67     $data['two_column_no_stroke'][] = [['left', 'right']];
68     $data['two_column_no_stroke'][] = <<<'EOD'
69 <svg width="250" height="300" class="layout-icon"><g><title>left</title>
70 <rect x="0" y="0" width="123" height="300" class="layout-icon__region layout-icon__region--left" />
71 </g>
72 <g><title>right</title>
73 <rect x="127" y="0" width="123" height="300" class="layout-icon__region layout-icon__region--right" />
74 </g>
75 </svg>
76
77 EOD;
78
79     $data['two_column_border_collapse'][] = (new SvgIconBuilder())
80       ->setWidth(250)
81       ->setHeight(300)
82       ->setStrokeWidth(2)
83       ->setPadding(-2);
84     $data['two_column_border_collapse'][] = [['left', 'right']];
85     $data['two_column_border_collapse'][] = <<<'EOD'
86 <svg width="250" height="300" class="layout-icon"><g><title>left</title>
87 <rect x="1" y="1" width="124" height="298" stroke-width="2" class="layout-icon__region layout-icon__region--left" />
88 </g>
89 <g><title>right</title>
90 <rect x="125" y="1" width="124" height="298" stroke-width="2" class="layout-icon__region layout-icon__region--right" />
91 </g>
92 </svg>
93
94 EOD;
95
96     $data['stacked'][] = (new SvgIconBuilder())
97       ->setStrokeWidth(2);
98     $data['stacked'][] = [
99       ['sidebar', 'top', 'top'],
100       ['sidebar', 'left', 'right'],
101       ['sidebar', 'middle', 'middle'],
102       ['footer_left', 'footer_right'],
103       ['footer_full'],
104     ];
105     $data['stacked'][] = <<<'EOD'
106 <svg width="125" height="150" class="layout-icon"><g><title>sidebar</title>
107 <rect x="1" y="1" width="37" height="86.4" stroke-width="2" class="layout-icon__region layout-icon__region--sidebar" />
108 </g>
109 <g><title>top</title>
110 <rect x="44" y="1" width="80" height="24.8" stroke-width="2" class="layout-icon__region layout-icon__region--top" />
111 </g>
112 <g><title>left</title>
113 <rect x="44" y="31.8" width="37" height="24.8" stroke-width="2" class="layout-icon__region layout-icon__region--left" />
114 </g>
115 <g><title>right</title>
116 <rect x="87" y="31.8" width="37" height="24.8" stroke-width="2" class="layout-icon__region layout-icon__region--right" />
117 </g>
118 <g><title>middle</title>
119 <rect x="44" y="62.6" width="80" height="24.8" stroke-width="2" class="layout-icon__region layout-icon__region--middle" />
120 </g>
121 <g><title>footer_left</title>
122 <rect x="1" y="93.4" width="58.5" height="24.8" stroke-width="2" class="layout-icon__region layout-icon__region--footer-left" />
123 </g>
124 <g><title>footer_right</title>
125 <rect x="65.5" y="93.4" width="58.5" height="24.8" stroke-width="2" class="layout-icon__region layout-icon__region--footer-right" />
126 </g>
127 <g><title>footer_full</title>
128 <rect x="1" y="124.2" width="123" height="24.8" stroke-width="2" class="layout-icon__region layout-icon__region--footer-full" />
129 </g>
130 </svg>
131
132 EOD;
133
134     return $data;
135   }
136
137 }