TYPO3 CMS  TYPO3_6-2
ResourceCompressorTest.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
29  protected $subject;
30 
34  public function setUp() {
35  parent::setUp();
36  $this->subject = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceCompressor', array('compressCssFile', 'compressJsFile', 'createMergedCssFile', 'createMergedJsFile', 'getFilenameFromMainDir', 'checkBaseDirectory'));
37  }
38 
42  public function cssFixStatementsDataProvider() {
43  return array(
44  'nothing to do - no charset/import/namespace' => array(
45  'body { background: #ffffff; }',
46  'body { background: #ffffff; }'
47  ),
48  'import in front' => array(
49  '@import url(http://www.example.com/css); body { background: #ffffff; }',
50  'LF/* moved by compressor */LF@import url(http://www.example.com/css);LFbody { background: #ffffff; }'
51  ),
52  'import in back, without quotes' => array(
53  'body { background: #ffffff; } @import url(http://www.example.com/css);',
54  'LF/* moved by compressor */LF@import url(http://www.example.com/css);LFbody { background: #ffffff; }'
55  ),
56  'import in back, with double-quotes' => array(
57  'body { background: #ffffff; } @import url("http://www.example.com/css");',
58  'LF/* moved by compressor */LF@import url("http://www.example.com/css");LFbody { background: #ffffff; }'
59  ),
60  'import in back, with single-quotes' => array(
61  'body { background: #ffffff; } @import url(\'http://www.example.com/css\');',
62  'LF/* moved by compressor */LF@import url(\'http://www.example.com/css\');LFbody { background: #ffffff; }'
63  ),
64  'import in middle and back, without quotes' => array(
65  'body { background: #ffffff; } @import url(http://www.example.com/A); div { background: #000; } @import url(http://www.example.com/B);',
66  'LF/* moved by compressor */LF@import url(http://www.example.com/A);LF/* moved by compressor */LF@import url(http://www.example.com/B);LFbody { background: #ffffff; } div { background: #000; }'
67  ),
68  );
69  }
70 
75  public function cssFixStatementsMovesStatementsToTopIfNeeded($input, $expected) {
76  $result = $this->subject->_call('cssFixStatements', $input);
77  $resultWithReadableLinefeed = str_replace(LF, 'LF', $result);
78  $this->assertEquals($expected, $resultWithReadableLinefeed);
79  }
80 
85  $fileName = 'fooFile.css';
86  $compressedFileName = $fileName . '.gz';
87  $testFileFixture = array(
88  $fileName => array(
89  'file' => $fileName,
90  'compress' => TRUE,
91  )
92  );
93  $this->subject->expects($this->once())
94  ->method('compressCssFile')
95  ->with($fileName)
96  ->will($this->returnValue($compressedFileName));
97 
98  $result = $this->subject->compressCssFiles($testFileFixture);
99 
100  $this->assertArrayHasKey($compressedFileName, $result);
101  $this->assertArrayHasKey('compress', $result[$compressedFileName]);
102  $this->assertFalse($result[$compressedFileName]['compress']);
103  }
104 
109  $fileName = 'fooFile.js';
110  $compressedFileName = $fileName . '.gz';
111  $testFileFixture = array(
112  $fileName => array(
113  'file' => $fileName,
114  'compress' => TRUE,
115  )
116  );
117  $this->subject->expects($this->once())
118  ->method('compressJsFile')
119  ->with($fileName)
120  ->will($this->returnValue($compressedFileName));
121 
122  $result = $this->subject->compressJsFiles($testFileFixture);
123 
124  $this->assertArrayHasKey($compressedFileName, $result);
125  $this->assertArrayHasKey('compress', $result[$compressedFileName]);
126  $this->assertFalse($result[$compressedFileName]['compress']);
127  }
128 
129 
134  $fileName = 'fooFile.css';
135  $concatenatedFileName = 'merged_' . $fileName;
136  $testFileFixture = array(
137  $fileName => array(
138  'file' => $fileName,
139  'excludeFromConcatenation' => FALSE,
140  'media' => 'all',
141  )
142  );
143  $this->subject->expects($this->once())
144  ->method('createMergedCssFile')
145  ->will($this->returnValue($concatenatedFileName));
146  $this->subject->setRelativePath('');
147 
148  $result = $this->subject->concatenateCssFiles($testFileFixture);
149 
150  $this->assertArrayHasKey($concatenatedFileName, $result);
151  $this->assertArrayHasKey('excludeFromConcatenation', $result[$concatenatedFileName]);
152  $this->assertTrue($result[$concatenatedFileName]['excludeFromConcatenation']);
153  }
154 
159  $fileName = 'fooFile.js';
160  $concatenatedFileName = 'merged_' . $fileName;
161  $testFileFixture = array(
162  $fileName => array(
163  'file' => $fileName,
164  'excludeFromConcatenation' => FALSE,
165  'section' => 'top',
166  )
167  );
168  $this->subject->expects($this->once())
169  ->method('createMergedJsFile')
170  ->will($this->returnValue($concatenatedFileName));
171  $this->subject->setRelativePath('');
172 
173  $result = $this->subject->concatenateJsFiles($testFileFixture);
174 
175  $this->assertArrayHasKey($concatenatedFileName, $result);
176  $this->assertArrayHasKey('excludeFromConcatenation', $result[$concatenatedFileName]);
177  $this->assertTrue($result[$concatenatedFileName]['excludeFromConcatenation']);
178  }
179 
180 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.