0ee19b43594b31eecf70248273190d59ec3d95f1
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / ResourceCompressorIntegrationTest.php
1 <?php
2
3 namespace TYPO3\CMS\Core\Tests\Unit\Resource;
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
18 use TYPO3\CMS\Core\Core\Environment;
19 use TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorTest\Fixtures\TestableResourceCompressor;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Test case
24 */
25 class ResourceCompressorIntegrationTest extends BaseTestCase
26 {
27 /**
28 * Subject is not notice free, disable E_NOTICES
29 */
30 protected static $suppressNotices = true;
31
32 /**
33 * @var TestableResourceCompressor
34 */
35 protected $resourceCompressor;
36
37 /**
38 * @var string
39 */
40 protected $fixtureDir;
41
42 /**
43 * @var string
44 */
45 protected $fixtureDirFromTest;
46
47 public function setUp()
48 {
49 $this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
50 $this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
51 }
52
53 /**
54 * @test
55 */
56 public function constructorCreatesTargetDirectory()
57 {
58 $this->resourceCompressor = new TestableResourceCompressor();
59 $dir = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
60 self::assertFileExists($dir);
61 }
62
63 /**
64 * @test
65 */
66 public function constructorCreatesHtaccessFileIfSet()
67 {
68 $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = true;
69 $this->resourceCompressor = new TestableResourceCompressor();
70 $htaccessPath = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
71 self::assertStringEqualsFile($htaccessPath, $this->resourceCompressor->getHtaccessTemplate());
72 }
73
74 /**
75 * @test
76 */
77 public function constructorDoesNotCreateHtaccessFileIfSetToFalse()
78 {
79 $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = false;
80 $this->resourceCompressor = new TestableResourceCompressor();
81 $htaccessPath = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
82 self::assertFileNotExists($htaccessPath);
83 }
84
85 /**
86 * @test
87 */
88 public function concatenateCssFiles()
89 {
90 $files = [
91 'sampleFile1' => [
92 'excludeFromConcatenation' => false,
93 'file' => $this->fixtureDir . 'css_input_with_import.css',
94 'media' => 'screen',
95 'forceOnTop' => false,
96 ],
97 ];
98 $this->resourceCompressor = new TestableResourceCompressor();
99 $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
100 $mergedFile = array_pop($concatFiles);
101 $expected = file_get_contents(
102 $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import.css'
103 );
104 self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
105 }
106
107 /**
108 * @test
109 */
110 public function concatenateCssFilesWorksWithFileFromNonRootPath()
111 {
112 $testFile = Environment::getPublicPath() . '/typo3temp/var/transient/css_input_with_import.css';
113 $this->testFilesToDelete[] = $testFile;
114 copy(Environment::getBackendPath() . '/' . $this->fixtureDir . 'css_input_with_import.css', $testFile);
115 $files = [
116 'sampleFile1' => [
117 'excludeFromConcatenation' => false,
118 'file' => 'typo3temp/var/transient/css_input_with_import.css',
119 'media' => 'screen',
120 'forceOnTop' => false,
121 ],
122 ];
123 $this->resourceCompressor = new TestableResourceCompressor();
124 $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
125 $mergedFile = array_pop($concatFiles);
126 $expected = file_get_contents(
127 $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import_non_root.css'
128 );
129 self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
130 }
131
132 public function tearDown()
133 {
134 $this->testFilesToDelete[] = Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
135 parent::tearDown();
136 }
137 }