‪TYPO3CMS  11.5
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 {
27 
28  public function ‪setUp(): void
29  {
30  parent::setUp();
31  $this->resetSingletonInstances = true;
32  $this->assetCollector = GeneralUtility::makeInstance(AssetCollector::class);
33  }
34 
41  public function ‪styleSheets(array $files, array $expectedResult): void
42  {
43  foreach ($files as $file) {
44  [$identifier, $source, $attributes, $options] = $file;
45  $this->assetCollector->addStyleSheet($identifier, $source, $attributes, $options);
46  }
47  self::assertSame($expectedResult, $this->assetCollector->getStyleSheets());
48  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
49  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
50  self::assertSame([], $this->assetCollector->getJavaScripts());
51  self::assertSame([], $this->assetCollector->getMedia());
52  foreach ($files as $file) {
53  [$identifier] = $file;
54  $this->assetCollector->removeStyleSheet($identifier);
55  }
56  self::assertSame([], $this->assetCollector->getStyleSheets());
57  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
58  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
59  self::assertSame([], $this->assetCollector->getJavaScripts());
60  self::assertSame([], $this->assetCollector->getMedia());
61  }
62 
69  public function ‪javaScript(array $files, array $expectedResult): void
70  {
71  foreach ($files as $file) {
72  [$identifier, $source, $attributes, $options] = $file;
73  $this->assetCollector->addJavaScript($identifier, $source, $attributes, $options);
74  }
75  self::assertSame($expectedResult, $this->assetCollector->getJavaScripts());
76  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
77  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
78  self::assertSame([], $this->assetCollector->getStyleSheets());
79  self::assertSame([], $this->assetCollector->getMedia());
80  foreach ($files as $file) {
81  [$identifier] = $file;
82  $this->assetCollector->removeJavaScript($identifier);
83  }
84  self::assertSame([], $this->assetCollector->getJavaScripts());
85  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
86  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
87  self::assertSame([], $this->assetCollector->getStyleSheets());
88  self::assertSame([], $this->assetCollector->getMedia());
89  }
90 
97  public function ‪inlineJavaScript(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 
125  public function ‪inlineStyles(array $sources, array $expectedResult): void
126  {
127  foreach ($sources as $source) {
128  [$identifier, $source, $attributes, $options] = $source;
129  $this->assetCollector->addInlineStyleSheet($identifier, $source, $attributes, $options);
130  }
131  self::assertSame($expectedResult, $this->assetCollector->getInlineStyleSheets());
132  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
133  self::assertSame([], $this->assetCollector->getJavaScripts());
134  self::assertSame([], $this->assetCollector->getStyleSheets());
135  self::assertSame([], $this->assetCollector->getMedia());
136  foreach ($sources as $source) {
137  [$identifier] = $source;
138  $this->assetCollector->removeInlineStyleSheet($identifier);
139  }
140  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
141  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
142  self::assertSame([], $this->assetCollector->getJavaScripts());
143  self::assertSame([], $this->assetCollector->getStyleSheets());
144  self::assertSame([], $this->assetCollector->getMedia());
145  }
146 
153  public function ‪media(array $images, array $expectedResult): void
154  {
155  foreach ($images as $image) {
156  [$fileName, $additionalInformation] = $image;
157  $this->assetCollector->addMedia($fileName, $additionalInformation);
158  }
159  self::assertSame($expectedResult, $this->assetCollector->getMedia());
160  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
161  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
162  self::assertSame([], $this->assetCollector->getJavaScripts());
163  self::assertSame([], $this->assetCollector->getStyleSheets());
164  foreach ($images as $image) {
165  [$fileName] = $image;
166  $this->assetCollector->removeMedia($fileName);
167  }
168  self::assertSame([], $this->assetCollector->getMedia());
169  self::assertSame([], $this->assetCollector->getInlineStyleSheets());
170  self::assertSame([], $this->assetCollector->getInlineJavaScripts());
171  self::assertSame([], $this->assetCollector->getJavaScripts());
172  self::assertSame([], $this->assetCollector->getStyleSheets());
173  }
174 }
‪TYPO3\CMS\Core\Page\AssetCollector
Definition: AssetCollector.php:42
‪TYPO3\CMS\Core\Tests\Unit\Page
Definition: AssetCollectorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\setUp
‪setUp()
Definition: AssetCollectorTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\$assetCollector
‪AssetCollector $assetCollector
Definition: AssetCollectorTest.php:26
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\media
‪media(array $images, array $expectedResult)
Definition: AssetCollectorTest.php:153
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest
Definition: AssetCollectorTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\javaScript
‪javaScript(array $files, array $expectedResult)
Definition: AssetCollectorTest.php:69
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\styleSheets
‪styleSheets(array $files, array $expectedResult)
Definition: AssetCollectorTest.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\inlineJavaScript
‪inlineJavaScript(array $sources, array $expectedResult)
Definition: AssetCollectorTest.php:97
‪TYPO3\CMS\Core\Tests\Unit\Page\AssetCollectorTest\inlineStyles
‪inlineStyles(array $sources, array $expectedResult)
Definition: AssetCollectorTest.php:125