a3ce27d2fab8d6bdb9404b23fb6f704bd905c19e
[Packages/TYPO3.CMS.git] / tests / typo3 / sysext / cms / 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 = '&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 = '&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 = '&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 = '&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 //////////////////////////////
379 // Tests concerning crop
380 //////////////////////////////
381
382 /**
383 * @test
384 */
385 public function cropIsMultibyteSafe() {
386 $this->assertEquals('бла', $this->cObj->crop('бла', '3|...'));
387 }
388
389 //////////////////////////////
390 // Tests concerning cropHTML
391 //////////////////////////////
392
393 /**
394 * This is the data provider for the tests of crop and cropHTML below. It provides all combinations
395 * of charset, text type, and configuration options to be tested.
396 *
397 * @return array two-dimensional array with the second level like this:
398 * 0 => the settings for the crop function, for example "-58|..."
399 * 1 => the string to crop
400 * 2 => the expected cropped result
401 * 3 => the charset that will be set as renderCharset
402 *
403 * @see cropHtmlWithDataProvider
404 */
405 public function cropHtmlDataProvider() {
406 $plainText = 'Kasper Sk' . chr(229) . 'rh' . chr(248) .
407 'j implemented the original version of the crop function.';
408 $textWithMarkup = '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' .
409 chr(229) . 'rh' . chr(248) . 'j</a>' .
410 ' implemented</strong> the original version of the crop function.';
411 $textWithEntities = 'Kasper Sk&aring;rh&oslash;j implemented the; original ' .
412 'version of the crop function.';
413
414 $charsets = array('iso-8859-1', 'utf-8', 'ascii', 'big5');
415
416 $data = array();
417 foreach ($charsets as $charset) {
418 $data = array_merge($data, array(
419 $charset . ' plain text; 11|...' => array(
420 '11|...', $plainText, 'Kasper Sk' . chr(229) . 'r...', $charset
421 ),
422 $charset . ' plain text; -58|...' => array(
423 '-58|...', $plainText, '...h' . chr(248) . 'j implemented the original version of the crop function.', $charset
424 ),
425 $charset . ' plain text; 4|...|1' => array(
426 '4|...|1', $plainText, 'Kasp...', $charset
427 ),
428 $charset . ' plain text; 20|...|1' => array(
429 '20|...|1', $plainText, 'Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j...', $charset
430 ),
431 $charset . ' plain text; -5|...|1' => array(
432 '-5|...|1', $plainText, '...tion.', $charset
433 ),
434 $charset . ' plain text; -49|...|1' => array(
435 '-49|...|1', $plainText, '...the original version of the crop function.', $charset
436 ),
437 $charset . ' text with markup; 11|...' => array(
438 '11|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'r...</a></strong>', $charset
439 ),
440 $charset . ' text with markup; 13|...' => array(
441 '13|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . '...</a></strong>', $charset
442 ),
443 $charset . ' text with markup; 14|...' => array(
444 '14|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>', $charset
445 ),
446 $charset . ' text with markup; 15|...' => array(
447 '15|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> ...</strong>', $charset
448 ),
449 $charset . ' text with markup; 29|...' => array(
450 '29|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong> th...', $charset
451 ),
452 $charset . ' text with markup; -58|...' => array(
453 '-58|...', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">...h' . chr(248) . 'j</a> implemented</strong> the original version of the crop function.', $charset
454 ),
455 $charset . ' text with markup 4|...|1' => array(
456 '4|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasp...</a></strong>', $charset
457 ),
458 $charset . ' text with markup; 11|...|1' => array(
459 '11|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>', $charset
460 ),
461 $charset . ' text with markup; 13|...|1' => array(
462 '13|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper...</a></strong>', $charset
463 ),
464 $charset . ' text with markup; 14|...|1' => array(
465 '14|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>', $charset
466 ),
467 $charset . ' text with markup; 15|...|1' => array(
468 '15|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a>...</strong>', $charset
469 ),
470 $charset . ' text with markup; 29|...|1' => array(
471 '29|...|1', $textWithMarkup, '<strong><a href="mailto:kasper@typo3.org">Kasper Sk' . chr(229) . 'rh' . chr(248) . 'j</a> implemented</strong>...', $charset
472 ),
473 $charset . ' text with markup; -66|...|1' => array(
474 '-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
475 ),
476 $charset . ' text with entities 9|...' => array(
477 '9|...', $textWithEntities, 'Kasper Sk...', $charset
478 ),
479 $charset . ' text with entities 10|...' => array(
480 '10|...', $textWithEntities, 'Kasper Sk&aring;...', $charset
481 ),
482 $charset . ' text with entities 11|...' => array(
483 '11|...', $textWithEntities, 'Kasper Sk&aring;r...', $charset
484 ),
485 $charset . ' text with entities 13|...' => array(
486 '13|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;...', $charset
487 ),
488 $charset . ' text with entities 14|...' => array(
489 '14|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
490 ),
491 $charset . ' text with entities 15|...' => array(
492 '15|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j ...', $charset
493 ),
494 $charset . ' text with entities 16|...' => array(
495 '16|...', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j i...', $charset
496 ),
497 $charset . ' text with entities -57|...' => array(
498 '-57|...', $textWithEntities, '...j implemented the; original version of the crop function.', $charset
499 ),
500 $charset . ' text with entities -58|...' => array(
501 '-58|...', $textWithEntities, '...&oslash;j implemented the; original version of the crop function.', $charset
502 ),
503 $charset . ' text with entities -59|...' => array(
504 '-59|...', $textWithEntities, '...h&oslash;j implemented the; original version of the crop function.', $charset
505 ),
506 $charset . ' text with entities 4|...|1' => array(
507 '4|...|1', $textWithEntities, 'Kasp...', $charset
508 ),
509 $charset . ' text with entities 9|...|1' => array(
510 '9|...|1', $textWithEntities, 'Kasper...', $charset
511 ),
512 $charset . ' text with entities 10|...|1' => array(
513 '10|...|1', $textWithEntities, 'Kasper...', $charset
514 ),
515 $charset . ' text with entities 11|...|1' => array(
516 '11|...|1', $textWithEntities, 'Kasper...', $charset
517 ),
518 $charset . ' text with entities 13|...|1' => array(
519 '13|...|1', $textWithEntities, 'Kasper...', $charset
520 ),
521 $charset . ' text with entities 14|...|1' => array(
522 '14|...|1', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
523 ),
524 $charset . ' text with entities 15|...|1' => array(
525 '15|...|1', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
526 ),
527 $charset . ' text with entities 16|...|1' => array(
528 '16|...|1', $textWithEntities, 'Kasper Sk&aring;rh&oslash;j...', $charset
529 ),
530 $charset . ' text with entities -57|...|1' => array(
531 '-57|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset
532 ),
533 $charset . ' text with entities -58|...|1' => array(
534 '-58|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset
535 ),
536 $charset . ' text with entities -59|...|1' => array(
537 '-59|...|1', $textWithEntities, '...implemented the; original version of the crop function.', $charset
538 ),
539 ));
540 }
541 return $data;
542 }
543
544 /**
545 * Checks if stdWrap.cropHTML works with plain text cropping from left
546 *
547 * @test
548 *
549 * @dataProvider cropHtmlDataProvider
550 *
551 * @param string $settings
552 * the settings for the crop function, for example "-58|..."
553 * @param string $subject the string to crop
554 * @param string $expected the expected cropped result
555 * @param string $charset the charset that will be set as renderCharset
556 */
557 public function cropHtmlWithDataProvider($settings, $subject, $expected, $charset) {
558 $this->handleCharset($charset, $subject, $expected);
559
560 $this->assertEquals(
561 $expected,
562 $this->cObj->cropHTML($subject, $settings),
563 'cropHTML failed with settings: "' . $settings . '" and charset "' . $charset . '"'
564 );
565 }
566
567 /**
568 * Checks if stdWrap.cropHTML works with a complex content with many tags. Currently cropHTML
569 * counts multiple invisible characters not as one (as the browser will output the content).
570 *
571 * @test
572 */
573 public function cropHtmlWorksWithComplexContent() {
574 $GLOBALS['TSFE']->renderCharset = 'iso-8859-1';
575 $subject = '
576 <h1>Blog Example</h1>
577 <hr>
578 <div class="csc-header csc-header-n1">
579 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
580 </div>
581 <p class="bodytext">
582 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>.
583 </p>
584 <div class="tx-blogexample-list-container">
585 <p class="bodytext">
586 Below are the most recent posts:
587 </p>
588 <ul>
589 <li>
590 <h3>
591 <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>
592 </h3>
593 <p class="bodytext">
594 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut...
595 </p>
596 <p class="metadata">
597 Published on 26.08.2009 by Jochen Rau
598 </p>
599 <p>
600 Tags: [MVC]&nbsp;[Domain Driven Design]&nbsp;<br>
601 <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>
602 <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>
603 </p>
604 </li>
605 </ul>
606 <p>
607 <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>
608 </p>
609 </div>
610 <hr>
611 <p>
612 ? TYPO3 Association
613 </p>
614 ';
615
616 $result = $this->cObj->cropHTML($subject, '300');
617 $expected = '
618 <h1>Blog Example</h1>
619 <hr>
620 <div class="csc-header csc-header-n1">
621 <h2 class="csc-firstHeader">Welcome to Blog #1</h2>
622 </div>
623 <p class="bodytext">
624 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>.
625 </p>
626 <div class="tx-blogexample-list-container">
627 <p class="bodytext">
628 Below are the most recent posts:
629 </p>
630 <ul>
631 <li>
632 <h3>
633 <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>';
634 $this->assertEquals($expected, $result);
635
636 $result = $this->cObj->cropHTML($subject, '-100');
637 $expected = '<div class="tx-blogexample-list-container"><ul><li><p>Design]&nbsp;<br>
638 <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>
639 <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>
640 </p>
641 </li>
642 </ul>
643 <p>
644 <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>
645 </p>
646 </div>
647 <hr>
648 <p>
649 ? TYPO3 Association
650 </p>
651 ';
652 $this->assertEquals(
653 $expected,
654 $result
655 );
656 }
657
658 /**
659 * Data provider for the numberFormat test
660 *
661 * @return array multi-dimensional array with the second level like this:
662 * 0 => the input float number
663 * 1 => the conf array for the numberFormat stdWrap function
664 * 2 => the expected result
665 *
666 * @see numberFormat
667 */
668 public function numberFormatDataProvider() {
669 $data = array(
670 'testing decimals' => array(
671 0.8,
672 array(
673 'decimals' => 2
674 ),
675 '0.80'
676 ),
677 'testing dec_point' => array(
678 0.8,
679 array(
680 'decimals' => 1,
681 'dec_point' => ','
682 ),
683 '0,8'
684 ),
685 'testing thousands_sep' => array(
686 999.99,
687 array(
688 'decimals' => 0,
689 'thousands_sep.' => array(
690 'char' => 46
691 )
692 ),
693 '1.000'
694 ),
695 'testing mixture' => array(
696 1281731.45,
697 array(
698 'decimals' => 1,
699 'dec_point.' => array(
700 'char' => 44
701 ),
702 'thousands_sep.' => array(
703 'char' => 46
704 )
705 ),
706 '1.281.731,5'
707 )
708 );
709 return $data;
710 }
711
712 /**
713 * Check if stdWrap.numberFormat and all of its properties work properly
714 *
715 * @dataProvider numberFormatDataProvider
716 *
717 * @test
718 */
719 public function numberFormat($float, $formatConf, $expected) {
720 $result = $this->cObj->numberFormat($float, $formatConf);
721 $this->assertEquals($expected, $result);
722 }
723 }
724 ?>