bf93455aee40ce41f51cbbbb3e8f3b776033cec9
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Format / Nl2brViewHelperTest.php
1 <?php
2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\ViewHelperBaseTestcase;
17 use TYPO3\CMS\Fluid\ViewHelpers\Format\Nl2brViewHelper;
18
19 /**
20 * Test case
21 */
22 class Nl2brViewHelperTest extends ViewHelperBaseTestcase
23 {
24 /**
25 * @var Nl2brViewHelper
26 */
27 protected $viewHelper;
28
29 protected function setUp()
30 {
31 parent::setUp();
32 $this->viewHelper = $this->getMockBuilder(Nl2brViewHelper::class)
33 ->setMethods(array('renderChildren'))
34 ->getMock();
35 $this->injectDependenciesIntoViewHelper($this->viewHelper);
36 $this->viewHelper->initializeArguments();
37 }
38
39 /**
40 * @test
41 */
42 public function viewHelperDoesNotModifyTextWithoutLineBreaks()
43 {
44 $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('<p class="bodytext">Some Text without line breaks</p>'));
45 $actualResult = $this->viewHelper->render();
46 $this->assertEquals('<p class="bodytext">Some Text without line breaks</p>', $actualResult);
47 }
48
49 /**
50 * @test
51 */
52 public function viewHelperConvertsLineBreaksToBRTags()
53 {
54 $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(10) . 'Line 2'));
55 $actualResult = $this->viewHelper->render();
56 $this->assertEquals('Line 1<br />' . chr(10) . 'Line 2', $actualResult);
57 }
58
59 /**
60 * @test
61 */
62 public function viewHelperConvertsWindowsLineBreaksToBRTags()
63 {
64 $this->viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('Line 1' . chr(13) . chr(10) . 'Line 2'));
65 $actualResult = $this->viewHelper->render();
66 $this->assertEquals('Line 1<br />' . chr(13) . chr(10) . 'Line 2', $actualResult);
67 }
68 }