‪TYPO3CMS  10.4
UrlencodeViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
19 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
20 
24 class ‪UrlencodeViewHelperTest extends ViewHelperBaseTestcase
25 {
29  protected ‪$viewHelper;
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->viewHelper = new ‪UrlencodeViewHelper();
35  $this->injectDependenciesIntoViewHelper($this->viewHelper);
36  }
37 
42  {
43  $this->setArgumentsUnderTest(
44  $this->viewHelper,
45  [
46  'value' => 'Source'
47  ]
48  );
49  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
50  self::assertEquals('Source', $actualResult);
51  }
52 
57  {
58  $this->setArgumentsUnderTest(
59  $this->viewHelper,
60  [
61  'value' => 'Source'
62  ]
63  );
64 
65  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
66  self::assertEquals('Source', $actualResult);
67  }
68 
73  {
74  $source = 'StringWithoutSpecialCharacters';
75 
76  $this->setArgumentsUnderTest(
77  $this->viewHelper,
78  [
79  'value' => $source
80  ]
81  );
82  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
83  self::assertSame($source, $actualResult);
84  }
85 
89  public function ‪renderEncodesString()
90  {
91  $source = 'Foo @+%/ "';
92  $expectedResult = 'Foo%20%40%2B%25%2F%20%22';
93 
94  $this->setArgumentsUnderTest(
95  $this->viewHelper,
96  [
97  'value' => $source
98  ]
99  );
100 
101  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
102  self::assertEquals($expectedResult, $actualResult);
103  }
104 
115  public function ‪renderEscapesObjectIfPossible($source, $expectation)
116  {
117  $this->setArgumentsUnderTest(
118  $this->viewHelper,
119  [
120  'value' => $source
121  ]
122  );
123  $actualResult = $this->viewHelper->render();
124  self::assertSame($expectation, $actualResult);
125  }
126 
130  public function ‪renderEscapesObjectIfPossibleDataProvider(): array
131  {
132  $stdClass = new \stdClass();
133  $toStringClass = new class() {
134  public function __toString(): string
135  {
136  return '<script>alert(\'"xss"\')</script>';
137  }
138  };
139 
140  return [
141  'plain object' => [$stdClass, $stdClass],
142  'object with __toString()' => [$toStringClass, '%3Cscript%3Ealert%28%27%22xss%22%27%29%3C%2Fscript%3E'],
143  ];
144  }
145 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters
‪renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters()
Definition: UrlencodeViewHelperTest.php:71
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest
Definition: UrlencodeViewHelperTest.php:25
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderEncodesString
‪renderEncodesString()
Definition: UrlencodeViewHelperTest.php:88
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: ScriptViewHelperTest.php:18
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderEscapesObjectIfPossibleDataProvider
‪array renderEscapesObjectIfPossibleDataProvider()
Definition: UrlencodeViewHelperTest.php:129
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\setUp
‪setUp()
Definition: UrlencodeViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderUsesChildnodesAsSourceIfSpecified
‪renderUsesChildnodesAsSourceIfSpecified()
Definition: UrlencodeViewHelperTest.php:55
‪TYPO3\CMS\Fluid\ViewHelpers\Format\UrlencodeViewHelper
Definition: UrlencodeViewHelper.php:53
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderEscapesObjectIfPossible
‪renderEscapesObjectIfPossible($source, $expectation)
Definition: UrlencodeViewHelperTest.php:114
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\$viewHelper
‪UrlencodeViewHelper $viewHelper
Definition: UrlencodeViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderUsesValueAsSourceIfSpecified
‪renderUsesValueAsSourceIfSpecified()
Definition: UrlencodeViewHelperTest.php:40