[BUGFIX] Flag compressed files to exclude from compression 79/29579/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Sat, 19 Apr 2014 14:16:38 +0000 (16:16 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 6 May 2014 20:38:48 +0000 (22:38 +0200)
Resolves: #58582
Related: #58010
Related: #57294
Releases: 6.2
Change-Id: I89e9bea10c24944ad2efb1fb9029ec75dc2f78db
Reviewed-on: https://review.typo3.org/29579
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/core/Classes/Resource/ResourceCompressor.php
typo3/sysext/core/Tests/Unit/Resource/ResourceCompressorTest.php

index ce17ee4..7cf059e 100644 (file)
@@ -205,6 +205,7 @@ class ResourceCompressor {
                                'rel' => 'stylesheet',
                                'media' => 'all',
                                'compress' => TRUE,
+                               'excludeFromConcatenation' => TRUE,
                                'forceOnTop' => FALSE,
                                'allWrap' => ''
                        );
@@ -249,6 +250,7 @@ class ResourceCompressor {
                                        'type' => 'text/javascript',
                                        'section' => $section,
                                        'compress' => TRUE,
+                                       'excludeFromConcatenation' => TRUE,
                                        'forceOnTop' => FALSE,
                                        'allWrap' => ''
                                );
@@ -360,6 +362,7 @@ class ResourceCompressor {
                        // if compression is enabled
                        if ($fileOptions['compress']) {
                                $filename = $this->compressCssFile($fileOptions['file']);
+                               $fileOptions['compress'] = FALSE;
                                $fileOptions['file'] = $filename;
                                $filesAfterCompression[$filename] = $fileOptions;
                        } else {
@@ -509,6 +512,7 @@ class ResourceCompressor {
                        // If compression is enabled
                        if ($fileOptions['compress']) {
                                $compressedFilename = $this->compressJsFile($fileOptions['file']);
+                               $fileOptions['compress'] = FALSE;
                                $fileOptions['file'] = $compressedFilename;
                                $filesAfterCompression[$compressedFilename] = $fileOptions;
                        } else {
index a32305c..a3043d1 100644 (file)
@@ -35,7 +35,7 @@ use TYPO3\CMS\Core\Resource\ResourceCompressor;
 class ResourceCompressorTest extends BaseTestCase {
 
        /**
-        * @var \TYPO3\CMS\Core\Resource\ResourceCompressor
+        * @var \TYPO3\CMS\Core\Resource\ResourceCompressor|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
         */
        protected $subject;
 
@@ -44,7 +44,7 @@ class ResourceCompressorTest extends BaseTestCase {
         */
        public function setUp() {
                parent::setUp();
-               $this->subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceCompressor', array('dummy'));
+               $this->subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceCompressor', array('compressCssFile', 'compressJsFile', 'createMergedCssFile', 'createMergedJsFile', 'getFilenameFromMainDir', 'checkBaseDirectory'));
        }
 
        /**
@@ -89,4 +89,103 @@ class ResourceCompressorTest extends BaseTestCase {
                $this->assertEquals($expected, $resultWithReadableLinefeed);
        }
 
+       /**
+        * @test
+        */
+       public function compressedCssFileIsFlaggedToNotCompressAgain() {
+               $fileName = 'fooFile.css';
+               $compressedFileName = $fileName . '.gz';
+               $testFileFixture = array(
+                       $fileName => array(
+                               'file' => $fileName,
+                               'compress' => TRUE,
+                       )
+               );
+               $this->subject->expects($this->once())
+                       ->method('compressCssFile')
+                       ->with($fileName)
+                       ->will($this->returnValue($compressedFileName));
+
+               $result = $this->subject->compressCssFiles($testFileFixture);
+
+               $this->assertArrayHasKey($compressedFileName, $result);
+               $this->assertArrayHasKey('compress', $result[$compressedFileName]);
+               $this->assertFalse($result[$compressedFileName]['compress']);
+       }
+
+       /**
+        * @test
+        */
+       public function compressedJsFileIsFlaggedToNotCompressAgain() {
+               $fileName = 'fooFile.js';
+               $compressedFileName = $fileName . '.gz';
+               $testFileFixture = array(
+                       $fileName => array(
+                               'file' => $fileName,
+                               'compress' => TRUE,
+                       )
+               );
+               $this->subject->expects($this->once())
+                       ->method('compressJsFile')
+                       ->with($fileName)
+                       ->will($this->returnValue($compressedFileName));
+
+               $result = $this->subject->compressJsFiles($testFileFixture);
+
+               $this->assertArrayHasKey($compressedFileName, $result);
+               $this->assertArrayHasKey('compress', $result[$compressedFileName]);
+               $this->assertFalse($result[$compressedFileName]['compress']);
+       }
+
+
+       /**
+        * @test
+        */
+       public function concatenatedCssFileIsFlaggedToNotConcatenateAgain() {
+               $fileName = 'fooFile.css';
+               $concatenatedFileName = 'merged_' . $fileName;
+               $testFileFixture = array(
+                       $fileName => array(
+                               'file' => $fileName,
+                               'excludeFromConcatenation' => FALSE,
+                               'media' => 'all',
+                       )
+               );
+               $this->subject->expects($this->once())
+                       ->method('createMergedCssFile')
+                       ->will($this->returnValue($concatenatedFileName));
+               $this->subject->setRelativePath('');
+
+               $result = $this->subject->concatenateCssFiles($testFileFixture);
+
+               $this->assertArrayHasKey($concatenatedFileName, $result);
+               $this->assertArrayHasKey('excludeFromConcatenation', $result[$concatenatedFileName]);
+               $this->assertTrue($result[$concatenatedFileName]['excludeFromConcatenation']);
+       }
+
+       /**
+        * @test
+        */
+       public function concatenatedJsFileIsFlaggedToNotConcatenateAgain() {
+               $fileName = 'fooFile.js';
+               $concatenatedFileName = 'merged_' . $fileName;
+               $testFileFixture = array(
+                       $fileName => array(
+                               'file' => $fileName,
+                               'excludeFromConcatenation' => FALSE,
+                               'section' => 'top',
+                       )
+               );
+               $this->subject->expects($this->once())
+                       ->method('createMergedJsFile')
+                       ->will($this->returnValue($concatenatedFileName));
+               $this->subject->setRelativePath('');
+
+               $result = $this->subject->concatenateJsFiles($testFileFixture);
+
+               $this->assertArrayHasKey($concatenatedFileName, $result);
+               $this->assertArrayHasKey('excludeFromConcatenation', $result[$concatenatedFileName]);
+               $this->assertTrue($result[$concatenatedFileName]['excludeFromConcatenation']);
+       }
+
 }
\ No newline at end of file