[TASK] Clean up MetaTagManager API
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / MetaTag / MetaTagManagerRegistryTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\MetaTag;
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
17 use TYPO3\CMS\Core\MetaTag\GenericMetaTagManager;
18 use TYPO3\CMS\Core\MetaTag\Html5MetaTagManager;
19 use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
20 use TYPO3\CMS\Core\MetaTag\OpenGraphMetaTagManager;
21 use TYPO3\CMS\Core\MetaTag\TwitterCardMetaTagManager;
22
23 /**
24 * Test case
25 */
26 class MetaTagManagerRegistryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
28 /**
29 * @test
30 */
31 public function checkRegisterNonExistingManagerDoesntThrowErrorWhenFetchingManagers()
32 {
33 $metaTagManagerRegistry = new MetaTagManagerRegistry();
34
35 $metaTagManagerRegistry->registerManager('name', 'fake//class//name');
36 $metaTagManagerRegistry->getAllManagers();
37 }
38
39 /**
40 * @param array $managersToRegister
41 * @param array $expected
42 *
43 * @dataProvider registerMetaTagManagersProvider
44 * @test
45 */
46 public function checkRegisterExistingManagerDoRegister($managersToRegister, $expected)
47 {
48 $metaTagManagerRegistry = new MetaTagManagerRegistry();
49
50 foreach ($managersToRegister as $managerToRegister) {
51 $metaTagManagerRegistry->registerManager(
52 $managerToRegister['name'],
53 $managerToRegister['className'],
54 (array)$managerToRegister['before'],
55 (array)$managerToRegister['after']
56 );
57 }
58
59 // Remove all properties from the manager if it was set by a previous unittest
60 foreach ($metaTagManagerRegistry->getAllManagers() as $manager) {
61 $manager->removeAllProperties();
62 }
63
64 $managers = $metaTagManagerRegistry->getAllManagers();
65
66 $this->assertEquals($expected, $managers);
67 }
68
69 /**
70 * @test
71 */
72 public function checkConditionRaceResultsIntoException()
73 {
74 $input = [
75 'name' => 'opengraph',
76 'className' => OpenGraphMetaTagManager::class,
77 'before' => ['opengraph'],
78 'after' => []
79 ];
80
81 $this->expectException(\UnexpectedValueException::class);
82
83 $metaTagManagerRegistry = new MetaTagManagerRegistry();
84 $metaTagManagerRegistry->registerManager($input['name'], $input['className'], (array)$input['before'], (array)$input['after']);
85 $metaTagManagerRegistry->getAllManagers();
86 }
87 /**
88 * @return array
89 */
90 public function registerMetaTagManagersProvider()
91 {
92 return [
93 [
94 [
95 [
96 'name' => 'opengraph',
97 'className' => OpenGraphMetaTagManager::class,
98 'before' => [],
99 'after' => []
100 ]
101 ],
102 [
103 new OpenGraphMetaTagManager(),
104 new GenericMetaTagManager()
105 ]
106 ],
107 [
108 [
109 [
110 'name' => 'opengraph',
111 'className' => OpenGraphMetaTagManager::class,
112 'before' => [],
113 'after' => []
114 ],
115 [
116 'name' => 'opengraph',
117 'className' => OpenGraphMetaTagManager::class,
118 'before' => [],
119 'after' => []
120 ],
121 ],
122 [
123 new OpenGraphMetaTagManager(),
124 new GenericMetaTagManager()
125 ]
126 ],
127 [
128 [
129 [
130 'name' => 'opengraph',
131 'className' => OpenGraphMetaTagManager::class,
132 'before' => [],
133 'after' => []
134 ],
135 [
136 'name' => 'html5',
137 'className' => Html5MetaTagManager::class,
138 'before' => [],
139 'after' => []
140 ],
141 ],
142 [
143 new Html5MetaTagManager(),
144 new OpenGraphMetaTagManager(),
145 new GenericMetaTagManager()
146 ]
147 ],
148 [
149 [
150 [
151 'name' => 'opengraph',
152 'className' => OpenGraphMetaTagManager::class,
153 'before' => ['html5'],
154 'after' => []
155 ],
156 [
157 'name' => 'html5',
158 'className' => Html5MetaTagManager::class,
159 'before' => [],
160 'after' => []
161 ],
162 ],
163 [
164 new OpenGraphMetaTagManager(),
165 new Html5MetaTagManager(),
166 new GenericMetaTagManager()
167 ]
168 ],
169 [
170 [
171 [
172 'name' => 'opengraph',
173 'className' => OpenGraphMetaTagManager::class,
174 'before' => [],
175 'after' => []
176 ],
177 [
178 'name' => 'html5',
179 'className' => Html5MetaTagManager::class,
180 'before' => [],
181 'after' => ['opengraph']
182 ],
183 ],
184 [
185 new OpenGraphMetaTagManager(),
186 new Html5MetaTagManager(),
187 new GenericMetaTagManager()
188 ]
189 ],
190 [
191 [
192 [
193 'name' => 'opengraph',
194 'className' => OpenGraphMetaTagManager::class,
195 'before' => [],
196 'after' => []
197 ],
198 [
199 'name' => 'html5',
200 'className' => Html5MetaTagManager::class,
201 'before' => [],
202 'after' => ['twitter']
203 ],
204 [
205 'name' => 'twitter',
206 'className' => TwitterCardMetaTagManager::class,
207 'before' => [],
208 'after' => ['opengraph']
209 ],
210 ],
211 [
212 new OpenGraphMetaTagManager(),
213 new TwitterCardMetaTagManager(),
214 new Html5MetaTagManager(),
215 new GenericMetaTagManager()
216 ]
217 ],
218 [
219 [],
220 [
221 new GenericMetaTagManager()
222 ]
223 ],
224 ];
225 }
226 }