‪TYPO3CMS  9.5
ResourceCompressorIntegrationTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
22 
27 {
31  protected ‪$backupEnvironment = true;
32 
36  protected ‪$resourceCompressor;
37 
41  protected ‪$fixtureDir;
42 
46  protected ‪$fixtureDirFromTest;
47 
48  public function ‪setUp(): void
49  {
50  parent::setUp();
51  $this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
52  $this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
53  }
54 
58  public function ‪constructorCreatesTargetDirectory(): void
59  {
60  $this->resourceCompressor = new ‪TestableResourceCompressor();
61  ‪$dir = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
62  self::assertFileExists(‪$dir);
63  }
64 
68  public function ‪constructorCreatesHtaccessFileIfSet(): void
69  {
70  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = true;
71  $this->resourceCompressor = new ‪TestableResourceCompressor();
72  $htaccessPath = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
73  self::assertStringEqualsFile($htaccessPath, $this->resourceCompressor->getHtaccessTemplate());
74  }
75 
80  {
81  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = false;
82  $this->resourceCompressor = new ‪TestableResourceCompressor();
83  $htaccessPath = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
84  self::assertFileNotExists($htaccessPath);
85  }
86 
90  public function ‪concatenateCssFiles(): void
91  {
92  $files = [
93  'sampleFile1' => [
94  'excludeFromConcatenation' => false,
95  'file' => $this->fixtureDir . 'css_input_with_import.css',
96  'media' => 'screen',
97  'forceOnTop' => false,
98  ],
99  ];
100  $this->resourceCompressor = new ‪TestableResourceCompressor();
101  $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
102  $mergedFile = array_pop($concatFiles);
103  $expected = file_get_contents(
104  $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import.css'
105  );
106  self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(‪Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
107  }
108 
113  {
116  true,
117  false,
122  ‪Environment::getBackendPath() . '/index.php',
123  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
124  );
125  $testFile = ‪Environment::getPublicPath() . '/typo3temp/var/transient/css_input_with_import.css';
126  $this->testFilesToDelete[] = $testFile;
127  copy(‪Environment::getBackendPath() . '/' . $this->fixtureDir . 'css_input_with_import.css', $testFile);
128  $files = [
129  'sampleFile1' => [
130  'excludeFromConcatenation' => false,
131  'file' => 'typo3temp/var/transient/css_input_with_import.css',
132  'media' => 'screen',
133  'forceOnTop' => false,
134  ],
135  ];
136  $this->resourceCompressor = new ‪TestableResourceCompressor();
137  $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
138  $mergedFile = array_pop($concatFiles);
139  $expected = file_get_contents(
140  $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import_non_root.css'
141  );
142  self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(‪Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
143  }
144 
145  public function ‪tearDown(): void
146  {
147  $this->testFilesToDelete[] = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
148  parent::tearDown();
149  }
150 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$fixtureDir
‪string $fixtureDir
Definition: ResourceCompressorIntegrationTest.php:38
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\tearDown
‪tearDown()
Definition: ResourceCompressorIntegrationTest.php:141
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$fixtureDirFromTest
‪string $fixtureDirFromTest
Definition: ResourceCompressorIntegrationTest.php:42
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest
Definition: ResourceCompressorIntegrationTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
Definition: BaseTestCase.php:24
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static bool isWindows()
Definition: Environment.php:266
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\concatenateCssFiles
‪concatenateCssFiles()
Definition: ResourceCompressorIntegrationTest.php:86
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\setUp
‪setUp()
Definition: ResourceCompressorIntegrationTest.php:44
‪$dir
‪$dir
Definition: validateRstFiles.php:213
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static ApplicationContext getContext()
Definition: Environment.php:106
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\constructorCreatesHtaccessFileIfSet
‪constructorCreatesHtaccessFileIfSet()
Definition: ResourceCompressorIntegrationTest.php:64
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:142
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$resourceCompressor
‪TestableResourceCompressor $resourceCompressor
Definition: ResourceCompressorIntegrationTest.php:34
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\constructorDoesNotCreateHtaccessFileIfSetToFalse
‪constructorDoesNotCreateHtaccessFileIfSetToFalse()
Definition: ResourceCompressorIntegrationTest.php:75
‪TYPO3\CMS\Core\Core\Environment\initialize
‪static initialize(ApplicationContext $context, bool $cli, bool $composerMode, string $projectPath, string $publicPath, string $varPath, string $configPath, string $currentScript, string $os)
Definition: Environment.php:77
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorTest\Fixtures\TestableResourceCompressor
Definition: TestableResourceCompressor.php:22
‪TYPO3\CMS\Core\Core\Environment\getBackendPath
‪static string getBackendPath()
Definition: Environment.php:223
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\constructorCreatesTargetDirectory
‪constructorCreatesTargetDirectory()
Definition: ResourceCompressorIntegrationTest.php:54
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\concatenateCssFilesWorksWithFileFromNonRootPath
‪concatenateCssFilesWorksWithFileFromNonRootPath()
Definition: ResourceCompressorIntegrationTest.php:108
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static string getConfigPath()
Definition: Environment.php:183
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$backupEnvironment
‪bool $backupEnvironment
Definition: ResourceCompressorIntegrationTest.php:30
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165