TYPO3 CMS  TYPO3_7-6
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 
21 {
25  protected $subject = null;
26 
27  protected function setUp()
28  {
29  $this->subject = new \TYPO3\CMS\Core\Encoder\JavaScriptEncoder();
30  }
31 
38  {
39  return [
40  'Immune characters are returned as is' => [
41  '._,',
42  '._,'
43  ],
44  'Alphanumerical characters are returned as is' => [
45  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
46  'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
47  ],
48  'Angel brackets and ampersand are encoded' => [
49  '<>&',
50  '\\x3C\\x3E\\x26'
51  ],
52  'Quotes and slashes are encoded' => [
53  '"\'\\/',
54  '\\x22\\x27\\x5C\\x2F'
55  ],
56  'Empty string stays empty' => [
57  '',
58  ''
59  ],
60  'Exclamation mark and space are properly encoded' => [
61  'Hello World!',
62  'Hello\\x20World\\x21'
63  ],
64  'Whitespaces are properly encoded' => [
65  TAB . LF . CR . ' ',
66  '\\x09\\x0A\\x0D\\x20'
67  ],
68  'Null byte is properly encoded' => [
69  chr(0),
70  '\\x00'
71  ],
72  'Umlauts are properly encoded' => [
73  'ÜüÖöÄä',
74  '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
75  ]
76  ];
77  }
78 
85  public function encodeEncodesCorrectly($input, $expected)
86  {
87  $this->assertSame($expected, $this->subject->encode($input));
88  }
89 }