Fixed #11206: Cleaned up test "t3lib_extmgm_testcase" (Thanks to Oliver Klee)
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_tcemain_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 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 require_once(PATH_t3lib . 'class.t3lib_beuserauth.php');
26
27 require_once(PATH_t3lib . 'class.t3lib_tcemain.php');
28
29 /**
30 * Testcase for the t3lib_TCEmain class in the TYPO3 core.
31 *
32 * @package TYPO3
33 * @subpackage t3lib
34 *
35 * @author Oliver Klee <typo3-coding@oliverklee.de>
36 */
37 class t3lib_tcemain_testcase extends tx_phpunit_testcase {
38 /**
39 * @var boolean
40 */
41 protected $backupGlobals = true;
42
43 /**
44 * @var t3lib_TCEmain
45 */
46 private $fixture;
47
48 /**
49 * @var t3lib_beUserAuth a mock logged-in back-end user
50 */
51 private $backEndUser;
52
53 public function setUp() {
54 $this->backEndUser = $this->getMock('t3lib_beUserAuth');
55
56 $this->fixture = new t3lib_TCEmain();
57 $this->fixture->start(array(), '', $this->backEndUser);
58 }
59
60 public function tearDown() {
61 unset(
62 $this->fixture->BE_USER, $this->fixture, $this->backEndUser
63 );
64 }
65
66
67 //////////////////////////////////////
68 // Tests for the basic functionality
69 //////////////////////////////////////
70
71 /**
72 * @test
73 */
74 public function fixtureCanBeCreated() {
75 $this->assertTrue(
76 $this->fixture instanceof t3lib_TCEmain
77 );
78 }
79
80
81 //////////////////////////////////////////
82 // Test concerning checkModifyAccessList
83 //////////////////////////////////////////
84
85 /**
86 * @test
87 */
88 public function adminIsAllowedToModifyNonAdminTable() {
89 $this->fixture->admin = true;
90
91 $this->assertTrue(
92 $this->fixture->checkModifyAccessList('tt_content')
93 );
94 }
95
96 /**
97 * @test
98 */
99 public function nonAdminIsNorAllowedToModifyNonAdminTable() {
100 $this->fixture->admin = false;
101
102 $this->assertFalse(
103 $this->fixture->checkModifyAccessList('tt_content')
104 );
105 }
106
107 /**
108 * @test
109 */
110 public function nonAdminWithTableModifyAccessIsAllowedToModifyNonAdminTable() {
111 $this->fixture->admin = false;
112 $this->backEndUser->groupData['tables_modify'] = 'tt_content';
113
114 $this->assertTrue(
115 $this->fixture->checkModifyAccessList('tt_content')
116 );
117 }
118
119 /**
120 * @test
121 */
122 public function adminIsAllowedToModifyAdminTable() {
123 $this->fixture->admin = true;
124
125 $this->assertTrue(
126 $this->fixture->checkModifyAccessList('be_users')
127 );
128 }
129
130 /**
131 * @test
132 */
133 public function nonAdminIsNotAllowedToModifyAdminTable() {
134 $this->fixture->admin = false;
135
136 $this->assertFalse(
137 $this->fixture->checkModifyAccessList('be_users')
138 );
139 }
140
141 /**
142 * @test
143 */
144 public function nonAdminWithTableModifyAccessIsNotAllowedToModifyAdminTable() {
145 $this->fixture->admin = false;
146 $this->backEndUser->groupData['tables_modify'] = 'be_users';
147
148 $this->assertFalse(
149 $this->fixture->checkModifyAccessList('be_users')
150 );
151 }
152
153 /**
154 * @test
155 */
156 public function evalCheckValueDouble2() {
157 $testData = array (
158 '-0,5' => '-0.50',
159 '1000' => '1000.00',
160 '1000,10' => '1000.10',
161 '1000,0' => '1000.00',
162 '600.000.000,00' => '600000000.00',
163 '60aaa00' => '6000.00',
164 );
165 foreach ($testData as $value => $expectedReturnValue){
166 $returnValue = $this->fixture->checkValue_input_Eval($value, array('double2'), '');
167 $this->assertSame(
168 $returnValue['value'],
169 $expectedReturnValue
170 );
171 }
172 }
173
174
175 ///////////////////////////////////////////
176 // Tests concerning checkModifyAccessList
177 ///////////////////////////////////////////
178
179 /**
180 * Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception.
181 * @test
182 * @expectedException UnexpectedValueException
183 * @see t3lib_TCEmain::checkModifyAccessList()
184 */
185 public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() {
186 $hookClass = uniqid('tx_coretest');
187 eval('class ' . $hookClass . ' {}');
188
189 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
190
191 $this->fixture->checkModifyAccessList('tt_content');
192 }
193
194 /**
195 * Tests whether the 'checkModifyAccessList' hook is called correctly.
196 * @test
197 * @see t3lib_TCEmain::checkModifyAccessList()
198 */
199 public function doesCheckModifyAccessListHookGetsCalled() {
200 $hookClass = uniqid('tx_coretest');
201 $hookMock = $this->getMock(
202 't3lib_TCEmain_checkModifyAccessListHook',
203 array('checkModifyAccessList'),
204 array(),
205 $hookClass
206 );
207 $hookMock->expects($this->once())->method('checkModifyAccessList');
208
209 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
210 $GLOBALS['T3_VAR']['getUserObj'][$hookClass] = $hookMock;
211
212 $this->fixture->checkModifyAccessList('tt_content');
213 }
214
215 /**
216 * Tests whether the 'checkModifyAccessList' hook modifies the $accessAllowed variable.
217 * @test
218 * @see t3lib_TCEmain::checkModifyAccessList()
219 */
220 public function doesCheckModifyAccessListHookModifyAccessAllowed() {
221 $hookClass = uniqid('tx_coretest');
222 eval('
223 class ' . $hookClass . ' implements t3lib_TCEmain_checkModifyAccessListHook {
224 public function checkModifyAccessList(&$accessAllowed, $table, t3lib_TCEmain $parent) { $accessAllowed = true; }
225 }
226 ');
227
228 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'][] = $hookClass;
229
230 $this->assertTrue($this->fixture->checkModifyAccessList('tt_content'));
231 }
232 }
233 ?>