e9c0a75cf6683d20996e38f8af568dc5068053da
[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 roundTripCryptString
94 //////////////////////////////////////////
95
96 /**
97 * @test
98 */
99 public function roundTripCryptStringCreatesStringWithSameLengthAsInputString() {
100 $clearText = 'Hello world!';
101
102 $this->assertEquals(
103 strlen($clearText),
104 strlen($this->fixture->roundTripCryptString($clearText))
105 );
106 }
107
108 /**
109 * @test
110 */
111 public function roundTripCryptStringCreatesResultDifferentFromInputString() {
112 $clearText = 'Hello world!';
113
114 $this->assertNotEquals(
115 $clearText,
116 $this->fixture->roundTripCryptString($clearText)
117 );
118 }
119
120 /**
121 * @test
122 */
123 public function roundTripCryptStringAppliedTwoTimesReturnsOriginalString() {
124 $clearText = 'Hello world!';
125
126 $this->assertEquals(
127 $clearText,
128 $this->fixture->roundTripCryptString(
129 $this->fixture->roundTripCryptString($clearText)
130 )
131 );
132 }
133 }
134 ?>