3bdf3e26cc7b5b6c9df0785a31b618c5a6297adc
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tests / tslib / class.tslib_contentTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Oliver Hader <oliver@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the "tslib_cObj" class in the TYPO3 Core.
27 *
28 * @package TYPO3
29 * @subpackage tslib
30 *
31 * @author Oliver Hader <oliver@typo3.org>
32 * @author Oliver Klee <typo3-coding@oliverklee.de>
33 */
34 class tslib_contentTest extends tx_phpunit_testcase {
35 /**
36 * @var array
37 */
38 private $backupGlobalVariables;
39
40 /**
41 * @var tslib_cObj
42 */
43 private $cObj;
44
45 /**
46 * @var tslib_fe
47 */
48 private $tsfe;
49
50 /**
51 * @var t3lib_TStemplate
52 */
53 private $template;
54
55 /**
56 * @var array
57 */
58 private $typoScriptImage;
59
60 public function setUp() {
61 $this->backupGlobalVariables = array(
62 '_GET' => $_GET,
63 '_POST' => $_POST,
64 '_SERVER' => $_SERVER,
65 'TYPO3_CONF_VARS' => $GLOBALS['TYPO3_CONF_VARS'],
66 );
67
68 $this->template = $this->getMock(
69 't3lib_TStemplate', array('getFileName', 'linkData')
70 );
71 $this->tsfe = $this->getMock('tslib_fe', array(), array(), '', FALSE);
72 $this->tsfe->tmpl = $this->template;
73 $this->tsfe->config = array();
74 $GLOBALS['TSFE'] = $this->tsfe;
75 $GLOBALS['TSFE']->csConvObj = new t3lib_cs();
76 $GLOBALS['TSFE']->renderCharset = 'utf-8';
77 $GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] = 'mbstring';
78
79 $className = 'tslib_cObj_' . uniqid('test');
80 eval('
81 class ' . $className . ' extends tslib_cObj {
82 public $stdWrapHookObjects = array();
83 public $getImgResourceHookObjects;
84 }
85 ');
86
87 $this->cObj = new $className();
88 $this->cObj->start(array(), 'tt_content');
89
90 $this->typoScriptImage = array(
91 'file' => 'typo3/clear.gif',
92 );
93 }
94
95 public function tearDown() {
96 foreach ($this->backupGlobalVariables as $key => $data) {
97 $GLOBALS[$key] = $data;
98 }
99
100 $GLOBALS['TSFE'] = NULL;
101
102 unset($this->cObj, $this->tsfe, $this->template, $this->typoScriptImage);
103 }
104
105
106 ////////////////////////
107 // Utitility functions
108 ////////////////////////
109
110 /**
111 * Converts the subject and the expected result into the target charset.
112 *
113 * @param string $charset the target charset
114 * @param string $subject the subject, will be modified
115 * @param string $expected the expected result, will be modified
116 */
117 protected function handleCharset($charset, &$subject, &$expected) {
118 $GLOBALS['TSFE']->renderCharset = $charset;
119 $subject = $GLOBALS['TSFE']->csConvObj->conv($subject, 'iso-8859-1', $charset);
120 $expected = $GLOBALS['TSFE']->csConvObj->conv($expected, 'iso-8859-1', $charset);
121 }
122
123
124 /////////////////////////////////////////////
125 // Tests concerning the getImgResource hook
126 /////////////////////////////////////////////
127
128 /**
129 * @test
130 */
131 public function getImgResourceHookGetsCalled() {
132 $this->template->expects($this->atLeastOnce())->method('getFileName')
133 ->with('typo3/clear.gif')->will($this->returnValue('typo3/clear.gif'));
134
135 $className = uniqid('tx_coretest');
136 $getImgResourceHookMock = $this->getMock(
137 'tslib_cObj_getImgResourceHook',
138 array('getImgResourcePostProcess'),
139 array(),
140 $className
141 );
142
143 $getImgResourceHookMock->expects($this->once())->method('getImgResourcePostProcess')
144 ->will($this->returnCallback(array($this, 'isGetImgResourceHookCalledCallback')));
145 $this->cObj->getImgResourceHookObjects = array($getImgResourceHookMock);
146
147 $this->cObj->IMAGE($this->typoScriptImage);
148 }
149
150 /**
151 * Handles the arguments that have been sent to the getImgResource hook.
152 *
153 * @return array
154 *
155 * @see getImgResourceHookGetsCalled
156 */
157 public function isGetImgResourceHookCalledCallback() {
158 list($file, $fileArray, $imageResource, $parent) = func_get_args();
159
160 $this->assertEquals('typo3/clear.gif', $file);
161 $this->assertEquals('typo3/clear.gif', $imageResource['origFile']);
162 $this->assertTrue(is_array($fileArray));
163 $this->assertTrue($parent instanceof tslib_cObj);
164
165 return $imageResource;
166 }
167
168
169 //////////////////////////
170 // Tests concerning FORM
171 //////////////////////////
172
173 /**
174 * @test
175 */
176 public function formWithSecureFormMailEnabledDoesNotContainRecipientField() {
177 $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = TRUE;
178
179 $this->assertNotContains(
180 'name="recipient',
181 $this->cObj->FORM(
182 array('recipient' => 'foo@bar.com', 'recipient.' => array()),
183 array()
184 )
185 );
186 }
187
188 /**
189 * @test
190 */
191 public function formWithSecureFormMailDisabledDoesNotContainRecipientField() {
192 $GLOBALS['TYPO3_CONF_VARS']['FE']['secureFormmail'] = FALSE;
193
194 $this->assertContains(
195 'name="recipient',
196 $this->cObj->FORM(
197 array('recipient' => 'foo@bar.com', 'recipient.' => array()),
198 array()
199 )
200 );
201 }
202
203
204 /////////////////////////////////////////
205 // Tests concerning getQueryArguments()
206 /////////////////////////////////////////
207
208 /**
209 * @test
210 */
211 public function getQueryArgumentsExcludesParameters() {
212 $_SERVER['QUERY_STRING'] =
213 'key1=value1' .
214 '&key2=value2' .
215 '&key3[key31]=value31' .
216 '&key3[key32][key321]=value321' .
217 '&key3[key32][key322]=value322';
218
219 $getQueryArgumentsConfiguration = array();
220 $getQueryArgumentsConfiguration['exclude'] = array();
221 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
222 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
223 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
224 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
225
226 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
227 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
228 $this->assertEquals($expectedResult, $actualResult);
229 }
230
231 /**
232 * @test
233 */
234 public function getQueryArgumentsExcludesGetParameters() {
235 $_GET = array(
236 'key1' => 'value1',
237 'key2' => 'value2',
238 'key3' => array(
239 'key31' => 'value31',
240 'key32' => array(
241 'key321' => 'value321',
242 'key322' => 'value322',
243 ),
244 ),
245 );
246
247 $getQueryArgumentsConfiguration = array();
248 $getQueryArgumentsConfiguration['method'] = 'GET';
249 $getQueryArgumentsConfiguration['exclude'] = array();
250 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
251 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
252 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
253 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
254
255 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2&key3[key32][key322]=value322');
256 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration);
257 $this->assertEquals($expectedResult, $actualResult);
258 }
259
260 /**
261 * @test
262 */
263 public function getQueryArgumentsOverrulesSingleParameter() {
264 $_SERVER['QUERY_STRING'] = 'key1=value1';
265
266 $getQueryArgumentsConfiguration = array();
267
268 $overruleArguments = array(
269 // Should be overriden
270 'key1' => 'value1Overruled',
271 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
272 'key2' => 'value2Overruled',
273 );
274
275 $expectedResult = '&key1=value1Overruled';
276 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
277 $this->assertEquals($expectedResult, $actualResult);
278 }
279
280 /**
281 * @test
282 */
283 public function getQueryArgumentsOverrulesMultiDimensionalParameters() {
284 $_POST = array(
285 'key1' => 'value1',
286 'key2' => 'value2',
287 'key3' => array(
288 'key31' => 'value31',
289 'key32' => array(
290 'key321' => 'value321',
291 'key322' => 'value322',
292 ),
293 ),
294 );
295
296 $getQueryArgumentsConfiguration = array();
297 $getQueryArgumentsConfiguration['method'] = 'POST';
298 $getQueryArgumentsConfiguration['exclude'] = array();
299 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
300 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
301 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
302 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
303
304 $overruleArguments = array(
305 // Should be overriden
306 'key2' => 'value2Overruled',
307 'key3' => array(
308 'key32' => array(
309 // Shouldn't be set: Parameter is excluded and not forced
310 'key321' => 'value321Overruled',
311 // Should be overriden: Parameter is not excluded
312 'key322' => 'value322Overruled',
313 // Shouldn't be set: Parameter doesn't exist in source array and is not forced
314 'key323' => 'value323Overruled',
315 ),
316 ),
317 );
318
319 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key322]=value322Overruled');
320 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments);
321 $this->assertEquals($expectedResult, $actualResult);
322 }
323
324 /**
325 * @test
326 */
327 public function getQueryArgumentsOverrulesMultiDimensionalForcedParameters() {
328 $_SERVER['QUERY_STRING'] =
329 'key1=value1' .
330 '&key2=value2' .
331 '&key3[key31]=value31' .
332 '&key3[key32][key321]=value321' .
333 '&key3[key32][key322]=value322';
334
335 $_POST = array(
336 'key1' => 'value1',
337 'key2' => 'value2',
338 'key3' => array(
339 'key31' => 'value31',
340 'key32' => array(
341 'key321' => 'value321',
342 'key322' => 'value322',
343 ),
344 ),
345 );
346
347 $getQueryArgumentsConfiguration = array();
348 $getQueryArgumentsConfiguration['exclude'] = array();
349 $getQueryArgumentsConfiguration['exclude'][] = 'key1';
350 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key31]';
351 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key321]';
352 $getQueryArgumentsConfiguration['exclude'][] = 'key3[key32][key322]';
353 $getQueryArgumentsConfiguration['exclude'] = implode(',', $getQueryArgumentsConfiguration['exclude']);
354
355 $overruleArguments = array(
356 // Should be overriden
357 'key2' => 'value2Overruled',
358 'key3' => array(
359 'key32' => array(
360 // Should be set: Parameter is excluded but forced
361 'key321' => 'value321Overruled',
362 // Should be set: Parameter doesn't exist in source array but is forced
363 'key323' => 'value323Overruled',
364 ),
365 ),
366 );
367
368 $expectedResult = $this->rawUrlEncodeSquareBracketsInUrl('&key2=value2Overruled&key3[key32][key321]=value321Overruled&key3[key32][key323]=value323Overruled');
369 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
370 $this->assertEquals($expectedResult, $actualResult);
371
372 $getQueryArgumentsConfiguration['method'] = 'POST';
373 $actualResult = $this->cObj->getQueryArguments($getQueryArgumentsConfiguration, $overruleArguments, TRUE);
374 $this->assertEquals($expectedResult, $actualResult);
375 }
376
377 /**
378 * Encodes square brackets in URL.
379 *
380 * @param string $string
381 * @return string
382 */
383 private function rawUrlEncodeSquareBracketsInUrl($string) {
384 return str_replace(
385 array('[', ']'),
386 array('%5B', '%5D'),
387 $string
388 );
389 }
390
391
392 //////////////////////////////
393 // Tests concerning crop
394 //////////////////////////////
395
396 /**
397 * @test
398 */
399 public function cropIsMultibyteSafe() {
400 $this->assertEquals('бла', $this->cObj->crop('бла', '3|...'));
401 }
402
403 //////////////////////////////
404 // Tests concerning cropHTML
405 //////////////////////////////
406
407 /**
408 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
409 * of charset, text type, and configuration options to be tested.
410 *
411 * @return array two-dimensional array with the second level like this:
412 * 0 => the settings for the crop function, for example "-58|..."
413 * 1 => the string to crop
414 * 2 => the expected cropped result
415 * 3 => the charset that will be set as renderCharset
416 *
417 * @see cropHtmlWithDataProvider
418 */
419 public function cropHtmlDataProvider() {
420 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) .
421 'j implemented the original version of the crop function.';
422 $textWithMarkup = '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' .
423 chr(229) . 'rh' . chr(248) . 'j</a>' .
424 ' implemented</strong> the original version of the crop function.';
425 $textWithEntities = 'Kasper Sk&aring;rh&oslash;j implemented the; original ' .
426 'version of the crop function.';
427
428 $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5');
429
430 $data = array();
431 foreach ($charsets as $charset) {
432 $data = array_merge($data, array(
433 $charset . ' plain text; 11|...' => array(
434 '11|...', $plainText, 'Kasper Sk' . chr(229) . 'r...', $charset
435 ),
436 $charset . ' plain text; -58|...' => array(
437 '-58|...', $plainText, '...h' . chr(248) . 'j implemented the original version of the crop function.', $charset
438 ),
439 $charset . ' plain text; 4|...|1' => array(
440 '4|...|1', $plainText, 'Kasp...', $charset
441 ),
442 $charset . ' plain text; 20|...|1' => array(
443 '20|...|1', $plainText, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset
444 ),
445 $charset . ' plain text; -5|...|1' => array(
446 '-5|...|1', $plainText, '...tion.', $charset
447 ),
448 $charset . ' plain text; -49|...|1' => array(
449 '-49|...|1', $plainText, '...the original version of the crop function.', $charset
450 ),
451 $charset . ' text with markup; 11|...' => array(
452 '11|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>', $charset
453 ),
454 $charset . ' text with markup; 13|...' => array(
455 '13|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>', $charset
456 ),
457 $charset . ' text with markup; 14|...' => array(
458 '14|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>', $charset
459 ),
460 $charset . ' text with markup; 15|...' => array(
461 '15|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>', $charset
462 ),
463 $charset . ' text with markup; 29|...' => array(
464 '29|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...', $charset
465 ),
466 $charset . ' text with markup; -58|...' => array(
467 '-58|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.', $charset
468 ),
469 $charset . ' text with markup 4|...|1' => array(
470 '4|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>', $charset
471 ),
472 $charset . ' text with markup; 11|...|1' => array(
473 '11|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>', $charset
474 ),
475 $charset . ' text with markup; 13|...|1' => array(
476 '13|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>', $charset
477 ),
478 $charset . ' text with markup; 14|...|1' => array(
479 '14|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>', $charset
480 ),
481 $charset . ' text with markup; 15|...|1' => array(
482 '15|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>', $charset
483 ),
484 $charset . ' text with markup; 29|...|1' => array(
485 '29|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...', $charset
486 ),
487 $charset . ' text with markup; -66|...|1' => array(
488 '-66|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">...Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.', $charset
489 ),
490 $charset . ' text with entities 9|...' => array(
491 '9|...', $textWithEntities, 'Kasper Sk...', $charset
492 ),
493 $charset . ' text with entities 10|...' => array(
494 '10|...', $textWithEntities, 'Kasper Sk&aring;...', $charset
495 ),
496 $charset . ' text with entities 11|...' => array(
497 '11|...', $textWithEntities, 'Kasper Sk&aring;r...', $charset
498 ),
499 $charset . ' text with entities 13|...' => array(
500 '13|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;...', $charset
501 ),
502 $charset . ' text with entities 14|...' => array(
503 '14|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
504 ),
505 $charset . ' text with entities 15|...' => array(
506 '15|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j ...', $charset
507 ),
508 $charset . ' text with entities 16|...' => array(
509 '16|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j i...', $charset
510 ),
511 $charset . ' text with entities -57|...' => array(
512 '-57|...', $textWithEntities, '...j implemented the; original version of the crop function.', $charset
513 ),
514 $charset . ' text with entities -58|...' => array(
515 '-58|...', $textWithEntities, '...&oslash;j implemented the; original version of the crop function.', $charset
516 ),
517 $charset . ' text with entities -59|...' => array(
518 '-59|...', $textWithEntities, '...h&oslash;j implemented the; original version of the crop function.', $charset
519 ),
520 $charset . ' text with entities 4|...|1' => array(
521 '4|...|1', $textWithEntities, 'Kasp...', $charset
522 ),
523 $charset . ' text with entities 9|...|1' => array(
524 '9|...|1', $textWithEntities, 'Kasper...', $charset
525 ),
526 $charset . ' text with entities 10|...|1' => array(
527 '10|...|1', $textWithEntities, 'Kasper...', $charset
528 ),
529 $charset . ' text with entities 11|...|1' => array(
530 '11|...|1', $textWithEntities, 'Kasper...', $charset
531 ),
532 $charset . ' text with entities 13|...|1' => array(
533 '13|...|1', $textWithEntities, 'Kasper...', $charset
534 ),
535 $charset . ' text with entities 14|...|1' => array(
536 '14|...|1', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
537 ),
538 $charset . ' text with entities 15|...|1' => array(
539 '15|...|1', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
540 ),
541 $charset . ' text with entities 16|...|1' => array(
542 '16|...|1', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
543 ),
544 $charset . ' text with entities -57|...|1' => array(
545 '-57|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset
546 ),
547 $charset . ' text with entities -58|...|1' => array(
548 '-58|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset
549 ),
550 $charset . ' text with entities -59|...|1' => array(
551 '-59|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset
552 ),
553 ));
554 }
555 return $data;
556 }
557
558 /**
559 * Checks if stdWrap.cropHTML works with plain text cropping from left
560 *
561 * @test
562 *
563 * @dataProvider cropHtmlDataProvider
564 *
565 * @param string $settings
566 * the settings for the crop function, for example "-58|..."
567 * @param string $subject the string to crop
568 * @param string $expected the expected cropped result
569 * @param string $charset the charset that will be set as renderCharset
570 */
571 public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) {
572 $this->handleCharset($charset, $subject, $expected);
573
574 $this->assertEquals(
575 $expected,
576 $this->cObj->cropHTML($subject, $settings),
577 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"'
578 );
579 }
580
581 /**
582 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
583 * counts multiple invisible characters not as one (as the browser will output the content).
584 *
585 * @test
586 */
587 public function cropHtmlWorksWithComplexContent() {
588 $GLOBALS['TSFE']->renderCharset = 'iso-8859-1';
589 $subject = '
590 <h1>Blog Example</h1>
591 <hr>
592 <div class="csc-header csc-header-n1">
593 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
594 </div>
595 <p class="bodytext">
596 A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.
597 </p>
598 <div class="tx-blogexample-list-container">
599 <p class="bodytext">
600 Below are the most recent posts:
601 </p>
602 <ul>
603 <li>
604 <h3>
605 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog]=&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=003b0131ed">The Post #1</a>
606 </h3>
607 <p class="bodytext">
608 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
609 </p>
610 <p class="metadata">
611 Published on 26.08.2009 by Jochen Rau
612 </p>
613 <p>
614 Tags: [MVC]&nbsp;[Domain Driven Design]&nbsp;<br>
615 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=f982643bc3">read more &gt;&gt;</a><br>
616 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=edit&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=5b481bc8f0">Edit</a>&nbsp;<a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=delete&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=4e52879656">Delete</a>
617 </p>
618 </li>
619 </ul>
620 <p>
621 <a href="index.php?id=99&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=new&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=2718a4b1a0">Create a new Post</a>
622 </p>
623 </div>
624 <hr>
625 <p>
626 ? TYPO3 Association
627 </p>
628 ';
629
630 $result = $this->cObj->cropHTML($subject, '300');
631 $expected = '
632 <h1>Blog Example</h1>
633 <hr>
634 <div class="csc-header csc-header-n1">
635 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
636 </div>
637 <p class="bodytext">
638 A blog about TYPO3 extension development. In order to start blogging, read the <a href="#">Help section</a>. If you have any further questions, feel free to contact the administrator John Doe (<a href="mailto:john.doe@example.com">john.doe@example.com)</a>.
639 </p>
640 <div class="tx-blogexample-list-container">
641 <p class="bodytext">
642 Below are the most recent posts:
643 </p>
644 <ul>
645 <li>
646 <h3>
647 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog]=&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=003b0131ed">The Pos</a></h3></li></ul></div>';
648 $this->assertEquals($expected, $result);
649
650 $result = $this->cObj->cropHTML($subject, '-100');
651 $expected = '<div class="tx-blogexample-list-container"><ul><li><p>Design]&nbsp;<br>
652 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[action]=show&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=f982643bc3">read more &gt;&gt;</a><br>
653 <a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=edit&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=5b481bc8f0">Edit</a>&nbsp;<a href="index.php?id=99&amp;tx_blogexample_pi1[post][uid]=211&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=delete&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=4e52879656">Delete</a>
654 </p>
655 </li>
656 </ul>
657 <p>
658 <a href="index.php?id=99&amp;tx_blogexample_pi1[blog][uid]=70&amp;tx_blogexample_pi1[action]=new&amp;tx_blogexample_pi1[controller]=Post&amp;cHash=2718a4b1a0">Create a new Post</a>
659 </p>
660 </div>
661 <hr>
662 <p>
663 ? TYPO3 Association
664 </p>
665 ';
666 $this->assertEquals(
667 $expected,
668 $result
669 );
670 }
671
672 /**
673 * @return array
674 */
675 public function stdWrap_roundDataProvider() {
676 return array(
677 'rounding off without any configuration' => array(
678 1.123456789,
679 array(
680 ),
681 1
682 ),
683 'rounding up without any configuration' => array(
684 1.523456789,
685 array(
686 ),
687 2
688 ),
689 'regular rounding (off) to two decimals' => array(
690 0.123456789,
691 array(
692 'decimals' => 2
693 ),
694 0.12
695 ),
696 'regular rounding (up) to two decimals' => array(
697 0.1256789,
698 array(
699 'decimals' => 2
700 ),
701 0.13
702 ),
703 'rounding up to integer with type ceil' => array(
704 0.123456789,
705 array(
706 'roundType' => 'ceil'
707 ),
708 1
709 ),
710 'rounding down to integer with type floor' => array(
711 2.3481,
712 array(
713 'roundType' => 'floor'
714 ),
715 2
716 )
717 );
718 }
719
720 /**
721 * Test for the stdWrap function "round"
722 *
723 * @param float $float
724 * @param array $conf
725 * @param float $expected
726 * @return void
727 *
728 * @dataProvider stdWrap_roundDataProvider
729 * @test
730 */
731 public function stdWrap_round($float, $conf, $expected) {
732 $conf = array(
733 'round.' => $conf
734 );
735 $result = $this->cObj->stdWrap_round($float, $conf);
736 $this->assertEquals($expected, $result);
737 }
738
739 /**
740 * Data provider for the hash test
741 *
742 * @return array multi-dimensional array with the second level like this:
743 * 0 => the plain text
744 * 1 => the conf array for the hash stdWrap function
745 * 2 => the expected result
746 *
747 * @see hash
748 */
749 public function hashDataProvider() {
750 $data = array(
751 'testing md5' => array(
752 'joh316',
753 array(
754 'hash' => 'md5'
755 ),
756 'bacb98acf97e0b6112b1d1b650b84971'
757 ),
758 'testing sha1' => array(
759 'joh316',
760 array(
761 'hash' => 'sha1'
762 ),
763 '063b3d108bed9f88fa618c6046de0dccadcf3158'
764 ),
765 'testing non-existing hashing algorithm' => array(
766 'joh316',
767 array(
768 'hash' => 'non-existing'
769 ),
770 ''
771 ),
772 'testing stdWrap capability' => array(
773 'joh316',
774 array(
775 'hash.' => array(
776 'cObject' => 'TEXT',
777 'cObject.' => array(
778 'value' => 'md5'
779 )
780 )
781 ),
782 'bacb98acf97e0b6112b1d1b650b84971'
783 )
784 );
785 return $data;
786 }
787
788 /**
789 * Test for the stdWrap function "hash"
790 *
791 * @param string $text
792 * @param array $conf
793 * @param string $expected
794 * @return void
795 *
796 * @dataProvider hashDataProvider
797 * @test
798 */
799 public function stdWrap_hash($text, array $conf, $expected) {
800 $result = $this->cObj->stdWrap_hash($text, $conf);
801 $this->assertEquals($expected, $result);
802 }
803
804 /**
805 * Data provider for the numberFormat test
806 *
807 * @return array multi-dimensional array with the second level like this:
808 * 0 => the input float number
809 * 1 => the conf array for the numberFormat stdWrap function
810 * 2 => the expected result
811 *
812 * @see numberFormat
813 */
814 public function numberFormatDataProvider() {
815 $data = array(
816 'testing decimals' => array(
817 0.8,
818 array(
819 'decimals' => 2
820 ),
821 '0.80'
822 ),
823 'testing dec_point' => array(
824 0.8,
825 array(
826 'decimals' => 1,
827 'dec_point' => ','
828 ),
829 '0,8'
830 ),
831 'testing thousands_sep' => array(
832 999.99,
833 array(
834 'decimals' => 0,
835 'thousands_sep.' => array(
836 'char' => 46
837 )
838 ),
839 '1.000'
840 ),
841 'testing mixture' => array(
842 1281731.45,
843 array(
844 'decimals' => 1,
845 'dec_point.' => array(
846 'char' => 44
847 ),
848 'thousands_sep.' => array(
849 'char' => 46
850 )
851 ),
852 '1.281.731,5'
853 )
854 );
855 return $data;
856 }
857
858 /**
859 * Check if stdWrap.numberFormat and all of its properties work properly
860 *
861 * @dataProvider numberFormatDataProvider
862 *
863 * @test
864 */
865 public function numberFormat($float, $formatConf, $expected) {
866 $result = $this->cObj->numberFormat($float, $formatConf);
867 $this->assertEquals($expected, $result);
868 }
869
870 /**
871 * Data provider for the replacement test
872 *
873 * @return array multi-dimensional array with the second level like this:
874 * 0 => the input text
875 * 1 => the conf array for the replacement stdWrap function
876 * 2 => the expected result
877 *
878 * @see replacement
879 */
880 public function replacementDataProvider() {
881 $data = array(
882 'multiple replacements, including regex' => array(
883 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
884 array('replacement.' =>
885 array(
886 '120.' => array(
887 'search' => 'in da hood',
888 'replace' => 'around the block',
889 ),
890 '20.' => array(
891 'search' => '_',
892 'replace.' => array('char' => '32'),
893 ),
894 '130.' => array(
895 'search' => '#a (Cat|Dog|Tiger)#i',
896 'replace' => 'an animal',
897 'useRegExp' => '1',
898 ),
899 ),
900 ),
901 'There is an animal, an animal and an animal around the block! Yeah!'
902 ),
903 );
904 return $data;
905 }
906
907 /**
908 * Check if stdWrap.replacement and all of its properties work properly
909 *
910 * @dataProvider replacementDataProvider
911 *
912 * @test
913 */
914 public function replacement($input, $conf, $expected) {
915 $result = $this->cObj->stdWrap_replacement($input, $conf);
916 $this->assertEquals($expected, $result);
917 }
918 }
919 ?>