[TASK] Move render arguments StripTagsViewHelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Tests / Unit / ViewHelpers / Format / StripTagsViewHelperTest.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\StripTagsViewHelper;
18
19 /**
20 * Test case
21 */
22 class StripTagsViewHelperTest extends ViewHelperBaseTestcase
23 {
24 /**
25 * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\StripTagsViewHelper
26 */
27 protected $viewHelper;
28
29 protected function setUp()
30 {
31 parent::setUp();
32 $this->viewHelper = new StripTagsViewHelper();
33 $this->injectDependenciesIntoViewHelper($this->viewHelper);
34 }
35
36 /**
37 * @test
38 */
39 public function renderUsesValueAsSourceIfSpecified()
40 {
41 $this->setArgumentsUnderTest(
42 $this->viewHelper,
43 [
44 'value' => 'Some string',
45 ]
46 );
47 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
48 $this->assertEquals('Some string', $actualResult);
49 }
50
51 /**
52 * @test
53 */
54 public function renderUsesChildnodesAsSourceIfSpecified()
55 {
56 $this->setArgumentsUnderTest(
57 $this->viewHelper,
58 [
59 'value' => 'Some string',
60 ]
61 );
62 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
63 $this->assertEquals('Some string', $actualResult);
64 }
65
66 /**
67 * Data Provider for the render tests
68 *
69 * @return array
70 */
71 public function stringsTestDataProvider()
72 {
73 return array(
74 array('This is a sample text without special characters.', '', 'This is a sample text without special characters.'),
75 array('This is a sample text <b>with <i>some</i> tags</b>.', '', 'This is a sample text with some tags.'),
76 array('This text contains some &quot;&Uuml;mlaut&quot;.', '', 'This text contains some &quot;&Uuml;mlaut&quot;.'),
77 array('This text <i>contains</i> some <strong>allowed</strong> tags.', '<strong>', 'This text contains some <strong>allowed</strong> tags.'),
78 );
79 }
80
81 /**
82 * @test
83 * @dataProvider stringsTestDataProvider
84 * @param $source
85 * @param $allowed
86 * @param $expectedResult
87 */
88 public function renderCorrectlyConvertsIntoPlaintext($source, $allowed, $expectedResult)
89 {
90 $this->setArgumentsUnderTest(
91 $this->viewHelper,
92 [
93 'value' => $source,
94 'allowedTags' => $allowed
95 ]
96 );
97 $actualResult = $this->viewHelper->initializeArgumentsAndRender();
98 $this->assertSame($expectedResult, $actualResult);
99 }
100
101 /**
102 * @test
103 */
104 public function renderReturnsUnmodifiedSourceIfItIsNoString()
105 {
106 $source = new \stdClass();
107 $this->setArgumentsUnderTest(
108 $this->viewHelper,
109 [
110 'value' => $source
111 ]
112 );
113 $actualResult = $this->viewHelper->render();
114 $this->assertSame($source, $actualResult);
115 }
116 }