ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MediaTest.php
Go to the documentation of this file.
1<?php
2
20
21use PHPUnit\Framework\TestCase;
26
27require_once('./vendor/composer/vendor/autoload.php');
28
34class MediaTest extends TestCase
35{
36 public string $version;
38
39 protected function setUp(): void
40 {
41 parent::setUp();
42 $this->version = '1.2.3.4.5.6.7.8.9';
43 $this->meta_content = new MetaContent(
44 $this->version,
45 true,
46 false,
47 true,
48 true
49 );
50 }
51
52 public function testAddCssFile(): void
53 {
54 $path = '/path/to/file.css';
55 $this->meta_content->addCss($path);
56 $collection = $this->meta_content->getCss();
57
58 $iterator_to_array = iterator_to_array($collection->getItems());
59 $first_item = array_shift($iterator_to_array);
60 $this->assertInstanceOf(Css::class, $first_item);
61 $this->assertSame($path . '?version=' . $this->version, $first_item->getContent());
62 $this->assertSame(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
63 }
64
65 public function testAddCssFileWithQuery(): void
66 {
67 $path = '/path/to/file.css?my=query';
68 $this->meta_content->addCss($path);
69 $collection = $this->meta_content->getCss();
70
71 $iterator_to_array = iterator_to_array($collection->getItems());
72 $first_item = array_shift($iterator_to_array);
73 $this->assertInstanceOf(Css::class, $first_item);
74 $this->assertSame($path . '&version=' . $this->version, $first_item->getContent());
75 $this->assertSame(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
76 }
77
78 public function testAddInlineCss(): void
79 {
80 $css = 'body {background-color:red;}';
81 $this->meta_content->addInlineCss($css);
82 $collection = $this->meta_content->getInlineCss();
83
84 $first_item = iterator_to_array($collection->getItems())[0];
85 $this->assertInstanceOf(InlineCss::class, $first_item);
86 $this->assertSame($css, $first_item->getContent());
87 $this->assertSame(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
88 }
89
90 public function testAddJsFile(): void
91 {
92 $path = '/path/to/file.js';
93 $this->meta_content->addJs($path);
94 $collection = $this->meta_content->getJs();
95
96 $iterator_to_array = iterator_to_array($collection->getItems());
97 $first_item = $iterator_to_array[$path];
98 $this->assertInstanceOf(Js::class, $first_item);
99 $this->assertSame($path . '?version=' . $this->version, $first_item->getContent());
100 $this->assertSame(2, $first_item->getBatch());
101 }
102
103 public function testAddJsFileWithQuery(): void
104 {
105 $path = '/path/to/file.js';
106 $path_with_query = $path . '?my=query';
107 $this->meta_content->addJs($path_with_query);
108 $collection = $this->meta_content->getJs();
109
110 $first_item = iterator_to_array($collection->getItems())[$path];
111 $this->assertInstanceOf(Js::class, $first_item);
112 $this->assertSame($path_with_query . '&version=' . $this->version, $first_item->getContent());
113 $this->assertSame(2, $first_item->getBatch());
114 }
115}
$path
Definition: ltiservices.php:30
@noinspection PhpIncompatibleReturnTypeInspection