ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PCTabsTest.php
Go to the documentation of this file.
1 <?php
2 
20 
25 {
26  public function testConstruction(): void
27  {
28  $page = $this->getEmptyPageWithDom();
29  $pc = new ilPCTabs($page);
30  $this->assertEquals(
31  ilPCTabs::class,
32  get_class($pc)
33  );
34  }
35 
36  public function testCreate(): void
37  {
38  $page = $this->getEmptyPageWithDom();
39  $pc = new ilPCTabs($page);
40  $pc->create($page, "pg", "");
41  $this->assertXmlEquals(
42  '<PageObject HierId="pg"><PageContent><Tabs></Tabs></PageContent></PageObject>',
43  $page->getXMLFromDom()
44  );
45  }
46 
47  public function testType(): void
48  {
49  $page = $this->getEmptyPageWithDom();
50  $pc = new ilPCTabs($page);
51  $pc->create($page, "pg", "");
52  $pc->setTabType("Carousel");
53 
54  $this->assertEquals(
55  "Carousel",
56  $pc->getTabType()
57  );
58 
59  $page->stripHierIDs();
60 
61  $expected = <<<EOT
62 <PageObject><PageContent><Tabs Type="Carousel"></Tabs></PageContent></PageObject>
63 EOT;
64  $this->assertXmlEquals(
65  $expected,
66  $page->getXMLFromDom()
67  );
68  }
69 
70  public function testContentWidth(): void
71  {
72  $page = $this->getEmptyPageWithDom();
73  $pc = new ilPCTabs($page);
74  $pc->create($page, "pg", "");
75  $pc->setContentWidth("100");
76 
77  $this->assertEquals(
78  "100",
79  $pc->getContentWidth()
80  );
81 
82  $page->stripHierIDs();
83 
84  $expected = <<<EOT
85 <PageObject><PageContent><Tabs ContentWidth="100"></Tabs></PageContent></PageObject>
86 EOT;
87  $this->assertXmlEquals(
88  $expected,
89  $page->getXMLFromDom()
90  );
91  }
92 
93  public function testContentHeight(): void
94  {
95  $page = $this->getEmptyPageWithDom();
96  $pc = new ilPCTabs($page);
97  $pc->create($page, "pg", "");
98  $pc->setContentHeight("200");
99 
100  $this->assertEquals(
101  "200",
102  $pc->getContentHeight()
103  );
104 
105  $page->stripHierIDs();
106 
107  $expected = <<<EOT
108 <PageObject><PageContent><Tabs ContentHeight="200"></Tabs></PageContent></PageObject>
109 EOT;
110  $this->assertXmlEquals(
111  $expected,
112  $page->getXMLFromDom()
113  );
114  }
115 
116  public function testHorizontalAlign(): void
117  {
118  $page = $this->getEmptyPageWithDom();
119  $pc = new ilPCTabs($page);
120  $pc->create($page, "pg", "");
121  $pc->setHorizontalAlign("Right");
122 
123  $this->assertEquals(
124  "Right",
125  $pc->getHorizontalAlign()
126  );
127 
128  $page->stripHierIDs();
129 
130  $expected = <<<EOT
131 <PageObject><PageContent><Tabs HorizontalAlign="Right"></Tabs></PageContent></PageObject>
132 EOT;
133  $this->assertXmlEquals(
134  $expected,
135  $page->getXMLFromDom()
136  );
137  }
138 
139  public function testBehaviour(): void
140  {
141  $page = $this->getEmptyPageWithDom();
142  $pc = new ilPCTabs($page);
143  $pc->create($page, "pg", "");
144  $pc->setBehavior("AllClosed");
145 
146  $this->assertEquals(
147  "AllClosed",
148  $pc->getBehavior()
149  );
150 
151  $page->stripHierIDs();
152 
153  $expected = <<<EOT
154 <PageObject><PageContent><Tabs Behavior="AllClosed"></Tabs></PageContent></PageObject>
155 EOT;
156  $this->assertXmlEquals(
157  $expected,
158  $page->getXMLFromDom()
159  );
160  }
161 
162  protected function getTabsWithTabs(ilPageObject $page): ilPCTabs
163  {
164  $pc = new ilPCTabs($page);
165  $pc->create($page, "pg", "");
166  $pc->setTabType("HorizontalAccordion");
167  $pc->addTab("One");
168  $pc->addTab("Two");
169  $pc->addTab("Three");
170  $page->addHierIDs();
171  return $pc;
172  }
173 
174  public function testAddTab(): void
175  {
176  $page = $this->getEmptyPageWithDom();
177  $pc = $this->getTabsWithTabs($page);
178 
179  /*
180  $this->assertEquals(
181  "AllClosed",
182  $pc->getBehavior()
183  );*/
184 
185  $page->stripHierIDs();
186 
187  $expected = <<<EOT
188 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>One</TabCaption></Tab><Tab><TabCaption>Two</TabCaption></Tab><Tab><TabCaption>Three</TabCaption></Tab></Tabs></PageContent></PageObject>
189 EOT;
190  $this->assertXmlEquals(
191  $expected,
192  $page->getXMLFromDom()
193  );
194  }
195 
196  public function testCaptions(): void
197  {
198  $page = $this->getEmptyPageWithDom();
199  $pc = $this->getTabsWithTabs($page);
200  $pc->saveCaptions(
201  [
202  "1_1:" => "New 1",
203  "1_2:" => "New 2",
204  "1_3:" => "New 3"
205  ]
206  );
207 
208  $this->assertEquals(
209  [
210  0 => [
211  "pos" => 0,
212  "caption" => "New 1",
213  "pc_id" => "",
214  "hier_id" => "1_1"
215  ],
216  1 => [
217  "pos" => 1,
218  "caption" => "New 2",
219  "pc_id" => "",
220  "hier_id" => "1_2"
221  ],
222  2 => [
223  "pos" => 2,
224  "caption" => "New 3",
225  "pc_id" => "",
226  "hier_id" => "1_3"
227  ]
228  ],
229  $pc->getCaptions()
230  );
231 
232  $this->assertEquals(
233  "New 2",
234  $pc->getCaption("1_2", "")
235  );
236 
237  $page->stripHierIDs();
238 
239  $expected = <<<EOT
240 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>New 1</TabCaption></Tab><Tab><TabCaption>New 2</TabCaption></Tab><Tab><TabCaption>New 3</TabCaption></Tab></Tabs></PageContent></PageObject>
241 EOT;
242  $this->assertXmlEquals(
243  $expected,
244  $page->getXMLFromDom()
245  );
246  }
247 
248  public function testPositions(): void
249  {
250  $page = $this->getEmptyPageWithDom();
251  $pc = $this->getTabsWithTabs($page);
252  $pc->savePositions(
253  [
254  "1_1:" => 3,
255  "1_2:" => 2,
256  "1_3:" => 1
257  ]
258  );
259 
260  $page->stripHierIDs();
261 
262  $expected = <<<EOT
263 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>Three</TabCaption></Tab><Tab><TabCaption>Two</TabCaption></Tab><Tab><TabCaption>One</TabCaption></Tab></Tabs></PageContent></PageObject>
264 EOT;
265  $this->assertXmlEquals(
266  $expected,
267  $page->getXMLFromDom()
268  );
269  }
270 
271  public function testDeleteTab(): void
272  {
273  $page = $this->getEmptyPageWithDom();
274  $pc = $this->getTabsWithTabs($page);
275  $pc->deleteTab("1_2", "");
276 
277  $page->stripHierIDs();
278 
279  $expected = <<<EOT
280 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>One</TabCaption></Tab><Tab><TabCaption>Three</TabCaption></Tab></Tabs></PageContent></PageObject>
281 EOT;
282  $this->assertXmlEquals(
283  $expected,
284  $page->getXMLFromDom()
285  );
286  }
287 
288  public function testTemplate(): void
289  {
290  $page = $this->getEmptyPageWithDom();
291  $pc = new ilPCTabs($page);
292  $pc->create($page, "pg", "");
293  $pc->setTemplate("MyTemplate");
294 
295  $this->assertEquals(
296  "MyTemplate",
297  $pc->getTemplate()
298  );
299 
300  $page->stripHierIDs();
301 
302  $expected = <<<EOT
303 <PageObject><PageContent><Tabs Template="MyTemplate"></Tabs></PageContent></PageObject>
304 EOT;
305  $this->assertXmlEquals(
306  $expected,
307  $page->getXMLFromDom()
308  );
309  }
310 
311  public function testAutoTime(): void
312  {
313  $page = $this->getEmptyPageWithDom();
314  $pc = new ilPCTabs($page);
315  $pc->create($page, "pg", "");
316  $pc->setAutoTime(20);
317 
318  $this->assertEquals(
319  20,
320  $pc->getAutoTime()
321  );
322 
323  $page->stripHierIDs();
324 
325  $expected = <<<EOT
326 <PageObject><PageContent><Tabs AutoAnimWait="20"></Tabs></PageContent></PageObject>
327 EOT;
328  $this->assertXmlEquals(
329  $expected,
330  $page->getXMLFromDom()
331  );
332  }
333 
334  public function testRandomStart(): void
335  {
336  $page = $this->getEmptyPageWithDom();
337  $pc = new ilPCTabs($page);
338  $pc->create($page, "pg", "");
339 
340  $pc->setRandomStart(false);
341  $this->assertEquals(
342  false,
343  $pc->getRandomStart()
344  );
345 
346  $pc->setRandomStart(true);
347  $this->assertEquals(
348  true,
349  $pc->getRandomStart()
350  );
351 
352  $page->stripHierIDs();
353 
354  $expected = <<<EOT
355 <PageObject><PageContent><Tabs RandomStart="1"></Tabs></PageContent></PageObject>
356 EOT;
357  $this->assertXmlEquals(
358  $expected,
359  $page->getXMLFromDom()
360  );
361  }
362 
363  //
364  // PCTab tests
365  //
366 
367  protected function getTabForHierId(ilPageObject $page, string $hier_id): ilPCTab
368  {
369  $page->insertPCIds();
370  $pc_id = $page->getPCIdForHierId($hier_id);
371  $cont_node = $page->getContentDomNode($hier_id);
372  $pc = new ilPCTab($page);
373  $pc->setDomNode($cont_node);
374  $pc->setHierId($hier_id);
375  $pc->setPcId($pc_id);
376  return $pc;
377  }
378 
379  public function testNewItemAfter(): void
380  {
381  $page = $this->getEmptyPageWithDom();
382  $pc = $this->getTabsWithTabs($page);
383  $tab = $this->getTabForHierId($page, "1_1");
384  $tab->newItemAfter();
385 
386  $page->stripHierIDs();
387  $page->stripPCIDs();
388 
389  $expected = <<<EOT
390 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>One</TabCaption></Tab><Tab></Tab><Tab><TabCaption>Two</TabCaption></Tab><Tab><TabCaption>Three</TabCaption></Tab></Tabs></PageContent></PageObject>
391 EOT;
392  $this->assertXmlEquals(
393  $expected,
394  $page->getXMLFromDom()
395  );
396  }
397 
398  public function testNewItemBefore(): void
399  {
400  $page = $this->getEmptyPageWithDom();
401  $pc = $this->getTabsWithTabs($page);
402  $tab = $this->getTabForHierId($page, "1_2");
403  $tab->newItemBefore();
404 
405  $page->stripHierIDs();
406  $page->stripPCIDs();
407 
408  $expected = <<<EOT
409 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>One</TabCaption></Tab><Tab></Tab><Tab><TabCaption>Two</TabCaption></Tab><Tab><TabCaption>Three</TabCaption></Tab></Tabs></PageContent></PageObject>
410 EOT;
411  $this->assertXmlEquals(
412  $expected,
413  $page->getXMLFromDom()
414  );
415  }
416 
417  public function testDeleteItem(): void
418  {
419  $page = $this->getEmptyPageWithDom();
420  $pc = $this->getTabsWithTabs($page);
421  $tab = $this->getTabForHierId($page, "1_2");
422  $tab->deleteItem();
423 
424  $page->stripHierIDs();
425  $page->stripPCIDs();
426 
427  $expected = <<<EOT
428 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>One</TabCaption></Tab><Tab><TabCaption>Three</TabCaption></Tab></Tabs></PageContent></PageObject>
429 EOT;
430  $this->assertXmlEquals(
431  $expected,
432  $page->getXMLFromDom()
433  );
434  }
435 
436  public function testMoveItemDown(): void
437  {
438  $page = $this->getEmptyPageWithDom();
439  $pc = $this->getTabsWithTabs($page);
440  $tab = $this->getTabForHierId($page, "1_1");
441  $tab->moveItemDown();
442 
443  $page->stripHierIDs();
444  $page->stripPCIDs();
445 
446  $expected = <<<EOT
447 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>Two</TabCaption></Tab><Tab><TabCaption>One</TabCaption></Tab><Tab><TabCaption>Three</TabCaption></Tab></Tabs></PageContent></PageObject>
448 EOT;
449  $this->assertXmlEquals(
450  $expected,
451  $page->getXMLFromDom()
452  );
453  }
454 
455  public function testMoveItemUp(): void
456  {
457  $page = $this->getEmptyPageWithDom();
458  $pc = $this->getTabsWithTabs($page);
459  $tab = $this->getTabForHierId($page, "1_2");
460  $tab->moveItemUp();
461 
462  $page->stripHierIDs();
463  $page->stripPCIDs();
464 
465  $expected = <<<EOT
466 <PageObject><PageContent><Tabs Type="HorizontalAccordion"><Tab><TabCaption>Two</TabCaption></Tab><Tab><TabCaption>One</TabCaption></Tab><Tab><TabCaption>Three</TabCaption></Tab></Tabs></PageContent></PageObject>
467 EOT;
468  $this->assertXmlEquals(
469  $expected,
470  $page->getXMLFromDom()
471  );
472  }
473 }
getContentDomNode(string $a_hier_id, string $a_pc_id="")
getPCIdForHierId(string $hier_id)
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)
insertPCIds()
Insert Page Content IDs.
getTabForHierId(ilPageObject $page, string $hier_id)
Definition: PCTabsTest.php:367
addHierIDs()
Add hierarchical ID (e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTabsWithTabs(ilPageObject $page)
Definition: PCTabsTest.php:162
testContentHeight()
Definition: PCTabsTest.php:93
testMoveItemDown()
Definition: PCTabsTest.php:436
testHorizontalAlign()
Definition: PCTabsTest.php:116
testConstruction()
Definition: PCTabsTest.php:26
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
testNewItemBefore()
Definition: PCTabsTest.php:398
testContentWidth()
Definition: PCTabsTest.php:70
testNewItemAfter()
Definition: PCTabsTest.php:379