ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
PCMediaObjectTest.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 getObjectAdapterMock()
32  {
33  $object_adapter = $this->getMockBuilder(\ILIAS\Repository\Object\ObjectAdapter::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36  $object_adapter->method("getTypeForObjId")
37  ->willReturnCallback(fn() => "dummy");
38  return $object_adapter;
39  }
40 
41  public function testConstruction(): void
42  {
43  $page = $this->getEmptyPageWithDom();
44  $pc = new ilPCMediaObject($page);
45  $this->assertEquals(
46  ilPCMediaObject::class,
47  get_class($pc)
48  );
49  }
50 
51  public function testCreate(): void
52  {
53  $page = $this->getEmptyPageWithDom();
54  $pc = new ilPCMediaObject($page);
55  $pc->create($page, "pg");
56  $this->assertXmlEquals(
57  '<PageObject HierId="pg"></PageObject>',
58  $page->getXMLFromDom()
59  );
60  }
61 
62  public function testCreateAlias(): void
63  {
64  $page = $this->getEmptyPageWithDom();
65  $pc = new ilPCMediaObject($page);
66  $pc->setMediaObject($this->getMediaObjectMock());
67  $pc->createAlias($page, "pg");
68 
69  $page->stripHierIDs();
70 
71  $expected = <<<EOT
72 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
73 EOT;
74 
75  $this->assertXmlEquals(
76  $expected,
77  $page->getXMLFromDom()
78  );
79  }
80 
82  {
83  $pc = new ilPCMediaObject($page);
84  $pc->setMediaObject($this->getMediaObjectMock());
85  $pc->createAlias($page, "pg");
86  $page->addHierIDs();
87  $page->insertPCIds();
88  $pc->setHierId("1");
89  $pc->setPCId($page->getPCIdForHierId("1"));
90  $pc->setDomNode($pc->getDomNode());
91  return $pc;
92  }
93 
94  public function testDump(): void
95  {
96  $page = $this->getEmptyPageWithDom();
97  $pc = $this->getMediaObjectInPage($page);
98 
99  $page->stripHierIDs();
100  $page->stripPCIDs();
101 
102  $expected = <<<EOT
103 <PageContent><MediaObject><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"/></MediaAliasItem></MediaObject></PageContent>
104 EOT;
105 
106  $this->assertXmlEquals(
107  $expected,
108  $pc->dumpXML()
109  );
110  }
111 
112  public function testSetClass(): void
113  {
114  $page = $this->getEmptyPageWithDom();
115  $pc = $this->getMediaObjectInPage($page);
116 
117  $pc->setClass("MyClass");
118 
119  $this->assertEquals(
120  "MyClass",
121  $pc->getClass()
122  );
123 
124  $page->stripHierIDs();
125  $page->stripPCIDs();
126 
127  $expected = <<<EOT
128 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0" Class="MyClass"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"/></MediaAliasItem></MediaObject></PageContent></PageObject>
129 EOT;
130 
131  $this->assertXmlEquals(
132  $expected,
133  $page->getXMLFromDom()
134  );
135  }
136 
137  public function testCaptionClass(): void
138  {
139  $page = $this->getEmptyPageWithDom();
140  $pc = $this->getMediaObjectInPage($page);
141 
142  $pc->setCaptionClass("MyCaptionClass");
143 
144  $this->assertEquals(
145  "MyCaptionClass",
146  $pc->getCaptionClass()
147  );
148 
149  $page->stripHierIDs();
150  $page->stripPCIDs();
151 
152  $expected = <<<EOT
153 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0" CaptionClass="MyCaptionClass"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"/></MediaAliasItem></MediaObject></PageContent></PageObject>
154 EOT;
155 
156  $this->assertXmlEquals(
157  $expected,
158  $page->getXMLFromDom()
159  );
160  }
161 
162  // Media alias item tests
163 
164  public function checkMAProps(
165  Closure $assert,
166  ?string $expected = null
167  ): void {
168  $page = $this->getEmptyPageWithDom();
169  $pc = $this->getMediaObjectInPage($page);
170  $ma = $pc->getStandardMediaAliasItem();
171 
172  $assert($ma);
173 
174  $page->stripHierIDs();
175  $page->stripPCIDs();
176 
177  if (!is_null($expected)) {
178  $this->assertXmlEquals(
179  $expected,
180  $page->getXMLFromDom()
181  );
182  }
183  }
184 
185  public function testWidth(): void
186  {
187  $this->checkMAProps(
188  function (ilMediaAliasItem $ma): void {
189  $this->assertEquals(
190  false,
191  $ma->definesSize()
192  );
193  $ma->setWidth("222");
194  $this->assertEquals(
195  "222",
196  $ma->getWidth()
197  );
198  $this->assertEquals(
199  true,
200  $ma->definesSize()
201  );
202  },
203  $expected = <<<EOT
204 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left" Width="222"/></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"/></MediaAliasItem></MediaObject></PageContent></PageObject>
205 EOT
206  );
207  }
208 
209  public function testHeight(): void
210  {
211  $this->checkMAProps(
212  function (ilMediaAliasItem $ma): void {
213  $ma->setHeight("11");
214  $this->assertEquals(
215  "11",
216  $ma->getHeight()
217  );
218  },
219  $expected = <<<EOT
220 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left" Height="11"/></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"/></MediaAliasItem></MediaObject></PageContent></PageObject>
221 EOT
222  );
223  }
224 
225  public function testDeriveSize(): void
226  {
227  $this->checkMAProps(
228  function (ilMediaAliasItem $ma): void {
229  $this->assertEquals(
230  false,
231  $ma->definesSize()
232  );
233  $ma->setWidth("222");
234  $ma->setHeight("111");
235  $this->assertEquals(
236  true,
237  $ma->definesSize()
238  );
239  $ma->deriveSize();
240  $this->assertEquals(
241  false,
242  $ma->definesSize()
243  );
244  },
245  $expected = <<<EOT
246 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"/><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"/></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"/></MediaAliasItem></MediaObject></PageContent></PageObject>
247 EOT
248  );
249  }
250 
251  public function testCaption(): void
252  {
253  $this->checkMAProps(
254  function (ilMediaAliasItem $ma): void {
255  $this->assertEquals(
256  false,
257  $ma->definesCaption()
258  );
259  $ma->setCaption("My Caption");
260  $this->assertEquals(
261  "My Caption",
262  $ma->getCaption()
263  );
264  $this->assertEquals(
265  true,
266  $ma->definesCaption()
267  );
268  },
269  $expected = <<<EOT
270 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout><Caption Align="bottom">My Caption</Caption></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
271 EOT
272  );
273  }
274 
275  public function testDeriveCaption(): void
276  {
277  $this->checkMAProps(
278  function (ilMediaAliasItem $ma): void {
279  $ma->setCaption("My Caption");
280  $this->assertEquals(
281  true,
282  $ma->definesCaption()
283  );
284  $ma->deriveCaption();
285  $this->assertEquals(
286  false,
287  $ma->definesCaption()
288  );
289  },
290  $expected = <<<EOT
291 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
292 EOT
293  );
294  }
295 
296  public function testTextRepresentation(): void
297  {
298  $this->checkMAProps(
299  function (ilMediaAliasItem $ma): void {
300  $this->assertEquals(
301  false,
303  );
304  $ma->setTextRepresentation("My Text");
305  $this->assertEquals(
306  "My Text",
307  $ma->getTextRepresentation()
308  );
309  $this->assertEquals(
310  true,
312  );
313  },
314  $expected = <<<EOT
315 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout><TextRepresentation>My Text</TextRepresentation></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
316 EOT
317  );
318  }
319 
320  public function testDeriveTextRepresentation(): void
321  {
322  $this->checkMAProps(
323  function (ilMediaAliasItem $ma): void {
324  $ma->setTextRepresentation("My Text");
325  $this->assertEquals(
326  true,
328  );
330  $this->assertEquals(
331  false,
333  );
334  },
335  $expected = <<<EOT
336 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
337 EOT
338  );
339  }
340 
341  public function testHorizontalAlign(): void
342  {
343  $this->checkMAProps(
344  function (ilMediaAliasItem $ma): void {
345  $ma->setHorizontalAlign("Right");
346  $this->assertEquals(
347  "Right",
348  $ma->getHorizontalAlign()
349  );
350  },
351  $expected = <<<EOT
352 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Right"></Layout></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
353 EOT
354  );
355  }
356 
357  public function testParameters(): void
358  {
359  $this->checkMAProps(
360  function (ilMediaAliasItem $ma): void {
361  $this->assertEquals(
362  false,
363  $ma->definesParameters()
364  );
365  $ma->setParameters([
366  "par1" => "val1",
367  "par2" => "val2"
368  ]);
369  $this->assertEquals(
370  [
371  "par1" => "val1",
372  "par2" => "val2"
373  ],
374  $ma->getParameters()
375  );
376  $this->assertEquals(
377  true,
378  $ma->definesParameters()
379  );
380  $this->assertEquals(
381  'par1="val1", par2="val2"',
382  $ma->getParameterString()
383  );
384  },
385  $expected = <<<EOT
386 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout><Parameter Name="par1" Value="val1"></Parameter><Parameter Name="par2" Value="val2"></Parameter></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
387 EOT
388  );
389  }
390 
391  public function testDeriveParameters(): void
392  {
393  $this->checkMAProps(
394  function (ilMediaAliasItem $ma): void {
395  $ma->setParameters([
396  "par1" => "val1",
397  "par2" => "val2"
398  ]);
399  $ma->deriveParameters();
400  $this->assertEquals(
401  false,
402  $ma->definesParameters()
403  );
404  },
405  $expected = <<<EOT
406 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
407 EOT
408  );
409  }
410 
411  public function testAddMapArea(): void
412  {
413  $this->checkMAProps(
414  function (ilMediaAliasItem $ma): void {
415  $ma->addMapArea(
416  IL_AREA_RECT,
417  "10,10,100,100",
418  "Area Title",
419  [
420  "LinkType" => "ext",
421  "Href" => "http://www.ilias.de"
422  ],
423  "One"
424  );
425  $this->assertEquals(
426  [
427  0 => [
428  "Nr" => 1,
429  "Shape" => "Rect",
430  "Coords" => "10,10,100,100",
431  "HighlightMode" => "",
432  "HighlightClass" => "",
433  "Id" => "One",
434  "Link" => [
435  "LinkType" => "ExtLink",
436  "Href" => "http://www.ilias.de",
437  "Title" => "Area Title"
438  ]
439  ]
440  ],
441  $ma->getMapAreas()
442  );
443  $this->assertEquals(
444  "http://www.ilias.de",
445  $ma->getHrefOfArea(1)
446  );
447  },
448  $expected = <<<EOT
449 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout><MapArea Shape="Rect" Coords="10,10,100,100" Id="One"><ExtLink Href="http://www.ilias.de">Area Title</ExtLink></MapArea></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
450 EOT
451  );
452  }
453 
454  public function testDeleteMapArea(): void
455  {
456  $this->checkMAProps(
457  function (ilMediaAliasItem $ma): void {
458  $ma->addMapArea(
459  IL_AREA_RECT,
460  "10,10,100,100",
461  "Area Title",
462  [
463  "LinkType" => "ext",
464  "Href" => "http://www.ilias.de"
465  ],
466  "One"
467  );
468  $ma->addMapArea(
469  IL_AREA_RECT,
470  "11,11,101,101",
471  "Area Title 2",
472  [
473  "LinkType" => "ext",
474  "Href" => "http://ilias.de"
475  ],
476  "Two"
477  );
478  $ma->deleteMapArea(1);
479  },
480  $expected = <<<EOT
481 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout><MapArea Shape="Rect" Coords="11,11,101,101" Id="Two"><ExtLink Href="http://ilias.de">Area Title 2</ExtLink></MapArea></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
482 EOT
483  );
484  }
485 
486  public function testDeleteMapAreaById(): void
487  {
488  $this->checkMAProps(
489  function (ilMediaAliasItem $ma): void {
490  $ma->addMapArea(
491  IL_AREA_RECT,
492  "10,10,100,100",
493  "Area Title",
494  [
495  "LinkType" => "ext",
496  "Href" => "http://www.ilias.de"
497  ],
498  "One"
499  );
500  $ma->addMapArea(
501  IL_AREA_RECT,
502  "11,11,101,101",
503  "Area Title 2",
504  [
505  "LinkType" => "ext",
506  "Href" => "http://ilias.de"
507  ],
508  "Two"
509  );
510  $ma->deleteMapAreaById("One");
511  },
512  $expected = <<<EOT
513 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout><MapArea Shape="Rect" Coords="11,11,101,101" Id="Two"><ExtLink Href="http://ilias.de">Area Title 2</ExtLink></MapArea></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
514 EOT
515  );
516  }
517 
518  public function testDeleteAllMapAreas(): void
519  {
520  $this->checkMAProps(
521  function (ilMediaAliasItem $ma): void {
522  $ma->addMapArea(
523  IL_AREA_RECT,
524  "10,10,100,100",
525  "Area Title",
526  [
527  "LinkType" => "ext",
528  "Href" => "http://www.ilias.de"
529  ],
530  "One"
531  );
532  $ma->addMapArea(
533  IL_AREA_RECT,
534  "11,11,101,101",
535  "Area Title 2",
536  [
537  "LinkType" => "ext",
538  "Href" => "http://ilias.de"
539  ],
540  "Two"
541  );
542  $ma->deleteAllMapAreas();
543  },
544  $expected = <<<EOT
545 <PageObject><PageContent><MediaObject><MediaAlias OriginId="il__mob_0"></MediaAlias><MediaAliasItem Purpose="Standard"><Layout HorizontalAlign="Left"></Layout></MediaAliasItem><MediaAliasItem Purpose="Fullscreen"><Layout Width="100" Height="50"></Layout></MediaAliasItem></MediaObject></PageContent></PageObject>
546 EOT
547  );
548  }
549 
550  public function testAreaProps(): void
551  {
552  $this->checkMAProps(
553  function (ilMediaAliasItem $ma): void {
554  $ma->addMapArea(
555  IL_AREA_RECT,
556  "10,10,100,100",
557  "Area Title",
558  [
559  "LinkType" => "int",
560  "Type" => "ltype",
561  "Target" => "ltarget",
562  "TargetFrame" => "ltargetframe"
563  ],
564  "One"
565  );
566  $this->assertEquals(
567  "int",
568  $ma->getLinkTypeOfArea(1)
569  );
570  $this->assertEquals(
571  "ltype",
572  $ma->getTypeOfArea(1)
573  );
574  $this->assertEquals(
575  "ltarget",
576  $ma->getTargetOfArea(1)
577  );
578  $this->assertEquals(
579  "ltargetframe",
580  $ma->getTargetFrameOfArea(1)
581  );
582  $this->assertEquals(
583  "Area Title",
584  $ma->getTitleOfArea(1)
585  );
586  },
587  null
588  );
589  }
590 }
setCaption(string $a_caption)
Interface Observer Contains several chained tasks and infos about them.
definesTextRepresentation()
check if alias item defines own TextRepresentation or derives TextRepresentation from object ...
deleteAllMapAreas()
Delete all map areas.
checkMAProps(Closure $assert, ?string $expected=null)
getPCIdForHierId(string $hier_id)
Title class.
Definition: Title.php:41
getMediaObjectInPage(ilPageObject $page)
getTitleOfArea(int $a_nr)
Get title.
deriveSize()
derive size from object (-> width and height attributes are removed from layout element) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_AREA_RECT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deriveCaption()
derive caption from object (-> caption element is removed from media alias item)
deriveTextRepresentation()
derive TextRepresentation from object (-> TextRepresentation element is removed from media alias item...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
deleteMapArea(int $a_nr)
Delete a sinlge map area.
definesCaption()
check if alias item defines own caption or derives caption from object
definesSize()
check if alias item defines own size or derives size from object
getTargetOfArea(int $a_nr)
Get target (only internal link)
getParameterString()
Get all parameters as string.
setTextRepresentation(string $a_text_representation)
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
addMapArea(string $a_shape_type, string $a_coords, string $a_title, array $a_link, string $a_id="")
Add a new area to the map.
setHeight(string $a_height)
getParameters()
Get all parameters as array.
setParameters(array $a_par_array)
getTypeOfArea(int $a_nr)
Get type (only internal link)
getLinkTypeOfArea(int $a_nr)
Get link type.
insertPCIds()
Insert Page Content IDs.
addHierIDs()
Add hierarchical ID (e.g.
deriveParameters()
derive parameters from object (-> all parameter elements are removed from media alias item) ...
getTargetFrameOfArea(int $a_nr)
Get target frame (only internal link)
Class ilPCMediaObject Media content object (see ILIAS DTD)
setWidth(string $a_width)
deleteMapAreaById(string $a_id)
Delete map areas by id.
setHorizontalAlign(string $a_halign)
getHrefOfArea(int $a_nr)
Get href (only external link)
getMapAreas()
Get all map areas.
assertXmlEquals(string $expected_xml_as_string, string $html_xml_string)
definesParameters()
check if alias item defines own parameters or derives parameters from object