ILIAS  release_8 Revision v8.24
MediaTest.php
Go to the documentation of this file.
1<?php
2
4
5use PHPUnit\Framework\TestCase;
10
11require_once('./libs/composer/vendor/autoload.php');
12
18class MediaTest extends TestCase
19{
20 public string $version;
22
23 protected function setUp(): void
24 {
25 parent::setUp();
26 $this->version = '1.2.3.4.5.6.7.8.9';
27 $this->meta_content = new MetaContent($this->version);
28 }
29
30 public function testAddCssFile(): void
31 {
32 $path = '/path/to/file.css';
33 $this->meta_content->addCss($path);
34 $collection = $this->meta_content->getCss();
35
36 $first_item = iterator_to_array($collection->getItems())[0];
37 $this->assertInstanceOf(Css::class, $first_item);
38 $this->assertEquals($path . '?version=' . $this->version, $first_item->getContent());
39 $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
40 }
41
42 public function testAddCssFileWithQuery(): void
43 {
44 $path = '/path/to/file.css?my=query';
45 $this->meta_content->addCss($path);
46 $collection = $this->meta_content->getCss();
47
48 $first_item = iterator_to_array($collection->getItems())[0];
49 $this->assertInstanceOf(Css::class, $first_item);
50 $this->assertEquals($path . '&version=' . $this->version, $first_item->getContent());
51 $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
52 }
53
54 public function testAddInlineCss(): void
55 {
56 $css = 'body {background-color:red;}';
57 $this->meta_content->addInlineCss($css);
58 $collection = $this->meta_content->getInlineCss();
59
60 $first_item = iterator_to_array($collection->getItems())[0];
61 $this->assertInstanceOf(InlineCss::class, $first_item);
62 $this->assertEquals($css, $first_item->getContent());
63 $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
64 }
65
66 public function testAddJsFile(): void
67 {
68 $path = '/path/to/file.js';
69 $this->meta_content->addJs($path);
70 $collection = $this->meta_content->getJs();
71
72 $first_item = iterator_to_array($collection->getItems())[$path];
73 $this->assertInstanceOf(Js::class, $first_item);
74 $this->assertEquals($path . '?version=' . $this->version, $first_item->getContent());
75 $this->assertEquals(2, $first_item->getBatch());
76 }
77
78 public function testAddJsFileWithQuery(): void
79 {
80 $path = '/path/to/file.js';
81 $path_with_query = $path . '?my=query';
82 $this->meta_content->addJs($path_with_query);
83 $collection = $this->meta_content->getJs();
84
85 $first_item = iterator_to_array($collection->getItems())[$path];
86 $this->assertInstanceOf(Js::class, $first_item);
87 $this->assertEquals($path_with_query . '&version=' . $this->version, $first_item->getContent());
88 $this->assertEquals(2, $first_item->getBatch());
89 }
90}
$path
Definition: ltiservices.php:32
@noinspection PhpIncompatibleReturnTypeInspection