ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PCInteractiveImageTest.php
Go to the documentation of this file.
1 <?php
2 
20 
21 require_once("./components/ILIAS/MediaObjects/ImageMap/class.ilMapArea.php");
22 
27 {
31  protected function getMediaObjectMock()
32  {
33  $media_item = new ilMediaItem();
34  $media_item->setWidth("100");
35  $media_item->setHeight("50");
36  $media_object = $this->getMockBuilder(ilObjMediaObject::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39  $media_object->method("getMediaItem")
40  ->willReturnCallback(fn() => $media_item);
41  return $media_object;
42  }
43 
47  protected function getObjectAdapterMock()
48  {
49  $object_adapter = $this->getMockBuilder(\ILIAS\Repository\Object\ObjectAdapter::class)
50  ->disableOriginalConstructor()
51  ->getMock();
52  $object_adapter->method("getTypeForObjId")
53  ->willReturnCallback(fn() => "dummy");
54  return $object_adapter;
55  }
56 
57  public function testConstruction(): void
58  {
59  $page = $this->getEmptyPageWithDom();
60  $pc = new ilPCInteractiveImage($page);
61  $this->assertEquals(
62  ilPCInteractiveImage::class,
63  get_class($pc)
64  );
65  }
66 
67  public function testCreate(): void
68  {
69  $page = $this->getEmptyPageWithDom();
70  $pc = new ilPCInteractiveImage($page);
71  $pc->create($page, "pg");
72  $this->assertXmlEquals(
73  '<PageObject HierId="pg"></PageObject>',
74  $page->getXMLFromDom()
75  );
76  }
77 
78  public function testCreateAlias(): void
79  {
80  $page = $this->getEmptyPageWithDom();
81  $pc = new ilPCInteractiveImage($page);
82  $pc->setMediaObject($this->getMediaObjectMock());
83  $pc->createAlias($page, "pg");
84 
85  $expected = <<<EOT
86 <PageObject HierId="pg"><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem></InteractiveImage></PageContent></PageObject>
87 EOT;
88 
89  $this->assertXmlEquals(
90  $expected,
91  $page->getXMLFromDom()
92  );
93  }
94 
95  public function testDump(): void
96  {
97  $page = $this->getEmptyPageWithDom();
98  $pc = new ilPCInteractiveImage($page);
99  $pc->setMediaObject($this->getMediaObjectMock());
100  $pc->createAlias($page, "pg");
101 
102  $expected = <<<EOT
103 <PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem></InteractiveImage></PageContent>
104 EOT;
105 
106  $this->assertXmlEquals(
107  $expected,
108  $pc->dumpXML()
109  );
110  }
111 
112  public function testAddContentPopup(): void
113  {
114  $page = $this->getEmptyPageWithDom();
115  $pc = new ilPCInteractiveImage($page);
116  $pc->setMediaObject($this->getMediaObjectMock());
117  $pc->createAlias($page, "pg");
118  $pc->addContentPopup();
119 
120  //echo $page->getXMLFromDom();
121  //exit;
122 
123  $expected = <<<EOT
124 <PageObject HierId="pg"><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><ContentPopup Title="" Nr="1"/></InteractiveImage></PageContent></PageObject>
125 EOT;
126 
127  $this->assertXmlEquals(
128  $expected,
129  $page->getXMLFromDom()
130  );
131  }
132 
133  public function testGetPopups(): void
134  {
135  $page = $this->getEmptyPageWithDom();
136  $pc = new ilPCInteractiveImage($page);
137  $pc->setMediaObject($this->getMediaObjectMock());
138  $pc->createAlias($page, "pg");
139  $pc->addContentPopup();
140  $page->addHierIDs();
141  $popups = $pc->getPopups();
142 
143  $expected = [
144  0 => [
145  "title" => "",
146  "nr" => "1",
147  "pc_id" => "",
148  "hier_id" => "1_1"
149  ]
150  ];
151 
152  $this->assertEquals(
153  $expected,
154  $popups
155  );
156  }
157 
158  public function testSavePopups(): void
159  {
160  $page = $this->getEmptyPageWithDom();
161  $pc = new ilPCInteractiveImage($page);
162  $pc->setMediaObject($this->getMediaObjectMock());
163  $pc->createAlias($page, "pg");
164  $pc->addContentPopup();
165  $page->addHierIDs();
166  $popups = $pc->savePopups(
167  [
168  "1_1:" => "Test Title"
169  ]
170  );
171 
172  $expected = [
173  0 => [
174  "title" => "Test Title",
175  "nr" => "1",
176  "pc_id" => "",
177  "hier_id" => "1_1"
178  ]
179  ];
180 
181  $this->assertEquals(
182  $expected,
183  $pc->getPopups()
184  );
185  }
186 
187  public function testDeletePopup(): void
188  {
189  $page = $this->getEmptyPageWithDom();
190  $pc = new ilPCInteractiveImage($page);
191  $pc->setMediaObject($this->getMediaObjectMock());
192  $pc->createAlias($page, "pg");
193  $pc->addContentPopup();
194  $pc->addContentPopup();
195  $page->addHierIDs();
196  $popups = $pc->savePopups(
197  [
198  "1_1:" => "Test Title 1",
199  "1_2:" => "Test Title 2"
200  ]
201  );
202  $pc->deletePopup("1_1", "");
203  $page->stripHierIDs();
204 
205  $expected = <<<EOT
206 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><ContentPopup Title="Test Title 2" Nr="2"/></InteractiveImage></PageContent></PageObject>
207 EOT;
208 
209  $this->assertXmlEquals(
210  $expected,
211  $page->getXMLFromDom()
212  );
213  }
214 
216  {
217  $pc = new ilPCInteractiveImage(
218  $page,
219  null,
220  $this->getObjectAdapterMock()
221  );
222  $pc->setMediaObject($this->getMediaObjectMock());
223  $pc->createAlias($page, "pg");
224  $page->addHierIDs();
225  $page->insertPCIds();
226  $pc->setHierId("1");
227  $pc->setPCId($page->getPCIdForHierId("1"));
228  $pc->setDomNode($pc->getDomNode());
229  return $pc;
230  }
231 
232  public function testAddTriggerArea(): void
233  {
234  $page = $this->getEmptyPageWithDom();
235  $pc = $this->getInteractiveImageInPage($page);
236 
237  $pc->addTriggerArea(
238  $pc->getStandardAliasItem(),
239  IL_AREA_RECT,
240  "20,20,200,200",
241  "Area Title"
242  );
243  $page->stripHierIDs();
244  $page->stripPCIDs();
245 
246  $expected = <<<EOT
247 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/><MapArea Shape="Rect" Coords="20,20,200,200" Id="1"><ExtLink Href="#">Area Title</ExtLink></MapArea></MediaAliasItem><Trigger Type="Area" Title="Area Title" Nr="1" OverlayX="0" OverlayY="0" PopupX="0" PopupY="0" PopupWidth="150" PopupHeight="200"/></InteractiveImage></PageContent></PageObject>
248 EOT;
249 
250  $this->assertXmlEquals(
251  $expected,
252  $page->getXMLFromDom()
253  );
254  }
255 
256  public function testAddTriggerMarker(): void
257  {
258  $page = $this->getEmptyPageWithDom();
259  $pc = $this->getInteractiveImageInPage($page);
260 
261  $pc->addTriggerMarker(
262  );
263  $page->stripHierIDs();
264  $page->stripPCIDs();
265 
266  $expected = <<<EOT
267 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><Trigger Type="Marker" Nr="1" OverlayX="0" OverlayY="0" MarkerX="0" MarkerY="0" PopupX="0" PopupY="0" PopupWidth="150" PopupHeight="200"/></InteractiveImage></PageContent></PageObject>
268 EOT;
269 
270  $this->assertXmlEquals(
271  $expected,
272  $page->getXMLFromDom()
273  );
274  }
275 
276  public function testGetTriggerNodes(): void
277  {
278  $page = $this->getEmptyPageWithDom();
279  $pc = $this->getInteractiveImageInPage($page);
280  $pc->addTriggerMarker();
281  $page->stripPCIDs();
282  $nodes = $pc->getTriggerNodes("1", "");
283  $this->assertEquals(
284  "Trigger",
285  $nodes->item(0)->nodeName
286  );
287  }
288 
289  public function testGetTriggers(): void
290  {
291  $page = $this->getEmptyPageWithDom();
292  $pc = $this->getInteractiveImageInPage($page);
293  $pc->addTriggerMarker();
294  $triggers = $pc->getTriggers();
295  $this->assertEquals(
296  "Marker",
297  $triggers[0]["Type"]
298  );
299  }
300 
301  public function testDeleteTrigger(): void
302  {
303  $page = $this->getEmptyPageWithDom();
304  $pc = $this->getInteractiveImageInPage($page);
305 
306  $pc->addTriggerArea(
307  $pc->getStandardAliasItem(),
308  IL_AREA_RECT,
309  "20,20,200,200",
310  "Area Title"
311  );
312  $ma = $pc->getStandardAliasItem();
313  $pc->deleteTrigger($ma, "1");
314 
315  $page->stripHierIDs();
316  $page->stripPCIDs();
317 
318  $expected = <<<EOT
319 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem></InteractiveImage></PageContent></PageObject>
320 EOT;
321 
322  $this->assertXmlEquals(
323  $expected,
324  $page->getXMLFromDom()
325  );
326  }
327 
328  public function testSetOverlays(): void
329  {
330  $page = $this->getEmptyPageWithDom();
331  $pc = $this->getInteractiveImageInPage($page);
332 
333  $pc->addTriggerArea(
334  $pc->getStandardAliasItem(),
335  IL_AREA_RECT,
336  "20,20,200,200",
337  "Area Title"
338  );
339  $pc->setTriggerOverlays([
340  "1" => "image1.jpg"
341  ]);
342 
343  $page->stripHierIDs();
344  $page->stripPCIDs();
345 
346  $expected = <<<EOT
347 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/><MapArea Shape="Rect" Coords="20,20,200,200" Id="1"><ExtLink Href="#">Area Title</ExtLink></MapArea></MediaAliasItem><Trigger Type="Area" Title="Area Title" Nr="1" OverlayX="0" OverlayY="0" PopupX="0" PopupY="0" PopupWidth="150" PopupHeight="200" Overlay="image1.jpg"/></InteractiveImage></PageContent></PageObject>
348 EOT;
349 
350  $this->assertXmlEquals(
351  $expected,
352  $page->getXMLFromDom()
353  );
354  }
355 
356  public function testSetTriggerOverlayPositions(): void
357  {
358  $page = $this->getEmptyPageWithDom();
359  $pc = $this->getInteractiveImageInPage($page);
360 
361  $pc->addTriggerArea(
362  $pc->getStandardAliasItem(),
363  IL_AREA_RECT,
364  "20,20,200,200",
365  "Area Title"
366  );
367  $pc->setTriggerOverlayPositions([
368  "1" => "10,20"
369  ]);
370 
371  $page->stripHierIDs();
372  $page->stripPCIDs();
373 
374  $expected = <<<EOT
375 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/><MapArea Shape="Rect" Coords="20,20,200,200" Id="1"><ExtLink Href="#">Area Title</ExtLink></MapArea></MediaAliasItem><Trigger Type="Area" Title="Area Title" Nr="1" OverlayX="10" OverlayY="20" PopupX="0" PopupY="0" PopupWidth="150" PopupHeight="200"/></InteractiveImage></PageContent></PageObject>
376 EOT;
377 
378  $this->assertXmlEquals(
379  $expected,
380  $page->getXMLFromDom()
381  );
382  }
383 
384  public function testSetTriggerMarkerPositions(): void
385  {
386  $page = $this->getEmptyPageWithDom();
387  $pc = $this->getInteractiveImageInPage($page);
388 
389  $pc->addTriggerMarker();
390  $pc->setTriggerMarkerPositions(
391  ["1" => "50,100"]
392  );
393 
394  $page->stripHierIDs();
395  $page->stripPCIDs();
396 
397  $expected = <<<EOT
398 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><Trigger Type="Marker" Nr="1" OverlayX="0" OverlayY="0" MarkerX="50" MarkerY="100" PopupX="0" PopupY="0" PopupWidth="150" PopupHeight="200"/></InteractiveImage></PageContent></PageObject>
399 EOT;
400 
401  $this->assertXmlEquals(
402  $expected,
403  $page->getXMLFromDom()
404  );
405  }
406 
407  public function testSetTriggerPopupPositions(): void
408  {
409  $page = $this->getEmptyPageWithDom();
410  $pc = $this->getInteractiveImageInPage($page);
411 
412  $pc->addTriggerMarker();
413  $pc->setTriggerPopupPositions(
414  ["1" => "40,30"]
415  );
416 
417  $page->stripHierIDs();
418  $page->stripPCIDs();
419 
420  $expected = <<<EOT
421 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><Trigger Type="Marker" Nr="1" OverlayX="0" OverlayY="0" MarkerX="0" MarkerY="0" PopupX="40" PopupY="30" PopupWidth="150" PopupHeight="200"/></InteractiveImage></PageContent></PageObject>
422 EOT;
423 
424  $this->assertXmlEquals(
425  $expected,
426  $page->getXMLFromDom()
427  );
428  }
429 
430  public function testSetTriggerPopupSize(): void
431  {
432  $page = $this->getEmptyPageWithDom();
433  $pc = $this->getInteractiveImageInPage($page);
434 
435  $pc->addTriggerMarker();
436  $pc->setTriggerPopupSize(
437  ["1" => "220,330"]
438  );
439 
440  $page->stripHierIDs();
441  $page->stripPCIDs();
442 
443  $expected = <<<EOT
444 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><Trigger Type="Marker" Nr="1" OverlayX="0" OverlayY="0" MarkerX="0" MarkerY="0" PopupX="0" PopupY="0" PopupWidth="220" PopupHeight="330"/></InteractiveImage></PageContent></PageObject>
445 EOT;
446 
447  $this->assertXmlEquals(
448  $expected,
449  $page->getXMLFromDom()
450  );
451  }
452 
453  public function testSetTriggerPopups(): void
454  {
455  $page = $this->getEmptyPageWithDom();
456  $pc = $this->getInteractiveImageInPage($page);
457 
458  $pc->addTriggerMarker();
459  $pc->setTriggerPopups(
460  ["1" => "1"]
461  );
462 
463  $page->stripHierIDs();
464  $page->stripPCIDs();
465 
466  $expected = <<<EOT
467 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><Trigger Type="Marker" Nr="1" OverlayX="0" OverlayY="0" MarkerX="0" MarkerY="0" PopupX="0" PopupY="0" PopupWidth="150" PopupHeight="200" PopupNr="1"/></InteractiveImage></PageContent></PageObject>
468 EOT;
469 
470  $this->assertXmlEquals(
471  $expected,
472  $page->getXMLFromDom()
473  );
474  }
475 
476  public function testSetTriggerTitles(): void
477  {
478  $page = $this->getEmptyPageWithDom();
479  $pc = $this->getInteractiveImageInPage($page);
480 
481  $pc->addTriggerMarker();
482  $pc->setTriggerTitles(
483  ["1" => "My Title"]
484  );
485 
486  $page->stripHierIDs();
487  $page->stripPCIDs();
488 
489  $expected = <<<EOT
490 <PageObject><PageContent><InteractiveImage><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><Trigger Type="Marker" Nr="1" OverlayX="0" OverlayY="0" MarkerX="0" MarkerY="0" PopupX="0" PopupY="0" PopupWidth="150" PopupHeight="200" Title="My Title"/></InteractiveImage></PageContent></PageObject>
491 EOT;
492 
493  $this->assertXmlEquals(
494  $expected,
495  $page->getXMLFromDom()
496  );
497  }
498 }
getInteractiveImageInPage(ilPageObject $page)
Interface Observer Contains several chained tasks and infos about them.
getPCIdForHierId(string $hier_id)
Title class.
Definition: Title.php:41
const IL_AREA_RECT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
Class ilMediaItem Media Item, component of a media object (file or reference)
insertPCIds()
Insert Page Content IDs.
addHierIDs()
Add hierarchical ID (e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)