[FEATURE] Add "allowedTags" argument on f:format.stripTags
[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
18 /**
19 * Test case
20 */
21 class StripTagsViewHelperTest extends ViewHelperBaseTestcase
22 {
23 /**
24 * @var \TYPO3\CMS\Fluid\ViewHelpers\Format\StripTagsViewHelper
25 */
26 protected $viewHelper;
27
28 protected function setUp()
29 {
30 parent::setUp();
31 $this->viewHelper = $this->getMock(\TYPO3\CMS\Fluid\ViewHelpers\Format\StripTagsViewHelper::class, array('renderChildren'));
32 $this->injectDependenciesIntoViewHelper($this->viewHelper);
33 $this->viewHelper->initializeArguments();
34 }
35
36 /**
37 * @test
38 */
39 public function renderUsesValueAsSourceIfSpecified()
40 {
41 $this->viewHelper->expects($this->never())->method('renderChildren');
42 $actualResult = $this->viewHelper->render('Some string');
43 $this->assertEquals('Some string', $actualResult);
44 }
45
46 /**
47 * @test
48 */
49 public function renderUsesChildnodesAsSourceIfSpecified()
50 {
51 $this->viewHelper->expects($this->atLeastOnce())->method('renderChildren')->will($this->returnValue('Some string'));
52 $actualResult = $this->viewHelper->render();
53 $this->assertEquals('Some string', $actualResult);
54 }
55
56 /**
57 * Data Provider for the render tests
58 *
59 * @return array
60 */
61 public function stringsTestDataProvider()
62 {
63 return array(
64 array('This is a sample text without special characters.', '', 'This is a sample text without special characters.'),
65 array('This is a sample text <b>with <i>some</i> tags</b>.', '', 'This is a sample text with some tags.'),
66 array('This text contains some &quot;&Uuml;mlaut&quot;.', '', 'This text contains some &quot;&Uuml;mlaut&quot;.'),
67 array('This text <i>contains</i> some <strong>allowed</strong> tags.', '<strong>', 'This text contains some <strong>allowed</strong> tags.'),
68 );
69 }
70
71 /**
72 * @test
73 * @dataProvider stringsTestDataProvider
74 */
75 public function renderCorrectlyConvertsIntoPlaintext($source, $allowed, $expectedResult)
76 {
77 $actualResult = $this->viewHelper->render($source, $allowed);
78 $this->assertSame($expectedResult, $actualResult);
79 }
80
81 /**
82 * @test
83 */
84 public function renderReturnsUnmodifiedSourceIfItIsNoString()
85 {
86 $source = new \stdClass();
87 $actualResult = $this->viewHelper->render($source);
88 $this->assertSame($source, $actualResult);
89 }
90 }