Fixed Bug: #10283: Cleanup: Make unit test names more readable by adding underscores...
[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 t3lib_TCEmain
40 */
41 private $fixture;
42
43 /**
44 * @var t3lib_beUserAuth a simulated logged-in back-end user
45 */
46 private $backEndUser;
47
48 public function setUp() {
49 $this->backEndUser = $this->createBackEndUser();
50
51 $this->fixture = new t3lib_TCEmain();
52 $this->fixture->start(array(), '', $this->backEndUser);
53 }
54
55 public function tearDown() {
56 unset(
57 $this->fixture->BE_USER, $this->fixture, $this->backEndUser
58 );
59 }
60
61
62 //////////////////////
63 // Utility functions
64 //////////////////////
65
66 /**
67 * Creates a back-end user.
68 *
69 * @return t3lib_beUserAuth a back-end user
70 */
71 private function createBackEndUser() {
72 $user = new t3lib_beUserAuth();
73 $user->user = array();
74
75 return $user;
76 }
77
78
79 ////////////////////////////////////
80 // Tests for the utility functions
81 ////////////////////////////////////
82
83 /**
84 * @test
85 */
86 public function createBackEndUserCreatesBeUserAuthInstance() {
87 $this->assertTrue(
88 $this->createBackEndUser() instanceof t3lib_beUserAuth
89 );
90 }
91
92
93 //////////////////////////////////////
94 // Tests for the basic functionality
95 //////////////////////////////////////
96
97 /**
98 * @test
99 */
100 public function fixtureCanBeCreated() {
101 $this->assertTrue(
102 $this->fixture instanceof t3lib_TCEmain
103 );
104 }
105
106
107 //////////////////////////////////////////
108 // Test concerning checkModifyAccessList
109 //////////////////////////////////////////
110
111 /**
112 * @test
113 */
114 public function adminIsAllowedToModifyNonAdminTable() {
115 $this->fixture->admin = true;
116
117 $this->assertTrue(
118 $this->fixture->checkModifyAccessList('tt_content')
119 );
120 }
121
122 /**
123 * @test
124 */
125 public function nonAdminIsNorAllowedToModifyNonAdminTable() {
126 $this->fixture->admin = false;
127
128 $this->assertFalse(
129 $this->fixture->checkModifyAccessList('tt_content')
130 );
131 }
132
133 /**
134 * @test
135 */
136 public function nonAdminWithTableModifyAccessIsAllowedToModifyNonAdminTable() {
137 $this->fixture->admin = false;
138 $this->backEndUser->groupData['tables_modify'] = 'tt_content';
139
140 $this->assertTrue(
141 $this->fixture->checkModifyAccessList('tt_content')
142 );
143 }
144
145 /**
146 * @test
147 */
148 public function adminIsAllowedToModifyAdminTable() {
149 $this->fixture->admin = true;
150
151 $this->assertTrue(
152 $this->fixture->checkModifyAccessList('be_users')
153 );
154 }
155
156 /**
157 * @test
158 */
159 public function nonAdminIsNotAllowedToModifyAdminTable() {
160 $this->fixture->admin = false;
161
162 $this->assertFalse(
163 $this->fixture->checkModifyAccessList('be_users')
164 );
165 }
166
167 /**
168 * @test
169 */
170 public function nonAdminWithTableModifyAccessIsNotAllowedToModifyAdminTable() {
171 $this->fixture->admin = false;
172 $this->backEndUser->groupData['tables_modify'] = 'be_users';
173
174 $this->assertFalse(
175 $this->fixture->checkModifyAccessList('be_users')
176 );
177 }
178 }
179 ?>