[TASK] Remove unneeded backupGlobals from Unit Tests
[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 */
32 class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\Category\CategoryRegistry
36 */
37 protected $fixture;
38
39 /**
40 * @var array
41 */
42 protected $tables;
43
44 /**
45 * Sets up this test suite.
46 */
47 protected function setUp() {
48 $this->fixture = new \TYPO3\CMS\Core\Category\CategoryRegistry();
49 $this->tables = array(
50 'first' => uniqid('first'),
51 'second' => uniqid('second')
52 );
53 foreach ($this->tables as $tableName) {
54 $GLOBALS['TCA'][$tableName] = array('ctrl' => array());
55 }
56 }
57
58 /**
59 * Tears down this test suite.
60 */
61 protected function tearDown() {
62 unset($this->tables);
63 unset($this->fixture);
64 }
65
66 /**
67 * @test
68 */
69 public function isRegistryEmptyByDefault() {
70 $this->assertEquals(array(), $this->fixture->get());
71 }
72
73 /**
74 * @test
75 */
76 public function doesAddReturnTrueOnDefinedTable() {
77 $this->assertTrue($this->fixture->add('test_extension_a', $this->tables['first'], 'categories'));
78 }
79
80 /**
81 * @test
82 */
83 public function doesAddReturnFalseOnUndefinedTable() {
84 $this->assertFalse($this->fixture->add('test_extension_a', uniqid('undefined'), 'categories'));
85 }
86
87 /**
88 * @test
89 */
90 public function areMultipleElementsOfSameExtensionRegistered() {
91 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
92 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
93 $registry = $this->fixture->get();
94 ob_flush();
95 $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
96 $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
97 }
98
99 /**
100 * @test
101 */
102 public function areElementsOfDifferentExtensionsRegistered() {
103 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
104 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
105 $registry = $this->fixture->get();
106 $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
107 $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
108 }
109
110 /**
111 * @test
112 */
113 public function areElementsOnSameTableOverridden() {
114 $this->fixture->add('test_extension_a', $this->tables['first'], $this->tables['first']);
115 $this->fixture->add('test_extension_b', $this->tables['second'], $this->tables['second']);
116 $registry = $this->fixture->get();
117 $this->assertEquals($this->tables['first'], $registry['test_extension_a'][$this->tables['first']]);
118 }
119
120 /**
121 * @test
122 */
123 public function areDatabaseDefinitionsOfAllElementsAvailable() {
124 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
125 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
126 $this->fixture->add('test_extension_c', $this->tables['first'], 'categories');
127 $definitions = $this->fixture->getDatabaseTableDefinitions();
128 $matches = array();
129 preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
130 $this->assertEquals(2, count($matches[0]));
131 $this->assertEquals($matches[1][0], $this->tables['first']);
132 $this->assertEquals($matches[2][0], 'categories');
133 $this->assertEquals($matches[1][1], $this->tables['second']);
134 $this->assertEquals($matches[2][1], 'categories');
135 }
136
137 /**
138 * @test
139 */
140 public function areDatabaseDefinitionsOfParticularExtensionAvailable() {
141 $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
142 $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
143 $definitions = $this->fixture->getDatabaseTableDefinition('test_extension_a');
144 $matches = array();
145 preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
146 $this->assertEquals(1, count($matches[0]));
147 $this->assertEquals($matches[1][0], $this->tables['first']);
148 $this->assertEquals($matches[2][0], 'categories');
149 }
150
151 }
152
153 ?>