[FEATURE] Enable allWrap.splitChar on all includeJS/includeCSS properties
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Page / PageRendererTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Page;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2013 Steffen Kamper (info@sk-typo3.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for \TYPO3\CMS\Core\Page\PageRenderer
28 *
29 * @author Steffen Kamper (info@sk-typo3.de)
30 */
31 class PageRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
32
33 /**
34 * @var \TYPO3\CMS\Core\Page\PageRenderer
35 */
36 private $fixture;
37
38 public function setUp() {
39 $this->fixture = new \TYPO3\CMS\Core\Page\PageRenderer();
40 $this->fixture->setCharSet($GLOBALS['LANG']->charSet);
41 }
42
43 public function tearDown() {
44 unset($this->fixture);
45 }
46
47 //////////////////////////////////////
48 // Tests for the basic functionality
49 //////////////////////////////////////
50 /**
51 * @test
52 */
53 public function fixtureCanBeCreated() {
54 $this->assertTrue($this->fixture instanceof \TYPO3\CMS\Core\Page\PageRenderer);
55 }
56
57 //////////////////////
58 // test functions
59 //////////////////////
60 /**
61 * test set xml prolog and doctype
62 */
63 public function testSetXmlPrologAndDocType() {
64 $expectedReturnValue = '<?xml version="1.0" encoding="utf-8" ?>';
65 $this->fixture->setXmlPrologAndDocType('<?xml version="1.0" encoding="utf-8" ?>');
66 $out = $this->fixture->render();
67 $this->assertContains($expectedReturnValue, $out);
68 }
69
70 /**
71 * test set title
72 */
73 public function testSetTitle() {
74 $expectedReturnValue = '<title>This is the title</title>';
75 $this->fixture->setTitle('This is the title');
76 $out = $this->fixture->render();
77 $this->assertContains($expectedReturnValue, $out);
78 }
79
80 /**
81 * test set charset
82 */
83 public function testSetCharset() {
84 $expectedReturnValue = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
85 $this->fixture->setCharset('utf-8');
86 $out = $this->fixture->render();
87 $this->assertContains($expectedReturnValue, $out);
88 }
89
90 /**
91 * test set favicon
92 */
93 public function testSetFavIcon() {
94 $expectedReturnValue1 = '<link rel="shortcut icon" href="http://google.com/favicon.ico" />';
95 $expectedReturnValue2 = '<link rel="icon" href="http://google.com/favicon.ico" />';
96 $this->fixture->setFavIcon('http://google.com/favicon.ico');
97 $out = $this->fixture->render();
98 $this->assertContains($expectedReturnValue1, $out);
99 $this->assertContains($expectedReturnValue2, $out);
100 }
101
102 /**
103 * test set baseUrl
104 */
105 public function testSetBaseUrl() {
106 $expectedReturnValue = '<base href="http://ggogle.com/" />';
107 $this->fixture->setBaseUrl('http://ggogle.com/');
108 $out = $this->fixture->render();
109 $this->assertContains($expectedReturnValue, $out);
110 }
111
112 /**
113 * test add meta tag
114 */
115 public function testAddMetaTag() {
116 $expectedReturnValue = '<meta name="author" content="Anna Lyse">';
117 $this->fixture->addMetaTag('<meta name="author" content="Anna Lyse">');
118 $out = $this->fixture->render();
119 $this->assertContains($expectedReturnValue, $out);
120 }
121
122 /**
123 * test add inline comment
124 */
125 public function testAddInlineComment() {
126 $expectedReturnValue = 'this is an inline comment written by unit test';
127 $this->fixture->addInlineComment('this is an inline comment written by unit test');
128 $out = $this->fixture->render();
129 $this->assertContains($expectedReturnValue, $out);
130 }
131
132 /**
133 * test add header data
134 */
135 public function testAddHeaderData() {
136 $expectedReturnValue = '<tag method="private" name="test" />';
137 $this->fixture->addHeaderData('<tag method="private" name="test" />');
138 $out = $this->fixture->render();
139 $this->assertContains($expectedReturnValue, $out);
140 }
141
142 /**
143 * test add footer data
144 */
145 public function testAddFooterData() {
146 $expectedReturnValue = '<tag method="private" name="test" />';
147 $this->fixture->addFooterData('<tag method="private" name="test" />');
148 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
149 $this->assertContains($expectedReturnValue, $out);
150 }
151
152 /**
153 * test add JS library file
154 */
155 public function testAddJsLibrary() {
156 $expectedRegExp = '#wrapBefore<script src="fileadmin/test\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>wrapAfter#';
157 $this->fixture->addJsLibrary('test', 'fileadmin/test.js', 'text/javascript', FALSE, FALSE, 'wrapBeforeXwrapAfter', FALSE, 'X');
158 $out = $this->fixture->render();
159 $this->assertRegExp($expectedRegExp, $out);
160 }
161
162 /**
163 * test add JS footer library file
164 */
165 public function testAddJsFooterLibrary() {
166 $expectedRegExp = '#wrapBefore<script src="fileadmin/test\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>wrapAfter#';
167 $this->fixture->addJsFooterLibrary('test', 'fileadmin/test.js', 'text/javascript', FALSE, FALSE, 'wrapBeforeXwrapAfter', FALSE, 'X');
168 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
169 $this->assertRegExp($expectedRegExp, $out);
170 }
171
172 /**
173 * test add JS file
174 */
175 public function testAddJsFile() {
176 $expectedRegExp = '#wrapBefore<script src="fileadmin/test\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>wrapAfter#';
177 $this->fixture->addJsFile('fileadmin/test.js', 'text/javascript', FALSE, FALSE, 'wrapBeforeXwrapAfter', FALSE, 'X');
178 $out = $this->fixture->render();
179 $this->assertRegExp($expectedRegExp, $out);
180 }
181
182 /**
183 * test add JS file for footer
184 */
185 public function testAddJsFooterFile() {
186 $expectedRegExp = '#wrapBefore<script src="fileadmin/test\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>wrapAfter#';
187 $this->fixture->addJsFooterFile('fileadmin/test.js', 'text/javascript', FALSE, FALSE, 'wrapBeforeXwrapAfter', FALSE, 'X');
188 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
189 $this->assertRegExp($expectedRegExp, $out);
190 }
191
192 /**
193 * test add JS inline
194 */
195 public function testAddJsInlineCode() {
196 $expectedReturnValue = 'var x = "testvar"';
197 $this->fixture->addJsInlineCode('test', 'var x = "testvar"');
198 $out = $this->fixture->render();
199 $this->assertContains($expectedReturnValue, $out);
200 }
201
202 /**
203 * test add JS inline for footer
204 */
205 public function testAddJsFooterInlineCode() {
206 $expectedReturnValue = 'var x = "testvar"';
207 $this->fixture->addJsFooterInlineCode('test', 'var x = "testvar"');
208 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
209 $this->assertContains($expectedReturnValue, $out);
210 }
211
212 /**
213 * test add JS handler
214 */
215 public function testAddExtOnReadyCode() {
216 $expectedReturnValue1 = 'Ext.onReady(function() {';
217 $expectedReturnValue2 = 'var x = "testvar";';
218 $this->fixture->loadExtJS();
219 $this->fixture->addExtOnReadyCode('var x = "testvar";');
220 $out = $this->fixture->render();
221 $this->assertContains($expectedReturnValue1, $out);
222 $this->assertContains($expectedReturnValue2, $out);
223 }
224
225 /**
226 * test add CSS file
227 */
228 public function testAddCssFile() {
229 $expectedReturnValue = 'wrapBefore<link rel="stylesheet" type="text/css" href="fileadmin/test.css" media="print" />wrapAfter';
230 $this->fixture->addCssFile('fileadmin/test.css', 'stylesheet', 'print', '', TRUE, FALSE, 'wrapBeforeXwrapAfter', FALSE, 'X');
231 $out = $this->fixture->render();
232 $this->assertContains($expectedReturnValue, $out);
233 }
234
235 /**
236 * test add CSS inline
237 */
238 public function testAddCssInlineBlock() {
239 $expectedReturnValue = 'body {margin:20px;}';
240 $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
241 $out = $this->fixture->render();
242 $this->assertContains($expectedReturnValue, $out);
243 }
244
245 /**
246 * test add CSS inline and force on top
247 */
248 public function testAddCssInlineBlockForceOnTop() {
249 $expectedReturnValue = '/*general1*/' . LF . 'h1 {margin:20px;}' . LF . '/*general*/' . LF . 'body {margin:20px;}';
250 $this->fixture->addCssInlineBlock('general', 'body {margin:20px;}');
251 $this->fixture->addCssInlineBlock('general1', 'h1 {margin:20px;}', NULL, TRUE);
252 $out = $this->fixture->render();
253 $this->assertContains($expectedReturnValue, $out);
254 }
255
256 /**
257 * test load prototype
258 */
259 public function testLoadPrototype() {
260 $expectedRegExp = '#<script src="contrib/prototype/prototype\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
261 $this->fixture->loadPrototype();
262 $out = $this->fixture->render();
263 $this->assertRegExp($expectedRegExp, $out);
264 }
265
266 /**
267 * test load Scriptaculous
268 */
269 public function testLoadScriptaculous() {
270 $this->fixture->loadScriptaculous('slider,controls');
271 $out = $this->fixture->render();
272 $this->assertContains('<script src="contrib/scriptaculous/scriptaculous.js" type="text/javascript"></script>', $out);
273 $this->assertContains('<script src="contrib/scriptaculous/effects.js" type="text/javascript"></script>', $out);
274 $this->assertContains('<script src="contrib/scriptaculous/controls.js" type="text/javascript"></script>', $out);
275 $this->assertContains('<script src="contrib/scriptaculous/slider.js" type="text/javascript"></script>', $out);
276 }
277
278 /**
279 * Tests whether scriptaculous is loaded correctly when compression is enabled.
280 *
281 * @test
282 */
283 public function isScriptaculousLoadedCompressedIfConfiguredAndClientIsCapable() {
284 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate';
285 $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '5';
286 $this->fixture->loadScriptaculous('slider,controls');
287 $this->fixture->enableCompressJavascript();
288 $out = $this->fixture->render();
289 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/scriptaculous-[a-f0-9]+.js.gzip" type="text/javascript"></script>#', $out);
290 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/effects-[a-f0-9]+.js.gzip" type="text/javascript"></script>#', $out);
291 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/controls-[a-f0-9]+.js.gzip" type="text/javascript"></script>#', $out);
292 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/slider-[a-f0-9]+.js.gzip" type="text/javascript"></script>#', $out);
293 }
294
295 /**
296 * Tests whether scriptaculous is correctly loaded, but without compression
297 * if the browser did not send the appropriate headers.
298 *
299 * @test
300 */
301 public function isScriptaculousNotLoadedCompressedIfClientCannotHandleCompression() {
302 $_SERVER['HTTP_ACCEPT_ENCODING'] = '';
303 $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '5';
304 $this->fixture->loadScriptaculous('slider,controls');
305 $this->fixture->enableCompressJavascript();
306 $out = $this->fixture->render();
307 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/scriptaculous-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
308 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/effects-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
309 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/controls-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
310 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/slider-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
311 }
312
313 /**
314 * Tests whether scriptaculous is correctly loaded, but without compression
315 * if no compression is configured.
316 *
317 * @test
318 */
319 public function isScriptaculousNotLoadedCompressedIfCompressionIsNotConfigured() {
320 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip,deflate';
321 $GLOBALS['TYPO3_CONF_VARS']['BE']['compressionLevel'] = '';
322 $this->fixture->loadScriptaculous('slider,controls');
323 $this->fixture->enableCompressJavascript();
324 $out = $this->fixture->render();
325 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/scriptaculous-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
326 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/effects-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
327 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/controls-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
328 $this->assertRegExp('#<script src="[^"]*/typo3temp/compressor/slider-[a-f0-9]+.js" type="text/javascript"></script>#', $out);
329 }
330
331 /**
332 * test load jQuery
333 *
334 * @test
335 */
336 public function loadJqueryLoadsTheLatestJqueryMinifiedVersionInNoConflictMode() {
337 $expectedRegExp = '#<script src="contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
338 $expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.jQuery = jQuery.noConflict(true);';
339 $this->fixture->loadJquery();
340 $out = $this->fixture->render();
341 $this->assertRegExp($expectedRegExp, $out);
342 $this->assertContains($expectedStatement, $out);
343 }
344
345 /**
346 * test load jQuery
347 *
348 * @test
349 */
350 public function loadJqueryRespectsGivenNamespace() {
351 $expectedRegExp = '#<script src="contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
352 $expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.MyNameSpace = jQuery.noConflict(true);';
353 $this->fixture->loadJquery(NULL, NULL, 'MyNameSpace');
354 $out = $this->fixture->render();
355 $this->assertRegExp($expectedRegExp, $out);
356 $this->assertContains($expectedStatement, $out);
357 }
358
359 /**
360 * test load jQuery
361 *
362 * @test
363 */
364 public function loadJqueryWithDefaultNoConflictModeDoesNotSetNamespace() {
365 $expectedRegExp = '#<script src="contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
366 $expectedStatement = 'jQuery.noConflict();';
367 $this->fixture->loadJquery(NULL, NULL, \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_DEFAULT_NOCONFLICT);
368 $out = $this->fixture->render();
369 $this->assertRegExp($expectedRegExp, $out);
370 $this->assertContains($expectedStatement, $out);
371 $this->assertNotContains('var TYPO3 = TYPO3 || {}; TYPO3.', $out);
372 }
373
374 /**
375 * test load jQuery
376 *
377 * @test
378 */
379 public function loadJqueryWithNamespaceNoneDoesNotIncludeNoConflictHandling() {
380 $expectedRegExp = '#<script src="contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.min\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
381 $this->fixture->loadJquery(NULL, NULL, \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_NAMESPACE_NONE);
382 $out = $this->fixture->render();
383 $this->assertRegExp($expectedRegExp, $out);
384 $this->assertNotContains('jQuery.noConflict', $out);
385 }
386
387 /**
388 * test load jQuery
389 *
390 * @test
391 */
392 public function loadJqueryLoadsTheLatestJqueryVersionInNoConflictModeUncompressedInDebugMode() {
393 $expectedRegExp = '#<script src="contrib/jquery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
394 $expectedStatement = 'var TYPO3 = TYPO3 || {}; TYPO3.jQuery = jQuery.noConflict(true);';
395 $this->fixture->loadJquery();
396 $this->fixture->enableDebugMode();
397 $out = $this->fixture->render();
398 $this->assertRegExp($expectedRegExp, $out);
399 $this->assertContains($expectedStatement, $out);
400 }
401
402 /**
403 * @expectedException \UnexpectedValueException
404 * @test
405 */
406 public function includingNotAvailableLocalJqueryVersionThrowsException() {
407 $this->fixture->loadJquery('1.3.34');
408 $this->fixture->render();
409 }
410
411 /**
412 * @expectedException \UnexpectedValueException
413 * @test
414 */
415 public function includingJqueryWithNonAlphnumericNamespaceThrowsException() {
416 $this->fixture->loadJquery(NULL, NULL, '12sd.12fsd');
417 $this->fixture->render();
418 }
419
420 /**
421 * @return array
422 */
423 public function loadJqueryFromSourceDataProvider() {
424 $specificVersion = '1.6.3';
425 return array(
426 'google with no version number' => array(NULL, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '/jquery.js" type="text/javascript"></script>#'),
427 'google with version number' => array($specificVersion, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . $specificVersion . '/jquery.js" type="text/javascript"></script>#'),
428 'msn with no version number' => array(NULL, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '.js" type="text/javascript"></script>#'),
429 'msn with version number' => array($specificVersion, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . $specificVersion . '.js" type="text/javascript"></script>#'),
430 'jquery with no version number' => array(NULL, 'jquery', '#<script src="http://code.jquery.com/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '.js" type="text/javascript"></script>#'),
431 'jquery with version number' => array($specificVersion, 'jquery', '#<script src="http://code.jquery.com/jquery-' . $specificVersion . '.js" type="text/javascript"></script>#'),
432 'jquery with custom URL' => array($specificVersion, 'http://my.cool.cdn/foo/jquery.js', '#<script src="http://my.cool.cdn/foo/jquery.js" type="text/javascript"></script>#')
433 );
434 }
435
436 /**
437 * Tests whether jQuery is correctly loaded, from the respective CDNs
438 *
439 * @dataProvider loadJqueryFromSourceDataProvider
440 * @test
441 */
442 public function isJqueryLoadedFromSourceUncompressedIfDebugModeIsEnabled($version, $source, $regex) {
443 $this->fixture->loadJquery($version, $source);
444 $this->fixture->enableDebugMode();
445 $out = $this->fixture->render();
446 $this->assertRegExp($regex, $out);
447 }
448
449 /**
450 * @return array
451 */
452 public function loadJqueryMinifiedFromSourceDataProvider() {
453 $specificVersion = '1.6.3';
454 return array(
455 'google with no version number' => array(NULL, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '/jquery.min.js" type="text/javascript"></script>#'),
456 'google with version number' => array($specificVersion, 'google', '#<script src="//ajax.googleapis.com/ajax/libs/jquery/' . $specificVersion . '/jquery.min.js" type="text/javascript"></script>#'),
457 'msn with no version number' => array(NULL, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '.min.js" type="text/javascript"></script>#'),
458 'msn with version number' => array($specificVersion, 'msn', '#<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-' . $specificVersion . '.min.js" type="text/javascript"></script>#'),
459 'jquery with no version number' => array(NULL, 'jquery', '#<script src="http://code.jquery.com/jquery-' . \TYPO3\CMS\Core\Page\PageRenderer::JQUERY_VERSION_LATEST . '.min.js" type="text/javascript"></script>#'),
460 'jquery with version number' => array($specificVersion, 'jquery', '#<script src="http://code.jquery.com/jquery-' . $specificVersion . '.min.js" type="text/javascript"></script>#')
461 );
462 }
463
464 /**
465 * Tests whether jQuery is correctly loaded, from the respective CDNs
466 *
467 * @dataProvider loadJqueryMinifiedFromSourceDataProvider
468 * @test
469 */
470 public function isJqueryLoadedMinifiedFromSourceByDefault($version, $cdn, $regex) {
471 $this->fixture->loadJquery($version, $cdn);
472 $out = $this->fixture->render();
473 $this->assertRegExp($regex, $out);
474 }
475
476 /**
477 * test load ExtJS
478 */
479 public function testLoadExtJS() {
480 $expectedRegExp = '#<script src="contrib/extjs/adapter/jquery/ext-jquery-adapter\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>' . LF . '<script src="contrib/extjs/ext-all\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#m';
481 $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
482 $out = $this->fixture->render();
483 $this->assertRegExp($expectedRegExp, $out);
484 }
485
486 /**
487 * test load ExtCore
488 */
489 public function testLoadExtCore() {
490 $expectedRegExp = '#<script src="contrib/extjs/ext-core\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
491 $this->fixture->loadExtCore();
492 $out = $this->fixture->render();
493 $this->assertRegExp($expectedRegExp, $out);
494 }
495
496 /**
497 * test enable ExtJsDebug
498 */
499 public function testEnableExtJsDebug() {
500 $expectedRegExp = '#<script src="contrib/extjs/ext-all-debug\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
501 $this->fixture->loadExtJS(TRUE, TRUE, 'jquery');
502 $this->fixture->enableExtJsDebug();
503 $out = $this->fixture->render();
504 $this->assertRegExp($expectedRegExp, $out);
505 }
506
507 /**
508 * test enable ExtCoreDebug
509 */
510 public function testEnableExtCoreDebug() {
511 $expectedRegExp = '#<script src="contrib/extjs/ext-core-debug\\.(js|\\d+\\.js|js\\?\\d+)" type="text/javascript"></script>#';
512 $this->fixture->loadExtCore();
513 $this->fixture->enableExtCoreDebug();
514 $out = $this->fixture->render();
515 $this->assertRegExp($expectedRegExp, $out);
516 }
517
518 /**
519 * test inline language label
520 */
521 public function testAddInlineLanguageLabel() {
522 $expectedReturnValue = 'TYPO3.lang = {"myKey":"myValue"}';
523 $this->fixture->loadExtJS();
524 $this->fixture->addInlineLanguageLabel('myKey', 'myValue');
525 $this->fixture->enableMoveJsFromHeaderToFooter();
526 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
527 $this->assertContains($expectedReturnValue, $out);
528 }
529
530 /**
531 * test inline language label as array
532 */
533 public function testAddInlineLanguageLabelArray() {
534 $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
535 $this->fixture->loadExtJS();
536 $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1', 'myKey2' => 'myValue2'));
537 $this->fixture->enableMoveJsFromHeaderToFooter();
538 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
539 $this->assertContains($expectedReturnValue, $out);
540 }
541
542 /**
543 * test inline language label as array get merged
544 */
545 public function testAddInlineLanguageLabelArrayMerged() {
546 $expectedReturnValue = 'TYPO3.lang = {"myKey1":"myValue1","myKey2":"myValue2"}';
547 $this->fixture->loadExtJS();
548 $this->fixture->addInlineLanguageLabelArray(array('myKey1' => 'myValue1'));
549 $this->fixture->addInlineLanguageLabelArray(array('myKey2' => 'myValue2'));
550 $this->fixture->enableMoveJsFromHeaderToFooter();
551 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
552 $this->assertContains($expectedReturnValue, $out);
553 }
554
555 /**
556 * test inline setting
557 */
558 public function testAddInlineSetting() {
559 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey":"myValue"}};';
560 $this->fixture->loadExtJS();
561 $this->fixture->addInlineSetting('myApp', 'myKey', 'myValue');
562 $this->fixture->enableMoveJsFromHeaderToFooter();
563 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
564 $this->assertContains($expectedReturnValue, $out);
565 }
566
567 /**
568 * test inline settings with array
569 */
570 public function testAddInlineSettingArray() {
571 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
572 $this->fixture->loadExtJS();
573 $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1', 'myKey2' => 'myValue2'));
574 $this->fixture->enableMoveJsFromHeaderToFooter();
575 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
576 $this->assertContains($expectedReturnValue, $out);
577 }
578
579 /**
580 * test inline settings with array get merged
581 */
582 public function testAddInlineSettingArrayMerged() {
583 $expectedReturnValue = 'TYPO3.settings = {"myApp":{"myKey1":"myValue1","myKey2":"myValue2"}};';
584 $this->fixture->loadExtJS();
585 $this->fixture->addInlineSettingArray('myApp', array('myKey1' => 'myValue1'));
586 $this->fixture->addInlineSettingArray('myApp', array('myKey2' => 'myValue2'));
587 $this->fixture->enableMoveJsFromHeaderToFooter();
588 $out = $this->fixture->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
589 $this->assertContains($expectedReturnValue, $out);
590 }
591
592 /**
593 * test add body content
594 */
595 public function testAddBodyContent() {
596 $expectedReturnValue = 'ABCDE';
597 $this->fixture->addBodyContent('A');
598 $this->fixture->addBodyContent('B');
599 $this->fixture->addBodyContent('C');
600 $this->fixture->addBodyContent('D');
601 $this->fixture->addBodyContent('E');
602 $out = $this->fixture->getBodyContent();
603 $this->assertEquals($expectedReturnValue, $out);
604 }
605
606 /**
607 * test set body content
608 */
609 public function testSetBodyContent() {
610 $expectedReturnValue = 'ABCDE';
611 $this->fixture->setBodyContent('ABCDE');
612 $out = $this->fixture->getBodyContent();
613 $this->assertEquals($expectedReturnValue, $out);
614 $out = $this->fixture->render();
615 $this->assertContains($expectedReturnValue, $out);
616 }
617
618 /**
619 * Tests the addInlineLanguageLabelFile() method.
620 *
621 * @test
622 * @expectedException \RuntimeException
623 */
624 public function areInlineLanguageLabelsNotProcessable() {
625 $this->fixture->setLanguage(NULL);
626 $this->fixture->addInlineLanguageLabelFile('EXT:lang/locallang_core.xlf');
627 $out = $this->fixture->render();
628 }
629
630 /**
631 * Tests the addInlineLanguageLabelFile() method.
632 *
633 * @test
634 */
635 public function areInlineLanguageLabelsPassed() {
636 $this->fixture->setLanguage($GLOBALS['LANG']->lang);
637 $this->fixture->addInlineLanguageLabelFile('EXT:lang/locallang_core.xlf');
638 $out = $this->fixture->render();
639 $this->assertContains('labels.beUser', $out);
640 $this->assertContains('labels.feUser', $out);
641 }
642
643 /**
644 * Tests the addInlineLanguageLabelFile() method.
645 *
646 * @test
647 */
648 public function areInlineLanguageLabelsEmptyOnNonExistingFile() {
649 $this->fixture->addInlineLanguageLabelFile('');
650 $inlineLanguageLabelFiles = $this->fixture->getInlineLanguageLabelFiles();
651 $this->assertEquals(array(), $inlineLanguageLabelFiles);
652 }
653
654 /**
655 * Tests the addInlineLanguageLabelFile() method.
656 *
657 * @test
658 */
659 public function areInlineLanguageLabelsSelected() {
660 $this->fixture->setLanguage($GLOBALS['LANG']->lang);
661 $this->fixture->addInlineLanguageLabelFile('EXT:lang/locallang_core.xlf', 'labels.');
662 $out = $this->fixture->render();
663 $this->assertContains('labels.beUser', $out);
664 $this->assertContains('labels.feUser', $out);
665 }
666
667 /**
668 * Tests the addInlineLanguageLabelFile() method.
669 *
670 * @test
671 */
672 public function areInlineLanguageLabelsSelectedAndStripped() {
673 $this->fixture->setLanguage($GLOBALS['LANG']->lang);
674 $this->fixture->addInlineLanguageLabelFile('EXT:lang/locallang_core.xlf', 'labels.', 'lock');
675 $out = $this->fixture->render();
676 $this->assertContains('edRecord', $out);
677 $this->assertContains('edRecord_content', $out);
678 $this->assertContains('edRecordUser', $out);
679 }
680
681 }
682
683 ?>