TYPO3 CMS  TYPO3_8-7
ResourceCompressorIntegrationTest.php
Go to the documentation of this file.
1 <?php
2 
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 
20 
25 {
26 
31 
35  protected $fixtureDir;
36 
41 
42  public function setUp()
43  {
44  $this->fixtureDir = 'sysext/core/Tests/Unit/Resource/ResourceCompressorTest/Fixtures/';
45  $this->fixtureDirFromTest = GeneralUtility::fixWindowsFilePath(__DIR__ . '/ResourceCompressorTest/Fixtures/');
46  }
47 
52  {
53  $this->resourceCompressor = new TestableResourceCompressor();
54  $dir = PATH_site . $this->resourceCompressor->getTargetDirectory();
55  self::assertFileExists($dir);
56  }
57 
62  {
63  $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = true;
64  $this->resourceCompressor = new TestableResourceCompressor();
65  $htaccessPath = PATH_site . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
66  self::assertStringEqualsFile($htaccessPath, $this->resourceCompressor->getHtaccessTemplate());
67  }
68 
73  {
74  $GLOBALS['TYPO3_CONF_VARS']['SYS']['generateApacheHtaccess'] = false;
75  $this->resourceCompressor = new TestableResourceCompressor();
76  $htaccessPath = PATH_site . $this->resourceCompressor->getTargetDirectory() . '.htaccess';
77  self::assertFileNotExists($htaccessPath);
78  }
79 
83  public function concatenateCssFiles()
84  {
85  $files = [
86  'sampleFile1' => [
87  'excludeFromConcatenation' => false,
88  'file' => $this->fixtureDir . 'css_input_with_import.css',
89  'media' => 'screen',
90  'forceOnTop' => false,
91  ],
92  ];
93  $this->resourceCompressor = new TestableResourceCompressor();
94  $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
95  $mergedFile = array_pop($concatFiles);
96  $expected = file_get_contents(
97  $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import.css'
98  );
99  self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(PATH_site . $mergedFile['file']), $expected);
100  }
101 
106  {
107  $testFile = PATH_site . 'typo3temp/var/transient/css_input_with_import.css';
108  $this->testFilesToDelete[] = $testFile;
109  copy(PATH_typo3 . $this->fixtureDir . 'css_input_with_import.css', $testFile);
110  $files = [
111  'sampleFile1' => [
112  'excludeFromConcatenation' => false,
113  'file' => 'typo3temp/var/transient/css_input_with_import.css',
114  'media' => 'screen',
115  'forceOnTop' => false,
116  ],
117  ];
118  $this->resourceCompressor = new TestableResourceCompressor();
119  $concatFiles = $this->resourceCompressor->concatenateCssFiles($files);
120  $mergedFile = array_pop($concatFiles);
121  $expected = file_get_contents(
122  $this->fixtureDirFromTest . 'expected' . DIRECTORY_SEPARATOR . 'merged-css_input_with_import_non_root.css'
123  );
124  self::assertStringEqualsFile(GeneralUtility::fixWindowsFilePath(PATH_site . $mergedFile['file']), $expected);
125  }
126 
127  public function tearDown()
128  {
129  $this->testFilesToDelete[] = PATH_site . $this->resourceCompressor->getTargetDirectory();
130  parent::tearDown();
131  }
132 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']