ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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{
23 public $version;
28
29 protected function setUp() : void
30 {
31 parent::setUp();
32 $this->version = '1.2.3.4.5.6.7.8.9';
33 $this->meta_content = new MetaContent($this->version);
34 }
35
36 public function testAddCssFile() : void
37 {
38 $path = '/path/to/file.css';
39 $this->meta_content->addCss($path);
40 $collection = $this->meta_content->getCss();
41
42 $first_item = iterator_to_array($collection->getItems())[0];
43 $this->assertInstanceOf(Css::class, $first_item);
44 $this->assertEquals($path . '?version=' . $this->version, $first_item->getContent());
45 $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
46 }
47
48 public function testAddCssFileWithQuery() : void
49 {
50 $path = '/path/to/file.css?my=query';
51 $this->meta_content->addCss($path);
52 $collection = $this->meta_content->getCss();
53
54 $first_item = iterator_to_array($collection->getItems())[0];
55 $this->assertInstanceOf(Css::class, $first_item);
56 $this->assertEquals($path . '&version=' . $this->version, $first_item->getContent());
57 $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
58 }
59
60 public function testAddInlineCss() : void
61 {
62 $css = 'body {background-color:red;}';
63 $this->meta_content->addInlineCss($css);
64 $collection = $this->meta_content->getInlineCss();
65
66 $first_item = iterator_to_array($collection->getItems())[0];
67 $this->assertInstanceOf(InlineCss::class, $first_item);
68 $this->assertEquals($css, $first_item->getContent());
69 $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
70 }
71
72 public function testAddJsFile() : void
73 {
74 $path = '/path/to/file.js';
75 $this->meta_content->addJs($path);
76 $collection = $this->meta_content->getJs();
77
78 $first_item = iterator_to_array($collection->getItems())[$path];
79 $this->assertInstanceOf(Js::class, $first_item);
80 $this->assertEquals($path . '?version=' . $this->version, $first_item->getContent());
81 $this->assertEquals(2, $first_item->getBatch());
82 }
83
84 public function testAddJsFileWithQuery() : void
85 {
86 $path = '/path/to/file.js';
87 $path_with_query = $path . '?my=query';
88 $this->meta_content->addJs($path_with_query);
89 $collection = $this->meta_content->getJs();
90
91 $first_item = iterator_to_array($collection->getItems())[$path];
92 $this->assertInstanceOf(Js::class, $first_item);
93 $this->assertEquals($path_with_query . '&version=' . $this->version, $first_item->getContent());
94 $this->assertEquals(2, $first_item->getBatch());
95 }
96}
An exception for terminatinating execution or to throw for unit testing.