TYPO3 CMS  TYPO3_7-6
CategoryRegistryTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  protected $subject;
26 
30  protected $tables;
31 
35  protected function setUp()
36  {
37  $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = 'pages';
38  $GLOBALS['TCA']['pages']['columns'] = [];
39  $this->subject = new \TYPO3\CMS\Core\Category\CategoryRegistry();
40  $this->tables = [
41  'first' => $this->getUniqueId('first'),
42  'second' => $this->getUniqueId('second')
43  ];
44  foreach ($this->tables as $tableName) {
45  $GLOBALS['TCA'][$tableName] = [
46  'ctrl' => [],
47  'columns' => [],
48  'types' => [
49  '0' => [
50  'showitem' => ''
51  ],
52  '1' => [
53  'showitem' => ''
54  ]
55  ],
56  ];
57  }
58  }
59 
64  {
65  $this->assertTrue($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
66  }
67 
72  {
73  $this->assertTrue($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
74  $this->assertFalse($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
75  }
76 
83  {
84  $this->subject->add('test_extension_a', '', 'categories');
85  }
86 
93  {
94  $this->subject->add('', 'foo', 'categories');
95  }
96 
103  {
104  $this->subject->add('test_extension_a', [], 'categories');
105  }
106 
113  {
114  $this->subject->add([], 'foo', 'categories');
115  }
116 
121  {
122  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
123  $this->subject->add('test_extension_a', $this->tables['second'], 'categories');
124  $this->subject->applyTcaForPreRegisteredTables();
125 
126  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
127  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
128  }
129 
134  {
135  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
136  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
137  $this->subject->applyTcaForPreRegisteredTables();
138 
139  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
140  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
141  }
142 
147  {
148  $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
149  $this->subject->add('test_extension_b', $this->tables['first'], 'categories2');
150  $this->subject->applyTcaForPreRegisteredTables();
151 
152  $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
153  $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
154  }
155 
160  {
161  $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
162  $this->subject->add('test_extension_a', $this->tables['first'], 'categories2');
163  $this->subject->applyTcaForPreRegisteredTables();
164 
165  $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
166  $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
167  }
168 
173  {
174  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
175  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
176  $this->subject->add('test_extension_c', $this->tables['first'], 'categories');
177  $definitions = $this->subject->getDatabaseTableDefinitions();
178  $matches = [];
179  preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
180  $this->assertEquals(2, count($matches[0]));
181  $this->assertEquals($matches[1][0], $this->tables['first']);
182  $this->assertEquals($matches[2][0], 'categories');
183  $this->assertEquals($matches[1][1], $this->tables['second']);
184  $this->assertEquals($matches[2][1], 'categories');
185  }
186 
191  {
192  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
193  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
194  $definitions = $this->subject->getDatabaseTableDefinition('test_extension_a');
195  $matches = [];
196  preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
197  $this->assertEquals(1, count($matches[0]));
198  $this->assertEquals($matches[1][0], $this->tables['first']);
199  $this->assertEquals($matches[2][0], 'categories');
200  }
201 
206  {
207  $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = $this->tables['first'] . ',' . $this->tables['second'];
208  $this->subject->applyTcaForPreRegisteredTables();
209 
210  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
211  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
212  }
213 
217  public function canApplyTca()
218  {
219  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
220  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
221  $this->subject->applyTcaForPreRegisteredTables();
222 
223  $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['first']]['columns']['categories']);
224  $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['second']]['columns']['categories']);
225  }
226 
231  {
232  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
233  $this->assertTrue($this->subject->isRegistered($this->tables['first'], 'categories'));
234  }
235 
240  {
241  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
242  $this->assertFalse($this->subject->isRegistered($this->tables['first'], '_not_registered'));
243  $this->assertFalse($this->subject->isRegistered($this->tables['second'], 'categories'));
244  }
245 
249  public function tabIsAddedForElement()
250  {
251  $this->subject->add('text_extension_a', $this->tables['first']);
252  $this->subject->applyTcaForPreRegisteredTables();
253 
254  foreach ($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
255  $this->assertContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
256  }
257  }
258 
263  {
264  $this->subject->add('text_extension_a', $this->tables['first'], 'categories', ['fieldList' => 'categories']);
265  $this->subject->applyTcaForPreRegisteredTables();
266 
267  foreach ($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
268  $this->assertNotContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
269  }
270  }
271 
276  {
277  $this->subject->add('text_extension_a', $this->tables['first'], 'categories', ['typesList' => '0']);
278  $this->subject->applyTcaForPreRegisteredTables();
279  $this->assertSame('', $GLOBALS['TCA'][$this->tables['first']]['types'][1]['showitem']);
280  }
281 
285  public function tabIsAddedOnlyOncePerTable()
286  {
287  $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
288  $this->subject->add('text_extension_a', $this->tables['first'], 'categories2');
289  $this->subject->applyTcaForPreRegisteredTables();
290 
291  foreach ($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
292  $this->assertSame(
293  1, substr_count($typeConfig['showitem'], '--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category')
294  );
295  }
296  }
297 
302  {
303  $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
304  $result = $this->subject->add('text_extension_a', $this->tables['first'], 'categories1', [], true);
305  $this->assertTrue($result);
306  }
307 
311  public function addInitializesMissingTypes()
312  {
313  $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
314  $GLOBALS['TCA'][$this->tables['first']]['types']['newtypeafterfirstadd'] = ['showitem' => ''];
315  $this->subject->add('text_extension_a', $this->tables['first'], 'categories1', [], true);
316  $this->assertSame(
317  1, substr_count($GLOBALS['TCA'][$this->tables['first']]['types']['newtypeafterfirstadd']['showitem'], '--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category')
318  );
319  }
320 
324  public function addAddsOnlyOneSqlString()
325  {
326  $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
327  $this->subject->add('text_extension_b', $this->tables['first'], 'categories1', [], true);
328  $sqlData = $this->subject->addExtensionCategoryDatabaseSchemaToTablesDefinition([], 'text_extension_a');
329  $this->assertEmpty($sqlData['sqlString'][0]);
330  }
331 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']