ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
MediaTest.php
Go to the documentation of this file.
1 <?php
2 
20 
26 
27 require_once('./libs/composer/vendor/autoload.php');
28 
34 class MediaTest extends TestCase
35 {
39  public $version;
43  public $meta_content;
44 
45  protected function setUp() : void
46  {
47  parent::setUp();
48  $this->version = '1.2.3.4.5.6.7.8.9';
49  $this->meta_content = new MetaContent($this->version);
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  $first_item = iterator_to_array($collection->getItems())[0];
59  $this->assertInstanceOf(Css::class, $first_item);
60  $this->assertEquals($path . '?version=' . $this->version, $first_item->getContent());
61  $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
62  }
63 
64  public function testAddCssFileWithQuery() : void
65  {
66  $path = '/path/to/file.css?my=query';
67  $this->meta_content->addCss($path);
68  $collection = $this->meta_content->getCss();
69 
70  $first_item = iterator_to_array($collection->getItems())[0];
71  $this->assertInstanceOf(Css::class, $first_item);
72  $this->assertEquals($path . '&version=' . $this->version, $first_item->getContent());
73  $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
74  }
75 
76  public function testAddInlineCss() : void
77  {
78  $css = 'body {background-color:red;}';
79  $this->meta_content->addInlineCss($css);
80  $collection = $this->meta_content->getInlineCss();
81 
82  $first_item = iterator_to_array($collection->getItems())[0];
83  $this->assertInstanceOf(InlineCss::class, $first_item);
84  $this->assertEquals($css, $first_item->getContent());
85  $this->assertEquals(MetaContent::MEDIA_SCREEN, $first_item->getMedia());
86  }
87 
88  public function testAddJsFile() : void
89  {
90  $path = '/path/to/file.js';
91  $this->meta_content->addJs($path);
92  $collection = $this->meta_content->getJs();
93 
94  $first_item = iterator_to_array($collection->getItems())[$path];
95  $this->assertInstanceOf(Js::class, $first_item);
96  $this->assertEquals($path . '?version=' . $this->version, $first_item->getContent());
97  $this->assertEquals(2, $first_item->getBatch());
98  }
99 
100  public function testAddJsFileWithQuery() : void
101  {
102  $path = '/path/to/file.js';
103  $path_with_query = $path . '?my=query';
104  $this->meta_content->addJs($path_with_query);
105  $collection = $this->meta_content->getJs();
106 
107  $first_item = iterator_to_array($collection->getItems())[$path];
108  $this->assertInstanceOf(Js::class, $first_item);
109  $this->assertEquals($path_with_query . '&version=' . $this->version, $first_item->getContent());
110  $this->assertEquals(2, $first_item->getBatch());
111  }
112 }
PhpIncompatibleReturnTypeInspection