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