‪TYPO3CMS  9.5
StripTagsViewHelperTest.php
Go to the documentation of this file.
1 <?php
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 
18 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
19 
23 class ‪StripTagsViewHelperTest extends ViewHelperBaseTestcase
24 {
28  protected ‪$viewHelper;
29 
30  protected function ‪setUp()
31  {
32  parent::setUp();
33  $this->viewHelper = new ‪StripTagsViewHelper();
34  $this->injectDependenciesIntoViewHelper($this->viewHelper);
35  }
36 
41  {
42  $this->setArgumentsUnderTest(
43  $this->viewHelper,
44  [
45  'value' => 'Some string',
46  ]
47  );
48  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
49  $this->assertEquals('Some string', $actualResult);
50  }
51 
56  {
57  $this->setArgumentsUnderTest(
58  $this->viewHelper,
59  [
60  'value' => 'Some string',
61  ]
62  );
63  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
64  $this->assertEquals('Some string', $actualResult);
65  }
66 
72  public function ‪stringsTestDataProvider()
73  {
74  return [
75  ['This is a sample text without special characters.', '', 'This is a sample text without special characters.'],
76  ['This is a sample text <b>with <i>some</i> tags</b>.', '', 'This is a sample text with some tags.'],
77  ['This text contains some &quot;&Uuml;mlaut&quot;.', '', 'This text contains some &quot;&Uuml;mlaut&quot;.'],
78  ['This text <i>contains</i> some <strong>allowed</strong> tags.', '<strong>', 'This text contains some <strong>allowed</strong> tags.'],
79  ];
80  }
81 
89  public function ‪renderCorrectlyConvertsIntoPlaintext($source, $allowed, $expectedResult)
90  {
91  $this->setArgumentsUnderTest(
92  $this->viewHelper,
93  [
94  'value' => $source,
95  'allowedTags' => $allowed
96  ]
97  );
98  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
99  $this->assertSame($expectedResult, $actualResult);
100  }
101 
112  public function ‪renderEscapesObjectIfPossible($source, $expectation)
113  {
114  $this->setArgumentsUnderTest(
115  $this->viewHelper,
116  [
117  'value' => $source
118  ]
119  );
120  $actualResult = $this->viewHelper->render();
121  $this->assertSame($expectation, $actualResult);
122  }
123 
127  public function ‪renderEscapesObjectIfPossibleDataProvider(): array
128  {
129  $stdClass = new \stdClass();
130  $toStringClass = new class() {
131  public function __toString(): string
132  {
133  return '<script>alert(\'"xss"\')</script>';
134  }
135  };
136 
137  return [
138  'plain object' => [$stdClass, $stdClass],
139  'object with __toString()' => [$toStringClass, 'alert(\'"xss"\')'],
140  ];
141  }
142 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest
Definition: StripTagsViewHelperTest.php:24
‪TYPO3\CMS\Fluid\ViewHelpers\Format\StripTagsViewHelper
Definition: StripTagsViewHelper.php:72
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\renderUsesChildnodesAsSourceIfSpecified
‪renderUsesChildnodesAsSourceIfSpecified()
Definition: StripTagsViewHelperTest.php:54
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\renderEscapesObjectIfPossible
‪renderEscapesObjectIfPossible($source, $expectation)
Definition: StripTagsViewHelperTest.php:111
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers Format StripTagsViewHelper $viewHelper
Definition: StripTagsViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: BytesViewHelperTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\stringsTestDataProvider
‪array stringsTestDataProvider()
Definition: StripTagsViewHelperTest.php:71
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\renderUsesValueAsSourceIfSpecified
‪renderUsesValueAsSourceIfSpecified()
Definition: StripTagsViewHelperTest.php:39
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\setUp
‪setUp()
Definition: StripTagsViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\renderEscapesObjectIfPossibleDataProvider
‪array renderEscapesObjectIfPossibleDataProvider()
Definition: StripTagsViewHelperTest.php:126
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\StripTagsViewHelperTest\renderCorrectlyConvertsIntoPlaintext
‪renderCorrectlyConvertsIntoPlaintext($source, $allowed, $expectedResult)
Definition: StripTagsViewHelperTest.php:88