[BUGFIX] Empty text with non-localizable label key
[Packages/TYPO3.CMS.git] / tests / typo3 / sysext / cms / tslib / class.tslib_feTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Oliver Klee (typo3-coding@oliverklee.de)
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 /**
26 * Testcase for the "tslib_fe" class in the TYPO3 Core.
27 *
28 * @package TYPO3
29 * @subpackage tslib
30 *
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 */
33 class tslib_feTest extends tx_phpunit_testcase {
34 /**
35 * @var tslib_fe
36 */
37 private $fixture;
38
39 public function setUp() {
40 // This creates an instance of the class without calling the
41 // original constructor.
42 $className = uniqid('tslib_fe');
43 eval(
44 'class ' . $className . ' extends tslib_fe {' .
45 'public function ' . $className . '() {}' .
46 'public function roundTripCryptString($string) {' .
47 'return parent::roundTripCryptString($string);' .
48 '}' .
49 '}'
50 );
51
52 $this->fixture = new $className();
53 $this->fixture->TYPO3_CONF_VARS = $GLOBALS['TYPO3_CONF_VARS'];
54 $this->fixture->TYPO3_CONF_VARS['SYS']['encryptionKey']
55 = '170928423746123078941623042360abceb12341234231';
56 }
57
58 public function tearDown() {
59 unset($this->fixture);
60 }
61
62
63 ////////////////////////////////
64 // Tests concerning codeString
65 ////////////////////////////////
66
67 /**
68 * @test
69 */
70 public function codeStringForNonEmptyStringReturns10CharacterHashAndCodedString() {
71 $this->assertRegExp(
72 '/^[0-9a-f]{10}:[a-zA-Z0-9+=\/]+$/',
73 $this->fixture->codeString('Hello world!')
74 );
75 }
76
77 /**
78 * @test
79 */
80 public function decodingCodedStringReturnsOriginalString() {
81 $clearText = 'Hello world!';
82
83 $this->assertEquals(
84 $clearText,
85 $this->fixture->codeString(
86 $this->fixture->codeString($clearText), TRUE
87 )
88 );
89 }
90
91
92 //////////////////////
93 // Tests concerning sL
94 //////////////////////
95
96 /**
97 * @test
98 */
99 public function localizationReturnsUnchangedStringIfNotLocallangLabel() {
100 $string = uniqid();
101 $this->assertEquals($string, $this->fixture->sL($string));
102 }
103
104
105 //////////////////////////////////////////
106 // Tests concerning roundTripCryptString
107 //////////////////////////////////////////
108
109 /**
110 * @test
111 */
112 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
113 $clearText = 'Hello world!';
114
115 $this->assertEquals(
116 strlen($clearText),
117 strlen($this->fixture->roundTripCryptString($clearText))
118 );
119 }
120
121 /**
122 * @test
123 */
124 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
125 $clearText = 'Hello world!';
126
127 $this->assertNotEquals(
128 $clearText,
129 $this->fixture->roundTripCryptString($clearText)
130 );
131 }
132
133 /**
134 * @test
135 */
136 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
137 $clearText = 'Hello world!';
138
139 $this->assertEquals(
140 $clearText,
141 $this->fixture->roundTripCryptString(
142 $this->fixture->roundTripCryptString($clearText)
143 )
144 );
145 }
146 }
147 ?>