Convert DOS to Unix linebreaks
[Packages/TYPO3.CMS.git] / typo3 / tests / 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 public function testCreateBackEndUserCreatesBeUserAuthInstance() {
84 $this->assertTrue(
85 $this->createBackEndUser() instanceof t3lib_beUserAuth
86 );
87 }
88
89
90 //////////////////////////////////////
91 // Tests for the basic functionality
92 //////////////////////////////////////
93
94 public function testFixtureCanBeCreated() {
95 $this->assertTrue(
96 $this->fixture instanceof t3lib_TCEmain
97 );
98 }
99
100
101 //////////////////////////////////////////
102 // Test concerning checkModifyAccessList
103 //////////////////////////////////////////
104
105 public function testCheckModifyAccessListForAdminForContentTableReturnsTrue() {
106 $this->fixture->admin = true;
107
108 $this->assertTrue(
109 $this->fixture->checkModifyAccessList('tt_content')
110 );
111 }
112
113 public function testCheckModifyAccessListForNonAdminForContentTableReturnsFalse() {
114 $this->fixture->admin = false;
115
116 $this->assertFalse(
117 $this->fixture->checkModifyAccessList('tt_content')
118 );
119 }
120
121 public function testCheckModifyAccessListForNonAdminWithTableModifyAccessForContentTableReturnsTrue() {
122 $this->fixture->admin = false;
123 $this->backEndUser->groupData['tables_modify'] = 'tt_content';
124
125 $this->assertTrue(
126 $this->fixture->checkModifyAccessList('tt_content')
127 );
128 }
129
130 public function testCheckModifyAccessListForAdminForBeUsersTableReturnsTrue() {
131 $this->fixture->admin = true;
132
133 $this->assertTrue(
134 $this->fixture->checkModifyAccessList('be_users')
135 );
136 }
137
138 public function testCheckModifyAccessListForNonAdminForBeUsersTableReturnsFalse() {
139 $this->fixture->admin = false;
140
141 $this->assertFalse(
142 $this->fixture->checkModifyAccessList('be_users')
143 );
144 }
145
146 public function testCheckModifyAccessListForNonAdminWithTableModifyAccessForBeUsersTableReturnsFalse() {
147 $this->fixture->admin = false;
148 $this->backEndUser->groupData['tables_modify'] = 'be_users';
149
150 $this->assertFalse(
151 $this->fixture->checkModifyAccessList('be_users')
152 );
153 }
154 }
155 ?>