‪TYPO3CMS  10.4
AssetCollectorTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 class ‪AssetCollectorTest extends UnitTestCase
25 {
29  protected ‪$assetCollector;
30 
31  public function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->resetSingletonInstances = true;
35  $this->assetCollector = GeneralUtility::makeInstance(AssetCollector::class);
36  }
37 
43  public function ‪testStyleSheets(array $files, array $expectedResult): void
44  {
45  foreach ($files as $file) {
46  [$identifier, $source, $attributes, $options] = $file;
47  $this->assetCollector->addStyleSheet($identifier, $source, $attributes, $options);
48  }
49  self::assertSame($expectedResult, $this->assetCollector->getStyleSheets());
50  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
51  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
52  self::assertSame([], $this->assetCollector->getJavaScripts());
53  self::assertSame([], $this->assetCollector->getMedia());
54  foreach ($files as $file) {
55  [$identifier] = $file;
56  $this->assetCollector->removeStyleSheet($identifier);
57  }
58  self::assertSame([], $this->assetCollector->getStyleSheets());
59  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
60  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
61  self::assertSame([], $this->assetCollector->getJavaScripts());
62  self::assertSame([], $this->assetCollector->getMedia());
63  }
64 
70  public function ‪testJavaScript(array $files, array $expectedResult): void
71  {
72  foreach ($files as $file) {
73  [$identifier, $source, $attributes, $options] = $file;
74  $this->assetCollector->addJavaScript($identifier, $source, $attributes, $options);
75  }
76  self::assertSame($expectedResult, $this->assetCollector->getJavaScripts());
77  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
78  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
79  self::assertSame([], $this->assetCollector->getStyleSheets());
80  self::assertSame([], $this->assetCollector->getMedia());
81  foreach ($files as $file) {
82  [$identifier] = $file;
83  $this->assetCollector->removeJavaScript($identifier);
84  }
85  self::assertSame([], $this->assetCollector->getJavaScripts());
86  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
87  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
88  self::assertSame([], $this->assetCollector->getStyleSheets());
89  self::assertSame([], $this->assetCollector->getMedia());
90  }
91 
97  public function ‪testInlineJavaScript(array $sources, array $expectedResult): void
98  {
99  foreach ($sources as $source) {
100  [$identifier, $source, $attributes, $options] = $source;
101  $this->assetCollector->addInlineJavaScript($identifier, $source, $attributes, $options);
102  }
103  self::assertSame($expectedResult, $this->assetCollector->getInlineJavaScripts());
104  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
105  self::assertSame([], $this->assetCollector->getJavaScripts());
106  self::assertSame([], $this->assetCollector->getStyleSheets());
107  self::assertSame([], $this->assetCollector->getMedia());
108  foreach ($sources as $source) {
109  [$identifier] = $source;
110  $this->assetCollector->removeInlineJavaScript($identifier);
111  }
112  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
113  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
114  self::assertSame([], $this->assetCollector->getJavaScripts());
115  self::assertSame([], $this->assetCollector->getStyleSheets());
116  self::assertSame([], $this->assetCollector->getMedia());
117  }
118 
124  public function ‪testInlineStyles(array $sources, array $expectedResult): void
125  {
126  foreach ($sources as $source) {
127  [$identifier, $source, $attributes, $options] = $source;
128  $this->assetCollector->addInlineStyleSheet($identifier, $source, $attributes, $options);
129  }
130  self::assertSame($expectedResult, $this->assetCollector->getInlineStyleSheets());
131  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
132  self::assertSame([], $this->assetCollector->getJavaScripts());
133  self::assertSame([], $this->assetCollector->getStyleSheets());
134  self::assertSame([], $this->assetCollector->getMedia());
135  foreach ($sources as $source) {
136  [$identifier] = $source;
137  $this->assetCollector->removeInlineStyleSheet($identifier);
138  }
139  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
140  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
141  self::assertSame([], $this->assetCollector->getJavaScripts());
142  self::assertSame([], $this->assetCollector->getStyleSheets());
143  self::assertSame([], $this->assetCollector->getMedia());
144  }
145 
151  public function ‪testMedia(array $images, array $expectedResult): void
152  {
153  foreach ($images as $image) {
154  [$fileName, $additionalInformation] = $image;
155  $this->assetCollector->addMedia($fileName, $additionalInformation);
156  }
157  self::assertSame($expectedResult, $this->assetCollector->getMedia());
158  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
159  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
160  self::assertSame([], $this->assetCollector->getJavaScripts());
161  self::assertSame([], $this->assetCollector->getStyleSheets());
162  foreach ($images as $image) {
163  [$fileName] = $image;
164  $this->assetCollector->removeMedia($fileName);
165  }
166  self::assertSame([], $this->assetCollector->getMedia());
167  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
168  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
169  self::assertSame([], $this->assetCollector->getJavaScripts());
170  self::assertSame([], $this->assetCollector->getStyleSheets());
171  }
172 }
‪TYPO3\CMS\Core\Page\AssetCollector
Definition: AssetCollector.php:44
‪TYPO3\CMS\Core\Tests\Unit\Page
Definition: AssetCollectorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\testMedia
‪testMedia(array $images, array $expectedResult)
Definition: AssetCollectorTest.php:150
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\setUp
‪setUp()
Definition: AssetCollectorTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\testInlineStyles
‪testInlineStyles(array $sources, array $expectedResult)
Definition: AssetCollectorTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\$assetCollector
‪AssetCollector $assetCollector
Definition: AssetCollectorTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest
Definition: AssetCollectorTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\testInlineJavaScript
‪testInlineJavaScript(array $sources, array $expectedResult)
Definition: AssetCollectorTest.php:96
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\testJavaScript
‪testJavaScript(array $files, array $expectedResult)
Definition: AssetCollectorTest.php:69
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\testStyleSheets
‪testStyleSheets(array $files, array $expectedResult)
Definition: AssetCollectorTest.php:42