‪TYPO3CMS  9.5
JavaScriptEncoderTest.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\Core\Unit\UnitTestCase;
19 
23 class ‪JavaScriptEncoderTest extends UnitTestCase
24 {
28  protected ‪$resetSingletonInstances = true;
29 
36  {
37  return [
38  'Immune characters are returned as is' => [
39  '._,',
40  '._,'
41  ],
42  'Alphanumerical characters are returned as is' => [
43  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
44  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
45  ],
46  'Angel brackets and ampersand are encoded' => [
47  '<>&',
48  '\\x3C\\x3E\\x26'
49  ],
50  'Quotes and slashes are encoded' => [
51  '"\'\\/',
52  '\\x22\\x27\\x5C\\x2F'
53  ],
54  'Empty string stays empty' => [
55  '',
56  ''
57  ],
58  'Exclamation mark and space are properly encoded' => [
59  'Hello World!',
60  'Hello\\x20World\\x21'
61  ],
62  'Whitespaces are properly encoded' => [
63  "\t" . LF . CR . ' ',
64  '\\x09\\x0A\\x0D\\x20'
65  ],
66  'Null byte is properly encoded' => [
67  "\0",
68  '\\x00'
69  ],
70  'Umlauts are properly encoded' => [
71  'ÜüÖöÄä',
72  '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
73  ]
74  ];
75  }
76 
83  public function ‪encodeEncodesCorrectly($input, $expected)
84  {
85  $subject = new ‪JavaScriptEncoder();
86  $this->assertSame($expected, $subject->encode($input));
87  }
88 }
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Encoder\JavaScriptEncoderTest\encodeEncodesCorrectlyDataProvider
‪array encodeEncodesCorrectlyDataProvider()
Definition: JavaScriptEncoderTest.php:34
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Encoder
Definition: JavaScriptEncoderTest.php:2
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Encoder\JavaScriptEncoderTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: JavaScriptEncoderTest.php:27
‪TYPO3\CMS\Core\Encoder\JavaScriptEncoder
Definition: JavaScriptEncoder.php:28
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Encoder\JavaScriptEncoderTest
Definition: JavaScriptEncoderTest.php:24
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Encoder\JavaScriptEncoderTest\encodeEncodesCorrectly
‪encodeEncodesCorrectly($input, $expected)
Definition: JavaScriptEncoderTest.php:82