ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ILIAS\GlobalScreen\Scope\Layout\MediaTest Class Reference

Class MediaTest. More...

+ Inheritance diagram for ILIAS\GlobalScreen\Scope\Layout\MediaTest:
+ Collaboration diagram for ILIAS\GlobalScreen\Scope\Layout\MediaTest:

Public Member Functions

 testAddCssFile ()
 
 testAddCssFileWithQuery ()
 
 testAddInlineCss ()
 
 testAddJsFile ()
 
 testAddJsFileWithQuery ()
 
 testDeliverPhpCssIsExcludedFromVersionParameter ()
 
 testDeliverPhpJsIsExcludedFromVersionParameter ()
 
 testFilterDoesNotAffectUnrelatedUrls ()
 
 testCustomVersionParameterFilter ()
 
 testFiltersViaConstructorAreApplied ()
 

Data Fields

string $version
 
MetaContent $meta_content
 

Protected Member Functions

 setUp ()
 

Private Attributes

const VERSION = AbstractCollection::VERSION_PARAMETER
 

Detailed Description

Class MediaTest.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 55 of file MediaTest.php.

Member Function Documentation

◆ setUp()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::setUp ( )
protected

Definition at line 61 of file MediaTest.php.

61 : void
62 {
63 parent::setUp();
64 $this->version = '1.2.3.4.5.6.7.8.9';
65 $this->meta_content = new MetaContent(
66 $this->version,
67 true,
68 false,
69 true,
70 true
71 );
72 }

◆ testAddCssFile()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testAddCssFile ( )

Definition at line 74 of file MediaTest.php.

74 : void
75 {
76 $path = '/path/to/file.css';
77 $this->meta_content->addCss($path);
78 $collection = $this->meta_content->getCss();
79
80 $iterator_to_array = iterator_to_array($collection->getItems());
81 $first_item = array_shift($iterator_to_array);
82 $this->assertInstanceOf(Css::class, $first_item);
83 $this->assertSame($path . '?' . self::VERSION . '=' . $this->version, $first_item->getContent());
84 $this->assertSame(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
85 }
$path
Definition: ltiservices.php:30

References $path, and ILIAS\GlobalScreen\Scope\Layout\MetaContent\MetaContent\MEDIA_SCREEN.

◆ testAddCssFileWithQuery()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testAddCssFileWithQuery ( )

Definition at line 87 of file MediaTest.php.

87 : void
88 {
89 $path = '/path/to/file.css?my=query';
90 $this->meta_content->addCss($path);
91 $collection = $this->meta_content->getCss();
92
93 $iterator_to_array = iterator_to_array($collection->getItems());
94 $first_item = array_shift($iterator_to_array);
95 $this->assertInstanceOf(Css::class, $first_item);
96 $this->assertSame($path . '&' . self::VERSION . '=' . $this->version, $first_item->getContent());
97 $this->assertSame(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
98 }

References $path, and ILIAS\GlobalScreen\Scope\Layout\MetaContent\MetaContent\MEDIA_SCREEN.

◆ testAddInlineCss()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testAddInlineCss ( )

Definition at line 100 of file MediaTest.php.

100 : void
101 {
102 $css = 'body {background-color:red;}';
103 $this->meta_content->addInlineCss($css);
104 $collection = $this->meta_content->getInlineCss();
105
106 $first_item = iterator_to_array($collection->getItems())[0];
107 $this->assertInstanceOf(InlineCss::class, $first_item);
108 $this->assertSame($css, $first_item->getContent());
109 $this->assertSame(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
110 }

References ILIAS\GlobalScreen\Scope\Layout\MetaContent\MetaContent\MEDIA_SCREEN.

◆ testAddJsFile()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testAddJsFile ( )

Definition at line 112 of file MediaTest.php.

112 : void
113 {
114 $path = '/path/to/file.js';
115 $this->meta_content->addJs($path);
116 $collection = $this->meta_content->getJs();
117
118 $iterator_to_array = iterator_to_array($collection->getItems());
119 $first_item = $iterator_to_array[$path];
120 $this->assertInstanceOf(Js::class, $first_item);
121 $this->assertSame($path . '?' . self::VERSION . '=' . $this->version, $first_item->getContent());
122 $this->assertSame(2, $first_item->getBatch());
123 }

References $path.

◆ testAddJsFileWithQuery()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testAddJsFileWithQuery ( )

Definition at line 125 of file MediaTest.php.

125 : void
126 {
127 $path = '/path/to/file.js';
128 $path_with_query = $path . '?my=query';
129 $this->meta_content->addJs($path_with_query);
130 $collection = $this->meta_content->getJs();
131
132 $first_item = iterator_to_array($collection->getItems())[$path];
133 $this->assertInstanceOf(Js::class, $first_item);
134 $this->assertSame($path_with_query . '&' . self::VERSION . '=' . $this->version, $first_item->getContent());
135 $this->assertSame(2, $first_item->getBatch());
136 }

References $path.

◆ testCustomVersionParameterFilter()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testCustomVersionParameterFilter ( )

Definition at line 176 of file MediaTest.php.

176 : void
177 {
178 $custom_filter = new class () implements VersionParameterFilter {
179 public function shouldAppend(string $content): bool
180 {
181 return !str_contains($content, '/no-version/');
182 }
183 };
184 $this->meta_content->addVersionParameterFilter($custom_filter);
185
186 $excluded = '/no-version/file.js';
187 $included = '/path/to/file.js';
188 $this->meta_content->addJs($excluded);
189 $this->meta_content->addJs($included);
190
191 $items = iterator_to_array($this->meta_content->getJs()->getItems());
192 $this->assertEquals($excluded, $items[$excluded]->getContent());
193 $this->assertEquals(
194 $included . '?' . self::VERSION . '=' . $this->version,
195 $items[$included]->getContent()
196 );
197 }

References ILIAS\UI\Implementation\Component\Input\ViewControl\getContent().

+ Here is the call graph for this function:

◆ testDeliverPhpCssIsExcludedFromVersionParameter()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testDeliverPhpCssIsExcludedFromVersionParameter ( )

Definition at line 138 of file MediaTest.php.

138 : void
139 {
140 $this->meta_content->addVersionParameterFilter(new DeliverPhpFilter());
141 $path = '/ilias/public/deliver.php/HczLCgMhDIXhd8m6NDGjUYdhnsRNqk43vVGlUErfvXY2/-/style.css';
142 $this->meta_content->addCss($path);
143 $collection = $this->meta_content->getCss();
144
145 $items = iterator_to_array($collection->getItems());
146 $first_item = array_shift($items);
147 $this->assertInstanceOf(Css::class, $first_item);
148 $this->assertSame($path, $first_item->getContent());
149 }

References $path.

◆ testDeliverPhpJsIsExcludedFromVersionParameter()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testDeliverPhpJsIsExcludedFromVersionParameter ( )

Definition at line 151 of file MediaTest.php.

151 : void
152 {
153 $this->meta_content->addVersionParameterFilter(new DeliverPhpFilter());
154 $path = '/ilias/public/deliver.php/HczLCgMhDIXhd8m6NDGjUYdhnsRNqk43vVGlUErfvXY2/-/script.js';
155 $this->meta_content->addJs($path);
156 $collection = $this->meta_content->getJs();
157
158 $first_item = iterator_to_array($collection->getItems())[$path];
159 $this->assertInstanceOf(Js::class, $first_item);
160 $this->assertSame($path, $first_item->getContent());
161 }

References $path.

◆ testFilterDoesNotAffectUnrelatedUrls()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testFilterDoesNotAffectUnrelatedUrls ( )

Definition at line 163 of file MediaTest.php.

163 : void
164 {
165 $this->meta_content->addVersionParameterFilter(new DeliverPhpFilter());
166 $path = '/path/to/file.css';
167 $this->meta_content->addCss($path);
168 $collection = $this->meta_content->getCss();
169
170 $items = iterator_to_array($collection->getItems());
171 $first_item = array_shift($items);
172 $this->assertInstanceOf(Css::class, $first_item);
173 $this->assertSame($path . '?' . self::VERSION . '=' . $this->version, $first_item->getContent());
174 }

References $path.

◆ testFiltersViaConstructorAreApplied()

ILIAS\GlobalScreen\Scope\Layout\MediaTest::testFiltersViaConstructorAreApplied ( )

Definition at line 199 of file MediaTest.php.

199 : void
200 {
201 $meta_content = new MetaContent(
202 $this->version,
203 true,
204 false,
205 true,
206 true,
207 [new DeliverPhpFilter()]
208 );
209 $path = '/ilias/public/deliver.php/SIGNED/-/style.css';
211
212 $items = iterator_to_array($meta_content->getCss()->getItems());
213 $first_item = array_shift($items);
214 $this->assertEquals($path, $first_item->getContent());
215 }
addCss(string $path, string $media=self::MEDIA_SCREEN)

References ILIAS\GlobalScreen\Scope\Layout\MediaTest\$meta_content, $path, ILIAS\GlobalScreen\Scope\Layout\MetaContent\MetaContent\addCss(), and ILIAS\GlobalScreen\Scope\Layout\MetaContent\MetaContent\getCss().

+ Here is the call graph for this function:

Field Documentation

◆ $meta_content

MetaContent ILIAS\GlobalScreen\Scope\Layout\MediaTest::$meta_content

◆ $version

string ILIAS\GlobalScreen\Scope\Layout\MediaTest::$version

Definition at line 58 of file MediaTest.php.

◆ VERSION

const ILIAS\GlobalScreen\Scope\Layout\MediaTest::VERSION = AbstractCollection::VERSION_PARAMETER
private

Definition at line 57 of file MediaTest.php.


The documentation for this class was generated from the following file: