TYPO3 CMS  TYPO3_6-2
CategoryRegistryTest.php
Go to the documentation of this file.
1 <?php
3 
24 
28  protected $subject;
29 
33  protected $tables;
34 
38  protected function setUp() {
39  $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = 'pages';
40  $GLOBALS['TCA']['pages']['columns'] = array();
41  $this->subject = new \TYPO3\CMS\Core\Category\CategoryRegistry();
42  $this->tables = array(
43  'first' => $this->getUniqueId('first'),
44  'second' => $this->getUniqueId('second')
45  );
46  foreach ($this->tables as $tableName) {
47  $GLOBALS['TCA'][$tableName] = array(
48  'ctrl' => array(),
49  'columns' => array(),
50  'types' => array(
51  '1' => array(
52  'showitem' => ''
53  )
54  ),
55  );
56  }
57  }
58 
62  public function doesAddReturnTrueOnDefinedTable() {
63  $this->assertTrue($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
64  }
65 
70  $this->assertTrue($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
71  $this->assertFalse($this->subject->add('test_extension_a', $this->tables['first'], 'categories'));
72  }
73 
80  $this->subject->add('test_extension_a', '', 'categories');
81  }
82 
89  $this->subject->add('', 'foo', 'categories');
90  }
91 
98  $this->subject->add('test_extension_a', array(), 'categories');
99  }
100 
107  $this->subject->add(array(), 'foo', 'categories');
108  }
109 
114  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
115  $this->subject->add('test_extension_a', $this->tables['second'], 'categories');
116  $this->subject->applyTcaForPreRegisteredTables();
117 
118  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
119  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
120  }
121 
126  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
127  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
128  $this->subject->applyTcaForPreRegisteredTables();
129 
130  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
131  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
132  }
133 
138  $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
139  $this->subject->add('test_extension_b', $this->tables['first'], 'categories2');
140  $this->subject->applyTcaForPreRegisteredTables();
141 
142  $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
143  $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
144  }
145 
150  $this->subject->add('test_extension_a', $this->tables['first'], 'categories1');
151  $this->subject->add('test_extension_a', $this->tables['first'], 'categories2');
152  $this->subject->applyTcaForPreRegisteredTables();
153 
154  $this->assertArrayHasKey('categories1', $GLOBALS['TCA'][$this->tables['first']]['columns']);
155  $this->assertArrayHasKey('categories2', $GLOBALS['TCA'][$this->tables['first']]['columns']);
156  }
157 
162  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
163  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
164  $this->subject->add('test_extension_c', $this->tables['first'], 'categories');
165  $definitions = $this->subject->getDatabaseTableDefinitions();
166  $matches = array();
167  preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
168  $this->assertEquals(2, count($matches[0]));
169  $this->assertEquals($matches[1][0], $this->tables['first']);
170  $this->assertEquals($matches[2][0], 'categories');
171  $this->assertEquals($matches[1][1], $this->tables['second']);
172  $this->assertEquals($matches[2][1], 'categories');
173  }
174 
179  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
180  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
181  $definitions = $this->subject->getDatabaseTableDefinition('test_extension_a');
182  $matches = array();
183  preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
184  $this->assertEquals(1, count($matches[0]));
185  $this->assertEquals($matches[1][0], $this->tables['first']);
186  $this->assertEquals($matches[2][0], 'categories');
187  }
188 
193  $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = $this->tables['first'] . ',' . $this->tables['second'];
194  $this->subject->applyTcaForPreRegisteredTables();
195 
196  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['first']]['columns']);
197  $this->assertArrayHasKey('categories', $GLOBALS['TCA'][$this->tables['second']]['columns']);
198  }
199 
203  public function canApplyTca() {
204  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
205  $this->subject->add('test_extension_b', $this->tables['second'], 'categories');
206  $this->subject->applyTcaForPreRegisteredTables();
207 
208  $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['first']]['columns']['categories']);
209  $this->assertNotEmpty($GLOBALS['TCA'][$this->tables['second']]['columns']['categories']);
210  }
211 
216  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
217  $this->assertTrue($this->subject->isRegistered($this->tables['first'], 'categories'));
218  }
219 
224  $this->subject->add('test_extension_a', $this->tables['first'], 'categories');
225  $this->assertFalse($this->subject->isRegistered($this->tables['first'], '_not_registered'));
226  $this->assertFalse($this->subject->isRegistered($this->tables['second'], 'categories'));
227  }
228 
232  public function tabIsAddedForElement() {
233  $this->subject->add('text_extension_a', $this->tables['first']);
234  $this->subject->applyTcaForPreRegisteredTables();
235 
236  foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
237  $this->assertContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
238  }
239  }
240 
245  $this->subject->add('text_extension_a', $this->tables['first'], 'categories', array('fieldList' => 'categories'));
246  $this->subject->applyTcaForPreRegisteredTables();
247 
248  foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
249  $this->assertNotContains('--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category', $typeConfig['showitem']);
250  }
251  }
252 
256  public function tabIsAddedOnlyOncePerTable() {
257  $this->subject->add('text_extension_a', $this->tables['first'], 'categories1');
258  $this->subject->add('text_extension_a', $this->tables['first'], 'categories2');
259  $this->subject->applyTcaForPreRegisteredTables();
260 
261  foreach($GLOBALS['TCA'][$this->tables['first']]['types'] as $typeConfig) {
262  $this->assertSame(
263  1, substr_count($typeConfig['showitem'], '--div--;LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category')
264  );
265  }
266 
267  }
268 
269 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]