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