‪TYPO3CMS  10.4
ResourceCompressorIntegrationTest.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 
23 
28 {
32  protected ‪$backupEnvironment = true;
33 
37  protected ‪$resourceCompressor;
38 
42  protected ‪$fixtureDir;
43 
47  protected ‪$fixtureDirFromTest;
48 
49  public function ‪setUp(): void
50  {
51  parent::setUp();
52  $this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
53  $this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
54  }
55 
56  public function ‪tearDown(): void
57  {
58  $this->testFilesToDelete[] = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
59  parent::tearDown();
60  }
61 
65  public function ‪constructorCreatesTargetDirectory(): void
66  {
67  $this->resourceCompressor = new ‪TestableResourceCompressor();
68  ‪$dir = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory();
69  self::assertFileExists(‪$dir);
70  }
71 
75  public function ‪constructorCreatesHtaccessFileIfSet(): void
76  {
77  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = true;
78  $this->resourceCompressor = new ‪TestableResourceCompressor();
79  $htaccessPath = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
80  self::assertStringEqualsFile($htaccessPath, $this->resourceCompressor->getHtaccessTemplate());
81  }
82 
87  {
88  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = false;
89  $this->resourceCompressor = new ‪TestableResourceCompressor();
90  $htaccessPath = ‪Environment::getPublicPath() . '/' . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
91  // @todo remove condition and else branch as soon as phpunit v8 goes out of support
92  if (method_exists($this, 'assertFileDoesNotExist')) {
93  self::assertFileDoesNotExist($htaccessPath);
94  } else {
95  self::assertFileNotExists($htaccessPath);
96  }
97  }
98 
102  public function ‪concatenateCssFiles(): void
103  {
104  $files = [
105  'sampleFile1' => [
106  'excludeFromConcatenation' => false,
107  'file' => $this->fixtureDir . 'css_input_with_import.css',
108  'media' => 'screen',
109  'forceOnTop' => false,
110  ],
111  ];
112  $this->resourceCompressor = new ‪TestableResourceCompressor();
113  $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
114  $mergedFile = array_pop($concatFiles);
115  $expected = file_get_contents(
116  $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import.css'
117  );
118  self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(‪Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
119  }
124  {
127  true,
128  false,
133  ‪Environment::getBackendPath() . '/index.php',
134  ‪Environment::isWindows() ? 'WINDOWS' : 'UNIX'
135  );
136  $testFile = ‪Environment::getPublicPath() . '/typo3temp/var/transient/css_input_with_import.css';
137  $this->testFilesToDelete[] = $testFile;
138  copy(‪Environment::getBackendPath() . '/' . $this->fixtureDir . 'css_input_with_import.css', $testFile);
139  $files = [
140  'sampleFile1' => [
141  'excludeFromConcatenation' => false,
142  'file' => 'typo3temp/var/transient/css_input_with_import.css',
143  'media' => 'screen',
144  'forceOnTop' => false,
145  ],
146  ];
147  $this->resourceCompressor = new ‪TestableResourceCompressor();
148  $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
149  $mergedFile = array_pop($concatFiles);
150  $expected = file_get_contents(
151  $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import_non_root.css'
152  );
153  self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(‪Environment::getPublicPath() . '/' . $mergedFile['file']), $expected);
154  }
155 }
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$fixtureDir
‪string $fixtureDir
Definition: ResourceCompressorIntegrationTest.php:39
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\tearDown
‪tearDown()
Definition: ResourceCompressorIntegrationTest.php:52
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$fixtureDirFromTest
‪string $fixtureDirFromTest
Definition: ResourceCompressorIntegrationTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest
Definition: ResourceCompressorIntegrationTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Resource
Definition: AbstractFileTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase
Definition: BaseTestCase.php:29
‪TYPO3\CMS\Core\Core\Environment\isWindows
‪static bool isWindows()
Definition: Environment.php:292
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\concatenateCssFiles
‪concatenateCssFiles()
Definition: ResourceCompressorIntegrationTest.php:98
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\setUp
‪setUp()
Definition: ResourceCompressorIntegrationTest.php:45
‪$dir
‪$dir
Definition: validateRstFiles.php:213
‪TYPO3\CMS\Core\Core\Environment\getContext
‪static ApplicationContext getContext()
Definition: Environment.php:133
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\constructorCreatesHtaccessFileIfSet
‪constructorCreatesHtaccessFileIfSet()
Definition: ResourceCompressorIntegrationTest.php:71
‪TYPO3\CMS\Core\Core\Environment\getProjectPath
‪static string getProjectPath()
Definition: Environment.php:169
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$resourceCompressor
‪TestableResourceCompressor $resourceCompressor
Definition: ResourceCompressorIntegrationTest.php:35
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\constructorDoesNotCreateHtaccessFileIfSetToFalse
‪constructorDoesNotCreateHtaccessFileIfSetToFalse()
Definition: ResourceCompressorIntegrationTest.php:82
‪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:104
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorTest\Fixtures\TestableResourceCompressor
Definition: TestableResourceCompressor.php:23
‪TYPO3\CMS\Core\Core\Environment\getBackendPath
‪static string getBackendPath()
Definition: Environment.php:250
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\constructorCreatesTargetDirectory
‪constructorCreatesTargetDirectory()
Definition: ResourceCompressorIntegrationTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\concatenateCssFilesWorksWithFileFromNonRootPath
‪concatenateCssFilesWorksWithFileFromNonRootPath()
Definition: ResourceCompressorIntegrationTest.php:119
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪TYPO3\CMS\Core\Core\Environment\getConfigPath
‪static string getConfigPath()
Definition: Environment.php:210
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Resource\ResourceCompressorIntegrationTest\$backupEnvironment
‪bool $backupEnvironment
Definition: ResourceCompressorIntegrationTest.php:31
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:192