BUGFIX] Wrong renaming of DBAL dbPostgresqlTest
[Packages/TYPO3.CMS.git] / tests / Unit / t3lib / category / RegistryTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
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 * Testcase for t3lib_category_Registry
26 *
27 * @package TYPO3
28 * @subpackage t3lib
29 * @author Oliver Hader <oliver.hader@typo3.org>
30 */
31 class t3lib_category_RegistryTest extends Tx_Phpunit_TestCase {
32
33 /**
34 * Enable backup of global and system variables
35 *
36 * @var boolean
37 */
38 protected $backupGlobals = TRUE;
39
40 /**
41 * @var \TYPO3\CMS\Core\Category\CategoryRegistry
42 */
43 protected $fixture;
44
45 /**
46 * @var array
47 */
48 protected $tables;
49
50 /**
51 * Sets up this test suite.
52 */
53 protected function setUp() {
54 $this->fixture = new \TYPO3\CMS\Core\Category\CategoryRegistry();
55 $this->tables = array(
56 'first' => uniqid('first'),
57 'second' => uniqid('second')
58 );
59 foreach ($this->tables as $tableName) {
60 $GLOBALS['TCA'][$tableName] = array('ctrl' => array());
61 }
62 }
63
64 /**
65 * Tears down this test suite.
66 */
67 protected function tearDown() {
68 unset($this->tables);
69 unset($this->fixture);
70 }
71
72 /**
73 * @test
74 */
75 public function isRegistryEmptyByDefault() {
76 $this->assertEquals(array(), $this->fixture->get());
77 }
78
79 /**
80 * @test
81 */
82 public function doesAddReturnTrueOnDefinedTable() {
83 $this->assertTrue($this->fixture->add('test_extension_a', $this->tables['first'], 'categories'));
84 }
85
86 /**
87 * @test
88 */
89 public function doesAddReturnFalseOnUndefinedTable() {
90 $this->assertFalse($this->fixture->add('test_extension_a', uniqid('undefined'), 'categories'));
91 }
92
93 /**
94 * @test
95 */
96 public function areMultipleElementsOfSameExtensionRegistered() {
97 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
98 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
99 $registry = $this->fixture->get();
100 ob_flush();
101 $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
102 $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
103 }
104
105 /**
106 * @test
107 */
108 public function areElementsOfDifferentExtensionsRegistered() {
109 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
110 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
111 $registry = $this->fixture->get();
112 $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
113 $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
114 }
115
116 /**
117 * @test
118 */
119 public function areElementsOnSameTableOverridden() {
120 $this->fixture->add('test_extension_a', $this->tables['first'], $this->tables['first']);
121 $this->fixture->add('test_extension_b', $this->tables['second'], $this->tables['second']);
122 $registry = $this->fixture->get();
123 $this->assertEquals($this->tables['first'], $registry['test_extension_a'][$this->tables['first']]);
124 }
125
126 /**
127 * @test
128 */
129 public function areDatabaseDefinitionsOfAllElementsAvailable() {
130 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
131 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
132 $this->fixture->add('test_extension_c', $this->tables['first'], 'categories');
133 $definitions = $this->fixture->getDatabaseTableDefinitions();
134 $matches = array();
135 preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
136 $this->assertEquals(2, count($matches[0]));
137 $this->assertEquals($matches[1][0], $this->tables['first']);
138 $this->assertEquals($matches[2][0], 'categories');
139 $this->assertEquals($matches[1][1], $this->tables['second']);
140 $this->assertEquals($matches[2][1], 'categories');
141 }
142
143 /**
144 * @test
145 */
146 public function areDatabaseDefinitionsOfParticularExtensionAvailable() {
147 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
148 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
149 $definitions = $this->fixture->getDatabaseTableDefinition('test_extension_a');
150 $matches = array();
151 preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
152 $this->assertEquals(1, count($matches[0]));
153 $this->assertEquals($matches[1][0], $this->tables['first']);
154 $this->assertEquals($matches[2][0], 'categories');
155 }
156
157 }
158
159 ?>