[BUGFIX] remove enableFields for sys_file_processedfile
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Category / CategoryRegistryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Category;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Oliver Hader <oliver.hader@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for CategoryRegistry
29 *
30 * @author Oliver Hader <oliver.hader@typo3.org>
31 * @author Fabien Udriot <fabien.udriot@typo3.org>
32 */
33 class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
34
35 /**
36 * @var \TYPO3\CMS\Core\Category\CategoryRegistry
37 */
38 protected $subject;
39
40 /**
41 * @var array
42 */
43 protected $tables;
44
45 /**
46 * Sets up this test suite.
47 */
48 protected function setUp() {
49 $this->subject = new \TYPO3\CMS\Core\Category\CategoryRegistry();
50 $this->tables = array(
51 'first' => uniqid('first'),
52 'second' => uniqid('second')
53 );
54 foreach ($this->tables as $tableName) {
55 $GLOBALS['TCA'][$tableName] = array(
56 'ctrl' => array(),
57 'columns' => array(),
58 'types' => array(
59 '1' => array()
60 ),
61 );
62 }
63 }
64
65 /**
66 * @test
67 */
68 public function doesAddReturnTrueOnDefinedTable() {
69 $this->assertTrue($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
70 }
71
72 /**
73 * @test
74 * @expectedException \InvalidArgumentException
75 * @expectedExceptionCode 1369122038
76 */
77 public function doesAddThrowExceptionOnEmptyTablename() {
78 $this->subject->add('test_extension_a', '', 'categories');
79 }
80
81 /**
82 * @test
83 */
84 public function areMultipleElementsOfSameExtensionRegistered() {
85 $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
86 $this->subject->add('test_extension_a', $this->tables['second'], 'categories');
87 $this->subject->applyTca();
88
89 $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
90 $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
91 }
92
93 /**
94 * @test
95 */
96 public function areElementsOfDifferentExtensionsRegistered() {
97 $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
98 $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
99 $this->subject->applyTca();
100
101 $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
102 $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
103 }
104
105 /**
106 * @test
107 */
108 public function areElementsOfDifferentExtensionsOnSameTableRegistered() {
109 $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
110 $this->subject->add('test_extension_b', $this->tables['first'], 'categories2');
111 $this->subject->applyTca();
112
113 $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
114 $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
115 }
116
117 /**
118 * @test
119 */
120 public function areElementsOfSameExtensionOnSameTableRegistered() {
121 $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
122 $this->subject->add('test_extension_a', $this->tables['first'], 'categories2');
123 $this->subject->applyTca();
124
125 $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
126 $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
127 }
128
129 /**
130 * @test
131 */
132 public function areDatabaseDefinitionsOfAllElementsAvailable() {
133 $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
134 $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
135 $this->subject->add('test_extension_c', $this->tables['first'], 'categories');
136 $definitions = $this->subject->getDatabaseTableDefinitions();
137 $matches = array();
138 preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
139 $this->assertEquals(2, count($matches[0]));
140 $this->assertEquals($matches[1][0], $this->tables['first']);
141 $this->assertEquals($matches[2][0], 'categories');
142 $this->assertEquals($matches[1][1], $this->tables['second']);
143 $this->assertEquals($matches[2][1], 'categories');
144 }
145
146 /**
147 * @test
148 */
149 public function areDatabaseDefinitionsOfParticularExtensionAvailable() {
150 $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
151 $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
152 $definitions = $this->subject->getDatabaseTableDefinition('test_extension_a');
153 $matches = array();
154 preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
155 $this->assertEquals(1, count($matches[0]));
156 $this->assertEquals($matches[1][0], $this->tables['first']);
157 $this->assertEquals($matches[2][0], 'categories');
158 }
159
160 /**
161 * @test
162 */
163 public function areDefaultCategorizedTablesLoaded() {
164 $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = $this->tables['first'] . ',' . $this->tables['second'];
165 $this->subject->applyTca();
166
167 $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
168 $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
169 }
170
171 /**
172 * @test
173 */
174 public function canApplyTca() {
175 $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
176 $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
177 $this->subject->applyTca();
178
179 $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['first']]['columns']['categories']);
180 $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['second']]['columns']['categories']);
181 }
182
183 /**
184 * @test
185 */
186 public function isRegisteredReturnsTrueIfElementIsAlreadyRegistered() {
187 $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
188 $this->assertTrue($this->subject->isRegistered($this->tables['first'], 'categories'));
189 }
190
191 /**
192 * @test
193 */
194 public function isRegisteredReturnsFalseIfElementIsNotRegistered() {
195 $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
196 $this->assertFalse($this->subject->isRegistered($this->tables['first'], '_not_registered'));
197 $this->assertFalse($this->subject->isRegistered($this->tables['second'], 'categories'));
198 }
199
200 /**
201 * @test
202 */
203 public function tabIsAddedForElement() {
204 $this->subject->add('text_extension_a', $this->tables['first']);
205 $this->subject->applyTca();
206
207 foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
208 $this->assertContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
209 }
210 }
211
212 /**
213 * @test
214 */
215 public function tabIsNotAddedForElementIfFieldListIsSpecified() {
216 $this->subject->add('text_extension_a', $this->tables['first'], 'categories', array('fieldList' => 'categories'));
217 $this->subject->applyTca();
218
219 foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
220 $this->assertNotContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
221 }
222 }
223
224 /**
225 * @test
226 */
227 public function tabIsAddedOnlyOncePerTable() {
228 $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
229 $this->subject->add('text_extension_a', $this->tables['first'], 'categories2');
230 $this->subject->applyTca();
231
232 foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
233 $this->assertSame(
234 1, substr_count($typeConfig['showitem'], '--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category')
235 );
236 }
237
238 }
239
240 }