[TASK] Namespace and move t3lib unit tests - 3
[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 * Copyright notice
6 *
7 * (c) 2012 Helmut Hummel <helmut.hummel@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Test cases for TYPO3\CMS\Core\Encoder\JavaScriptEncoder.
29 *
30 * @package TYPO3
31 * @subpackage t3lib
32 * @author Helmut Hummel <helmut.hummel@typo3.org>
33 */
34 class JavaScriptEncoderTest extends \Tx_Phpunit_TestCase {
35
36 /**
37 * @var \TYPO3\CMS\Core\Encoder\JavaScriptEncoder
38 */
39 protected $fixture = NULL;
40
41 public function setUp() {
42 $this->fixture = new \TYPO3\CMS\Core\Encoder\JavaScriptEncoder();
43 }
44
45 public function tearDown() {
46 unset($this->fixture);
47 }
48
49 /**
50 * Data provider for encodeEncodesCorrectly.
51 *
52 * @return array
53 */
54 public function encodeEncodesCorrectlyDataProvider() {
55 return array(
56 'Immune characters are returned as is' => array(
57 '._,',
58 '._,'
59 ),
60 'Alphanumerical characters are returned as is' => array(
61 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
62 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
63 ),
64 'Angel brackets and ampersand are encoded' => array(
65 '<>&',
66 '\\x3C\\x3E\\x26'
67 ),
68 'Quotes and slashes are encoded' => array(
69 '"\'\\/',
70 '\\x22\\x27\\x5C\\x2F'
71 ),
72 'Empty string stays empty' => array(
73 '',
74 ''
75 ),
76 'Exclamation mark and space are properly encoded' => array(
77 'Hello World!',
78 'Hello\\x20World\\x21'
79 ),
80 'Whitespaces are properly encoded' => array(
81 ((TAB . LF) . CR) . ' ',
82 '\\x09\\x0A\\x0D\\x20'
83 ),
84 'Null byte is properly encoded' => array(
85 chr(0),
86 '\\x00'
87 ),
88 'Umlauts are properly encoded' => array(
89 'ÜüÖöÄä',
90 '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
91 )
92 );
93 }
94
95 /**
96 * @test
97 * @param string $input
98 * @param string $expected
99 * @dataProvider encodeEncodesCorrectlyDataProvider
100 */
101 public function encodeEncodesCorrectly($input, $expected) {
102 $this->assertSame($expected, $this->fixture->encode($input));
103 }
104
105 }
106
107 ?>