[TASK] Change $fixture to $subject in unit-tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Encoder / JavaScriptEncoderTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Encoder;
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
17 /**
18 * Test cases for TYPO3\CMS\Core\Encoder\JavaScriptEncoder.
19 *
20 * @author Helmut Hummel <helmut.hummel@typo3.org>
21 */
22 class JavaScriptEncoderTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Core\Encoder\JavaScriptEncoder
26 */
27 protected $subject = NULL;
28
29 protected function setUp() {
30 $this->subject = new \TYPO3\CMS\Core\Encoder\JavaScriptEncoder();
31 }
32
33 /**
34 * Data provider for encodeEncodesCorrectly.
35 *
36 * @return array
37 */
38 public function encodeEncodesCorrectlyDataProvider() {
39 return array(
40 'Immune characters are returned as is' => array(
41 '._,',
42 '._,'
43 ),
44 'Alphanumerical characters are returned as is' => array(
45 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
46 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
47 ),
48 'Angel brackets and ampersand are encoded' => array(
49 '<>&',
50 '\\x3C\\x3E\\x26'
51 ),
52 'Quotes and slashes are encoded' => array(
53 '"\'\\/',
54 '\\x22\\x27\\x5C\\x2F'
55 ),
56 'Empty string stays empty' => array(
57 '',
58 ''
59 ),
60 'Exclamation mark and space are properly encoded' => array(
61 'Hello World!',
62 'Hello\\x20World\\x21'
63 ),
64 'Whitespaces are properly encoded' => array(
65 TAB . LF . CR . ' ',
66 '\\x09\\x0A\\x0D\\x20'
67 ),
68 'Null byte is properly encoded' => array(
69 chr(0),
70 '\\x00'
71 ),
72 'Umlauts are properly encoded' => array(
73 'ÜüÖöÄä',
74 '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
75 )
76 );
77 }
78
79 /**
80 * @test
81 * @param string $input
82 * @param string $expected
83 * @dataProvider encodeEncodesCorrectlyDataProvider
84 */
85 public function encodeEncodesCorrectly($input, $expected) {
86 $this->assertSame($expected, $this->subject->encode($input));
87 }
88
89 }