ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PCGridTest.php
Go to the documentation of this file.
1<?php
2
19use PHPUnit\Framework\TestCase;
20
25{
26 public function testConstruction(): void
27 {
28 $page = $this->getEmptyPageWithDom();
29 $pc = new ilPCGrid($page);
30 $this->assertEquals(
31 ilPCGrid::class,
32 get_class($pc)
33 );
34 }
35
36 public function testCreate(): void
37 {
38 $page = $this->getEmptyPageWithDom();
39 $pc = new ilPCGrid($page);
40 $pc->create($page, "pg");
41 $this->assertXmlEquals(
42 '<PageObject HierId="pg"><PageContent><Grid></Grid></PageContent></PageObject>',
43 $page->getXMLFromDom()
44 );
45 }
46
47 public function testApplyTemplateTwoColumn(): void
48 {
49 $page = $this->getEmptyPageWithDom();
50 $pc = new ilPCGrid($page);
51 $pc->create($page, "pg");
52 $pc->applyTemplate(
54 0,
55 0,
56 0,
57 0,
58 0
59 );
60
61 $expected = <<<EOT
62<PageObject HierId="pg"><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="6" WIDTH_XL="6"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="6" WIDTH_XL="6"/></Grid></PageContent></PageObject>
63EOT;
64
65 $this->assertXmlEquals(
66 $expected,
67 $page->getXMLFromDom()
68 );
69 }
70
71 public function testApplyTemplateManual(): void
72 {
73 $page = $this->getEmptyPageWithDom();
74 $pc = new ilPCGrid($page);
75 $pc->create($page, "pg");
76 $pc->applyTemplate(
78 4,
79 12,
80 6,
81 3,
82 3
83 );
84
85 $expected = <<<EOT
86<PageObject HierId="pg"><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="3" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="3" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="3" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="3" WIDTH_XL="3"/></Grid></PageContent></PageObject>
87EOT;
88
89 $this->assertXmlEquals(
90 $expected,
91 $page->getXMLFromDom()
92 );
93 }
94
95 public function testPositions(): void
96 {
97 $page = $this->getEmptyPageWithDom();
98 $pc = new ilPCGrid($page);
99 $pc->create($page, "pg");
100 $pc->applyTemplate(
102 0,
103 0,
104 0,
105 0,
106 0
107 );
108 $page->addHierIDs();
109 $pc->savePositions([
110 "1_1:" => 20,
111 "1_2:" => 10
112 ]);
113 $page->stripHierIDs();
114
115 $expected = <<<EOT
116<PageObject><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="4" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="8" WIDTH_XL="9"/></Grid></PageContent></PageObject>
117EOT;
118
119 $this->assertXmlEquals(
120 $expected,
121 $page->getXMLFromDom()
122 );
123 }
124
125 public function testWidths(): void
126 {
127 $page = $this->getEmptyPageWithDom();
128 $pc = new ilPCGrid($page);
129 $pc->create($page, "pg");
130 $pc->applyTemplate(
132 0,
133 0,
134 0,
135 0,
136 0
137 );
138 $page->addHierIDs();
139 $pc->saveWidths(
140 [
141 "1_1:" => 12,
142 "1_2:" => 12
143 ],
144 [
145 "1_1:" => 12,
146 "1_2:" => 12
147 ],
148 [
149 "1_1:" => 6,
150 "1_2:" => 6
151 ],
152 [
153 "1_1:" => 6,
154 "1_2:" => 6
155 ],
156 );
157 $page->stripHierIDs();
158
159 $expected = <<<EOT
160<PageObject><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="12" WIDTH_L="6" WIDTH_XL="6"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="12" WIDTH_L="6" WIDTH_XL="6"/></Grid></PageContent></PageObject>
161EOT;
162
163 $this->assertXmlEquals(
164 $expected,
165 $page->getXMLFromDom()
166 );
167 }
168
169 public function testDelete(): void
170 {
171 $page = $this->getEmptyPageWithDom();
172 $pc = new ilPCGrid($page);
173 $pc->create($page, "pg");
174 $pc->applyTemplate(
176 0,
177 0,
178 0,
179 0,
180 0
181 );
182 $page->addHierIDs();
183 $pc->deleteGridCell("1_2", "");
184 $page->stripHierIDs();
185
186 $expected = <<<EOT
187<PageObject><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="8" WIDTH_XL="9"/></Grid></PageContent></PageObject>
188EOT;
189
190 $this->assertXmlEquals(
191 $expected,
192 $page->getXMLFromDom()
193 );
194 }
195
196 public function testAddGridCell(): void
197 {
198 $page = $this->getEmptyPageWithDom();
199 $pc = new ilPCGrid($page);
200 $pc->create($page, "pg");
201 $pc->applyTemplate(
203 1,
204 12,
205 6,
206 3,
207 3
208 );
209 $pc->addGridCell(12, 12, 12, 6);
210
211 $expected = <<<EOT
212<PageObject HierId="pg"><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="3" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="12" WIDTH_L="12" WIDTH_XL="6"/></Grid></PageContent></PageObject>
213EOT;
214
215 $this->assertXmlEquals(
216 $expected,
217 $page->getXMLFromDom()
218 );
219 }
220
221 public function testAddCell(): void
222 {
223 $page = $this->getEmptyPageWithDom();
224 $pc = new ilPCGrid($page);
225 $pc->create($page, "pg");
226 $pc->applyTemplate(
228 1,
229 12,
230 6,
231 3,
232 3
233 );
234 $pc->addCell();
235
236 $expected = <<<EOT
237<PageObject HierId="pg"><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="3" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="" WIDTH_M="" WIDTH_L="" WIDTH_XL=""/></Grid></PageContent></PageObject>
238EOT;
239
240 $this->assertXmlEquals(
241 $expected,
242 $page->getXMLFromDom()
243 );
244 }
245
246
247 public function testCellData(): void
248 {
249 $page = $this->getEmptyPageWithDom();
250 $pc = new ilPCGrid($page);
251 $pc->create($page, "pg");
252 $pc->applyTemplate(
254 0,
255 0,
256 0,
257 0,
258 0
259 );
260 $page->addHierIDs();
261
262 $this->assertEquals(
263 [
264 0 => [
265 "xs" => "",
266 "s" => "12",
267 "m" => "6",
268 "l" => "8",
269 "xl" => "9",
270 "pc_id" => "",
271 "hier_id" => "1_1",
272 "pos" => 0
273 ],
274 1 => [
275 "xs" => "",
276 "s" => "12",
277 "m" => "6",
278 "l" => "4",
279 "xl" => "3",
280 "pc_id" => "",
281 "hier_id" => "1_2",
282 "pos" => 1
283 ]
284 ],
285 $pc->getCellData()
286 );
287 }
288
289 //
290 // Test file items
291 //
292
293 protected function getPageWithGrid(): ilPageObject
294 {
295 $page = $this->getEmptyPageWithDom();
296 $pc = new ilPCGrid($page);
297 $pc->create($page, "pg");
298 $pc->applyTemplate(
300 0,
301 0,
302 0,
303 0,
304 0
305 );
306 $page->addHierIDs();
307 $page->insertPCIds();
308 $pc->setHierId("1");
309 return $page;
310 }
311
312 protected function getCellForHierId(ilPageObject $page, string $hier_id): ilPCGridCell
313 {
314 $pc_id = $page->getPCIdForHierId($hier_id);
315 $cont_node = $page->getContentDomNode($hier_id);
316 $pc = new ilPCGridCell($page);
317 $pc->setDomNode($cont_node);
318 $pc->setHierId($hier_id);
319 $pc->setPcId($pc_id);
320 return $pc;
321 }
322
323 public function testMoveRight(): void
324 {
325 $page = $this->getPageWithGrid();
326 $cell = $this->getCellForHierId($page, "1_1");
327 $cell->moveCellRight();
328 $page->stripHierIDs();
329 $page->stripPCIDs();
330
331 $expected = <<<EOT
332<PageObject><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="4" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="8" WIDTH_XL="9"/></Grid></PageContent></PageObject>
333EOT;
334
335 $this->assertXmlEquals(
336 $expected,
337 $page->getXMLFromDom()
338 );
339 }
340
341 public function testMoveLeft(): void
342 {
343 $page = $this->getPageWithGrid();
344 $cell = $this->getCellForHierId($page, "1_2");
345 $cell->moveCellLeft();
346 $page->stripHierIDs();
347 $page->stripPCIDs();
348
349 $expected = <<<EOT
350<PageObject><PageContent><Grid><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="4" WIDTH_XL="3"/><GridCell WIDTH_XS="" WIDTH_S="12" WIDTH_M="6" WIDTH_L="8" WIDTH_XL="9"/></Grid></PageContent></PageObject>
351EOT;
352
353 $this->assertXmlEquals(
354 $expected,
355 $page->getXMLFromDom()
356 );
357 }
358}
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
getCellForHierId(ilPageObject $page, string $hier_id)
Definition: PCGridTest.php:312
testApplyTemplateManual()
Definition: PCGridTest.php:71
testConstruction()
Definition: PCGridTest.php:26
testApplyTemplateTwoColumn()
Definition: PCGridTest.php:47
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const TEMPLATE_TWO_COLUMN
const TEMPLATE_MAIN_SIDE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
getContentDomNode(string $a_hier_id, string $a_pc_id="")
getPCIdForHierId(string $hier_id)