19declare(strict_types=1);
39use PHPUnit\Framework\TestCase;
48require_once(
'./vendor/composer/vendor/autoload.php');
61 protected function setUp(): void
64 $this->version =
'1.2.3.4.5.6.7.8.9';
76 $path =
'/path/to/file.css';
77 $this->meta_content->addCss(
$path);
78 $collection = $this->meta_content->getCss();
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());
89 $path =
'/path/to/file.css?my=query';
90 $this->meta_content->addCss(
$path);
91 $collection = $this->meta_content->getCss();
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());
102 $css =
'body {background-color:red;}';
103 $this->meta_content->addInlineCss($css);
104 $collection = $this->meta_content->getInlineCss();
106 $first_item = iterator_to_array($collection->getItems())[0];
107 $this->assertInstanceOf(InlineCss::class, $first_item);
108 $this->assertSame($css, $first_item->getContent());
114 $path =
'/path/to/file.js';
115 $this->meta_content->addJs(
$path);
116 $collection = $this->meta_content->getJs();
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());
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();
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());
141 $path =
'/ilias/public/deliver.php/HczLCgMhDIXhd8m6NDGjUYdhnsRNqk43vVGlUErfvXY2/-/style.css';
142 $this->meta_content->addCss(
$path);
143 $collection = $this->meta_content->getCss();
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());
154 $path =
'/ilias/public/deliver.php/HczLCgMhDIXhd8m6NDGjUYdhnsRNqk43vVGlUErfvXY2/-/script.js';
155 $this->meta_content->addJs(
$path);
156 $collection = $this->meta_content->getJs();
158 $first_item = iterator_to_array($collection->getItems())[
$path];
159 $this->assertInstanceOf(Js::class, $first_item);
160 $this->assertSame(
$path, $first_item->getContent());
166 $path =
'/path/to/file.css';
167 $this->meta_content->addCss(
$path);
168 $collection = $this->meta_content->getCss();
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());
179 public function shouldAppend(
string $content):
bool
181 return !str_contains($content,
'/no-version/');
184 $this->meta_content->addVersionParameterFilter($custom_filter);
186 $excluded =
'/no-version/file.js';
187 $included =
'/path/to/file.js';
188 $this->meta_content->addJs($excluded);
189 $this->meta_content->addJs($included);
191 $items = iterator_to_array($this->meta_content->getJs()->getItems());
192 $this->assertEquals($excluded, $items[$excluded]->
getContent());
194 $included .
'?' . self::VERSION .
'=' . $this->version,
209 $path =
'/ilias/public/deliver.php/SIGNED/-/style.css';
213 $first_item = array_shift($items);
214 $this->assertEquals(
$path, $first_item->getContent());
Excludes URLs delivered by deliver.php from the resource version parameter.
addCss(string $path, string $media=self::MEDIA_SCREEN)
Decides whether the resource version parameter (see {.
@noinspection PhpIncompatibleReturnTypeInspection