‪TYPO3CMS  9.5
UrlencodeViewHelperTest.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 ‪UrlencodeViewHelperTest extends ViewHelperBaseTestcase
24 {
28  protected ‪$viewHelper;
29 
30  protected function ‪setUp()
31  {
32  parent::setUp();
33  $this->viewHelper = new ‪UrlencodeViewHelper();
34  $this->injectDependenciesIntoViewHelper($this->viewHelper);
35  }
36 
41  {
42  $this->setArgumentsUnderTest(
43  $this->viewHelper,
44  [
45  'value' => 'Source'
46  ]
47  );
48  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
49  $this->assertEquals('Source', $actualResult);
50  }
51 
56  {
57  $this->setArgumentsUnderTest(
58  $this->viewHelper,
59  [
60  'value' => 'Source'
61  ]
62  );
63 
64  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
65  $this->assertEquals('Source', $actualResult);
66  }
67 
72  {
73  $source = 'StringWithoutSpecialCharacters';
74 
75  $this->setArgumentsUnderTest(
76  $this->viewHelper,
77  [
78  'value' => $source
79  ]
80  );
81  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
82  $this->assertSame($source, $actualResult);
83  }
84 
88  public function ‪renderEncodesString()
89  {
90  $source = 'Foo @+%/ "';
91  $expectedResult = 'Foo%20%40%2B%25%2F%20%22';
92 
93  $this->setArgumentsUnderTest(
94  $this->viewHelper,
95  [
96  'value' => $source
97  ]
98  );
99 
100  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
101  $this->assertEquals($expectedResult, $actualResult);
102  }
103 
114  public function ‪renderEscapesObjectIfPossible($source, $expectation)
115  {
116  $this->setArgumentsUnderTest(
117  $this->viewHelper,
118  [
119  'value' => $source
120  ]
121  );
122  $actualResult = $this->viewHelper->render();
123  $this->assertSame($expectation, $actualResult);
124  }
125 
129  public function ‪renderEscapesObjectIfPossibleDataProvider(): array
130  {
131  $stdClass = new \stdClass();
132  $toStringClass = new class() {
133  public function __toString(): string
134  {
135  return '<script>alert(\'"xss"\')</script>';
136  }
137  };
138 
139  return [
140  'plain object' => [$stdClass, $stdClass],
141  'object with __toString()' => [$toStringClass, '%3Cscript%3Ealert%28%27%22xss%22%27%29%3C%2Fscript%3E'],
142  ];
143  }
144 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters
‪renderDoesNotModifyValueIfItDoesNotContainSpecialCharacters()
Definition: UrlencodeViewHelperTest.php:70
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest
Definition: UrlencodeViewHelperTest.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderEncodesString
‪renderEncodesString()
Definition: UrlencodeViewHelperTest.php:87
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format
Definition: BytesViewHelperTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderEscapesObjectIfPossibleDataProvider
‪array renderEscapesObjectIfPossibleDataProvider()
Definition: UrlencodeViewHelperTest.php:128
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\setUp
‪setUp()
Definition: UrlencodeViewHelperTest.php:29
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderUsesChildnodesAsSourceIfSpecified
‪renderUsesChildnodesAsSourceIfSpecified()
Definition: UrlencodeViewHelperTest.php:54
‪TYPO3\CMS\Fluid\ViewHelpers\Format\UrlencodeViewHelper
Definition: UrlencodeViewHelper.php:52
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderEscapesObjectIfPossible
‪renderEscapesObjectIfPossible($source, $expectation)
Definition: UrlencodeViewHelperTest.php:113
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\$viewHelper
‪UrlencodeViewHelper $viewHelper
Definition: UrlencodeViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Format\UrlencodeViewHelperTest\renderUsesValueAsSourceIfSpecified
‪renderUsesValueAsSourceIfSpecified()
Definition: UrlencodeViewHelperTest.php:39