[BUGFIX] cropHTML with dash in html element
[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 $charset . ' text with dash in html-element 28|...|1' => array(
554 '28|...|1', 'Some text with a link to <link email.address@example.org - mail "Open email window">my email.address@example.org</link> and text after it', 'Some text with a link to <link email.address@example.org - mail "Open email window">my...</link>', $charset
555 ),
556 ));
557 }
558 return $data;
559 }
560
561 /**
562 * Checks if stdWrap.cropHTML works with plain text cropping from left
563 *
564 * @test
565 *
566 * @dataProvider cropHtmlDataProvider
567 *
568 * @param string $settings
569 * the settings for the crop function, for example "-58|..."
570 * @param string $subject the string to crop
571 * @param string $expected the expected cropped result
572 * @param string $charset the charset that will be set as renderCharset
573 */
574 public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) {
575 $this->handleCharset($charset, $subject, $expected);
576
577 $this->assertEquals(
578 $expected,
579 $this->cObj->cropHTML($subject, $settings),
580 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"'
581 );
582 }
583
584 /**
585 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
586 * counts multiple invisible characters not as one (as the browser will output the content).
587 *
588 * @test
589 */
590 public function cropHtmlWorksWithComplexContent() {
591 $GLOBALS['TSFE']->renderCharset = 'iso-8859-1';
592 $subject = '
593 <h1>Blog Example</h1>
594 <hr>
595 <div class="csc-header csc-header-n1">
596 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
597 </div>
598 <p class="bodytext">
599 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>.
600 </p>
601 <div class="tx-blogexample-list-container">
602 <p class="bodytext">
603 Below are the most recent posts:
604 </p>
605 <ul>
606 <li>
607 <h3>
608 <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>
609 </h3>
610 <p class="bodytext">
611 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
612 </p>
613 <p class="metadata">
614 Published on 26.08.2009 by Jochen Rau
615 </p>
616 <p>
617 Tags: [MVC]&nbsp;[Domain Driven Design]&nbsp;<br>
618 <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>
619 <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>
620 </p>
621 </li>
622 </ul>
623 <p>
624 <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>
625 </p>
626 </div>
627 <hr>
628 <p>
629 ? TYPO3 Association
630 </p>
631 ';
632
633 $result = $this->cObj->cropHTML($subject, '300');
634 $expected = '
635 <h1>Blog Example</h1>
636 <hr>
637 <div class="csc-header csc-header-n1">
638 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
639 </div>
640 <p class="bodytext">
641 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>.
642 </p>
643 <div class="tx-blogexample-list-container">
644 <p class="bodytext">
645 Below are the most recent posts:
646 </p>
647 <ul>
648 <li>
649 <h3>
650 <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>';
651 $this->assertEquals($expected, $result);
652
653 $result = $this->cObj->cropHTML($subject, '-100');
654 $expected = '<div class="tx-blogexample-list-container"><ul><li><p>Design]&nbsp;<br>
655 <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>
656 <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>
657 </p>
658 </li>
659 </ul>
660 <p>
661 <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>
662 </p>
663 </div>
664 <hr>
665 <p>
666 ? TYPO3 Association
667 </p>
668 ';
669 $this->assertEquals(
670 $expected,
671 $result
672 );
673 }
674
675 /**
676 * @return array
677 */
678 public function stdWrap_roundDataProvider() {
679 return array(
680 'rounding off without any configuration' => array(
681 1.123456789,
682 array(
683 ),
684 1
685 ),
686 'rounding up without any configuration' => array(
687 1.523456789,
688 array(
689 ),
690 2
691 ),
692 'regular rounding (off) to two decimals' => array(
693 0.123456789,
694 array(
695 'decimals' => 2
696 ),
697 0.12
698 ),
699 'regular rounding (up) to two decimals' => array(
700 0.1256789,
701 array(
702 'decimals' => 2
703 ),
704 0.13
705 ),
706 'rounding up to integer with type ceil' => array(
707 0.123456789,
708 array(
709 'roundType' => 'ceil'
710 ),
711 1
712 ),
713 'rounding down to integer with type floor' => array(
714 2.3481,
715 array(
716 'roundType' => 'floor'
717 ),
718 2
719 )
720 );
721 }
722
723 /**
724 * Test for the stdWrap function "round"
725 *
726 * @param float $float
727 * @param array $conf
728 * @param float $expected
729 * @return void
730 *
731 * @dataProvider stdWrap_roundDataProvider
732 * @test
733 */
734 public function stdWrap_round($float, $conf, $expected) {
735 $conf = array(
736 'round.' => $conf
737 );
738 $result = $this->cObj->stdWrap_round($float, $conf);
739 $this->assertEquals($expected, $result);
740 }
741
742 /**
743 * Data provider for the hash test
744 *
745 * @return array multi-dimensional array with the second level like this:
746 * 0 => the plain text
747 * 1 => the conf array for the hash stdWrap function
748 * 2 => the expected result
749 *
750 * @see hash
751 */
752 public function hashDataProvider() {
753 $data = array(
754 'testing md5' => array(
755 'joh316',
756 array(
757 'hash' => 'md5'
758 ),
759 'bacb98acf97e0b6112b1d1b650b84971'
760 ),
761 'testing sha1' => array(
762 'joh316',
763 array(
764 'hash' => 'sha1'
765 ),
766 '063b3d108bed9f88fa618c6046de0dccadcf3158'
767 ),
768 'testing non-existing hashing algorithm' => array(
769 'joh316',
770 array(
771 'hash' => 'non-existing'
772 ),
773 ''
774 ),
775 'testing stdWrap capability' => array(
776 'joh316',
777 array(
778 'hash.' => array(
779 'cObject' => 'TEXT',
780 'cObject.' => array(
781 'value' => 'md5'
782 )
783 )
784 ),
785 'bacb98acf97e0b6112b1d1b650b84971'
786 )
787 );
788 return $data;
789 }
790
791 /**
792 * Test for the stdWrap function "hash"
793 *
794 * @param string $text
795 * @param array $conf
796 * @param string $expected
797 * @return void
798 *
799 * @dataProvider hashDataProvider
800 * @test
801 */
802 public function stdWrap_hash($text, array $conf, $expected) {
803 $result = $this->cObj->stdWrap_hash($text, $conf);
804 $this->assertEquals($expected, $result);
805 }
806
807 /**
808 * Data provider for the numberFormat test
809 *
810 * @return array multi-dimensional array with the second level like this:
811 * 0 => the input float number
812 * 1 => the conf array for the numberFormat stdWrap function
813 * 2 => the expected result
814 *
815 * @see numberFormat
816 */
817 public function numberFormatDataProvider() {
818 $data = array(
819 'testing decimals' => array(
820 0.8,
821 array(
822 'decimals' => 2
823 ),
824 '0.80'
825 ),
826 'testing dec_point' => array(
827 0.8,
828 array(
829 'decimals' => 1,
830 'dec_point' => ','
831 ),
832 '0,8'
833 ),
834 'testing thousands_sep' => array(
835 999.99,
836 array(
837 'decimals' => 0,
838 'thousands_sep.' => array(
839 'char' => 46
840 )
841 ),
842 '1.000'
843 ),
844 'testing mixture' => array(
845 1281731.45,
846 array(
847 'decimals' => 1,
848 'dec_point.' => array(
849 'char' => 44
850 ),
851 'thousands_sep.' => array(
852 'char' => 46
853 )
854 ),
855 '1.281.731,5'
856 )
857 );
858 return $data;
859 }
860
861 /**
862 * Check if stdWrap.numberFormat and all of its properties work properly
863 *
864 * @dataProvider numberFormatDataProvider
865 *
866 * @test
867 */
868 public function numberFormat($float, $formatConf, $expected) {
869 $result = $this->cObj->numberFormat($float, $formatConf);
870 $this->assertEquals($expected, $result);
871 }
872
873 /**
874 * Data provider for the replacement test
875 *
876 * @return array multi-dimensional array with the second level like this:
877 * 0 => the input text
878 * 1 => the conf array for the replacement stdWrap function
879 * 2 => the expected result
880 *
881 * @see replacement
882 */
883 public function replacementDataProvider() {
884 $data = array(
885 'multiple replacements, including regex' => array(
886 'There_is_a_cat,_a_dog_and_a_tiger_in_da_hood!_Yeah!',
887 array('replacement.' =>
888 array(
889 '120.' => array(
890 'search' => 'in da hood',
891 'replace' => 'around the block',
892 ),
893 '20.' => array(
894 'search' => '_',
895 'replace.' => array('char' => '32'),
896 ),
897 '130.' => array(
898 'search' => '#a (Cat|Dog|Tiger)#i',
899 'replace' => 'an animal',
900 'useRegExp' => '1',
901 ),
902 ),
903 ),
904 'There is an animal, an animal and an animal around the block! Yeah!'
905 ),
906 );
907 return $data;
908 }
909
910 /**
911 * Check if stdWrap.replacement and all of its properties work properly
912 *
913 * @dataProvider replacementDataProvider
914 *
915 * @test
916 */
917 public function replacement($input, $conf, $expected) {
918 $result = $this->cObj->stdWrap_replacement($input, $conf);
919 $this->assertEquals($expected, $result);
920 }
921 }
922 ?>