‪TYPO3CMS  ‪main
NodeFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 
33 final class ‪NodeFactoryTest extends UnitTestCase
34 {
35  #[Test]
37  {
38  $this->expectException(Exception::class);
39  $this->expectExceptionCode(1432207533);
40  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
41  1433089391 => [
42  'class' => 'foo',
43  'priority' => 23,
44  ],
45  ];
46  new ‪NodeFactory();
47  }
48 
49  #[Test]
51  {
52  $this->expectException(Exception::class);
53  $this->expectExceptionCode(1432207533);
54  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
55  1433089393 => [
56  'nodeName' => 'foo',
57  'class' => 'bar',
58  ],
59  ];
60  new ‪NodeFactory();
61  }
62 
63  #[Test]
65  {
66  $this->expectException(Exception::class);
67  $this->expectExceptionCode(1432207533);
68  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
69  1433089392 => [
70  'nodeName' => 'foo',
71  'priority' => 23,
72  ],
73  ];
74  new ‪NodeFactory();
75  }
76 
77  #[Test]
79  {
80  $this->expectException(Exception::class);
81  $this->expectExceptionCode(1432223531);
82  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
83  1433089394 => [
84  'nodeName' => 'foo',
85  'class' => 'bar',
86  'priority' => -23,
87  ],
88  ];
89  new ‪NodeFactory();
90  }
91  #[Test]
93  {
94  $this->expectException(Exception::class);
95  $this->expectExceptionCode(1432223531);
96  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
97  1433089395 => [
98  'nodeName' => 'foo',
99  'class' => 'bar',
100  'priority' => 142,
101  ],
102  ];
103  new ‪NodeFactory();
104  }
105 
106  #[Test]
108  {
109  $this->expectException(Exception::class);
110  $this->expectExceptionCode(1432223893);
111  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
112  1433089396 => [
113  'nodeName' => 'foo',
114  'priority' => 20,
115  'class' => 'fooClass',
116  ],
117  1433089397 => [
118  'nodeName' => 'foo',
119  'priority' => 20,
120  'class' => 'barClass',
121  ],
122  ];
123  new ‪NodeFactory();
124  }
125 
126  #[Test]
128  {
129  $this->expectException(Exception::class);
130  $this->expectExceptionCode(1433155522);
131  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
132  1433154905 => [
133  'class' => 'foo',
134  'priority' => 23,
135  ],
136  ];
137  new ‪NodeFactory();
138  }
139 
140  #[Test]
142  {
143  $this->expectException(Exception::class);
144  $this->expectExceptionCode(1433155522);
145  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
146  1433154905 => [
147  'nodeName' => 'foo',
148  'class' => 'bar',
149  ],
150  ];
151  new ‪NodeFactory();
152  }
153 
154  #[Test]
156  {
157  $this->expectException(Exception::class);
158  $this->expectExceptionCode(1433155522);
159  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
160  1433154906 => [
161  'nodeName' => 'foo',
162  'priority' => 23,
163  ],
164  ];
165  new ‪NodeFactory();
166  }
167 
168  #[Test]
170  {
171  $this->expectException(Exception::class);
172  $this->expectExceptionCode(1433155563);
173  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
174  1433154907 => [
175  'nodeName' => 'foo',
176  'class' => 'bar',
177  'priority' => -23,
178  ],
179  ];
180  new ‪NodeFactory();
181  }
182  #[Test]
184  {
185  $this->expectException(Exception::class);
186  $this->expectExceptionCode(1433155563);
187  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
188  1433154908 => [
189  'nodeName' => 'foo',
190  'class' => 'bar',
191  'priority' => 142,
192  ],
193  ];
194  new ‪NodeFactory();
195  }
196 
197  #[Test]
199  {
200  $this->expectException(Exception::class);
201  $this->expectExceptionCode(1433155705);
202  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
203  1433154909 => [
204  'nodeName' => 'foo',
205  'priority' => 20,
206  'class' => 'fooClass',
207  ],
208  1433154910 => [
209  'nodeName' => 'foo',
210  'priority' => 20,
211  'class' => 'barClass',
212  ],
213  ];
214  new ‪NodeFactory();
215  }
216 
217  #[Test]
219  {
220  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
221  1433154909 => [
222  'nodeName' => 'foo',
223  'priority' => 20,
224  'class' => 'fooClass',
225  ],
226  1433154910 => [
227  'nodeName' => 'bar',
228  'priority' => 20,
229  'class' => 'barClass',
230  ],
231  ];
232  new ‪NodeFactory();
233  }
234 
235  #[Test]
237  {
238  $this->expectException(Exception::class);
239  $this->expectExceptionCode(1431452406);
240  $subject = new ‪NodeFactory();
241  $subject->create([]);
242  }
243 
244  #[Test]
246  {
247  $unknownElementMock = $this->createMock(UnknownElement::class);
248  GeneralUtility::addInstance(UnknownElement::class, $unknownElementMock);
249  $subject = new ‪NodeFactory();
250  self::assertSame($unknownElementMock, $subject->create(['renderType' => 'foo']));
251  }
252 
253  #[Test]
255  {
256  $data = [
257  'type' => 'select',
258  'renderType' => 'selectTree',
259  ];
260  $selectTreeElementMock = $this->createMock(SelectTreeElement::class);
261  GeneralUtility::addInstance(SelectTreeElement::class, $selectTreeElementMock);
262  $subject = new ‪NodeFactory();
263  self::assertSame($selectTreeElementMock, $subject->create($data));
264  }
265 
266  #[Test]
268  {
269  $data = [
270  'type' => 'select',
271  'renderType' => 'selectSingle',
272  'parameterArray' => [
273  'fieldConf' => [
274  'config' => [],
275  ],
276  ],
277  ];
278  $subject = new ‪NodeFactory();
279  $selectSingleElementMock = $this->createMock(SelectSingleElement::class);
280  GeneralUtility::addInstance(SelectSingleElement::class, $selectSingleElementMock);
281  self::assertSame($selectSingleElementMock, $subject->create($data));
282  }
283 
284  #[Test]
286  {
287  $data = ['renderType' => 'foo'];
288  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
289  [
290  'nodeName' => 'foo',
291  'priority' => 20,
292  'class' => FooElement::class,
293  ],
294  ];
295 
296  $subject = new ‪NodeFactory();
297  self::assertInstanceOf(FooElement::class, ($subject->create($data)));
298  }
299 
300  #[Test]
302  {
303  $data = ['renderType' => 'foo'];
304  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
305  1433089467 => [
306  'nodeName' => 'foo',
307  'priority' => 20,
308  'class' => FooElement::class,
309  ],
310  1433089468 => [
311  'nodeName' => 'foo',
312  'priority' => 30,
313  'class' => BarElement::class,
314  ],
315  ];
316  $subject = new ‪NodeFactory();
317  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
318  }
319 
320  #[Test]
322  {
323  $data = ['renderType' => 'foo'];
324  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
325  1433089469 => [
326  'nodeName' => 'foo',
327  'priority' => 30,
328  'class' => FooElement::class,
329  ],
330  1433089470 => [
331  'nodeName' => 'foo',
332  'priority' => 20,
333  'class' => BarElement::class,
334  ],
335  ];
336  $subject = new ‪NodeFactory();
337  self::assertInstanceOf(FooElement::class, ($subject->create($data)));
338  }
339 
340  #[Test]
342  {
343  $data = ['renderType' => 'foo'];
344  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
345  [
346  'nodeName' => 'foo',
347  'priority' => 20,
348  'class' => FooElement::class,
349  ],
350  ];
351 
352  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
353  1433156887 => [
354  'nodeName' => 'foo',
355  'priority' => 10,
356  'class' => FooResolver::class,
357  ],
358  1433156888 => [
359  'nodeName' => 'foo',
360  'priority' => 30,
361  'class' => BarResolver::class,
362  ],
363  ];
364  $subject = new ‪NodeFactory();
365  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
366  }
367 
368  #[Test]
370  {
371  $data = ['renderType' => 'foo'];
372  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
373  [
374  'nodeName' => 'foo',
375  'priority' => 20,
376  'class' => FooElement::class,
377  ],
378  ];
379 
380  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
381  1433156887 => [
382  'nodeName' => 'foo',
383  'priority' => 30,
384  'class' => BarResolver::class,
385  ],
386  1433156888 => [
387  'nodeName' => 'foo',
388  'priority' => 10,
389  'class' => FooResolver::class,
390  ],
391  ];
392  $subject = new ‪NodeFactory();
393  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
394  }
395 
396  #[Test]
398  {
399  $data = ['renderType' => 'foo'];
400  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
401  [
402  'nodeName' => 'foo',
403  'priority' => 20,
404  'class' => FooElement::class,
405  ],
406  ];
407 
408  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
409  1433156887 => [
410  'nodeName' => 'foo',
411  'priority' => 30,
412  'class' => BarResolver::class,
413  ],
414  ];
415  $subject = new ‪NodeFactory();
416  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
417  }
418 }
‪TYPO3\CMS\Backend\Form\Element\UnknownElement
Definition: UnknownElement.php:22
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\BarResolver
Definition: BarResolver.php:24
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createReturnsInstanceOfSelectSingleElementIfNeeded
‪createReturnsInstanceOfSelectSingleElementIfNeeded()
Definition: NodeFactoryTest.php:267
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverrideMissesClassKey
‪constructThrowsExceptionIfOverrideMissesClassKey()
Definition: NodeFactoryTest.php:64
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructorThrowsExceptionIfOverrideTwoNodesWithSamePriorityAndSameNodeNameAreRegistered
‪constructorThrowsExceptionIfOverrideTwoNodesWithSamePriorityAndSameNodeNameAreRegistered()
Definition: NodeFactoryTest.php:107
‪TYPO3\CMS\Backend\Form\Exception
Definition: AccessDeniedContentEditException.php:16
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverridePriorityIsLowerThanZero
‪constructThrowsExceptionIfOverridePriorityIsLowerThanZero()
Definition: NodeFactoryTest.php:78
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\BarElement
Definition: BarElement.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesResolverWithHighestPriorityFirstWithOtherGivenOrder
‪createInstantiatesResolverWithHighestPriorityFirstWithOtherGivenOrder()
Definition: NodeFactoryTest.php:369
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createThrowsExceptionIfRenderTypeIsNotGiven
‪createThrowsExceptionIfRenderTypeIsNotGiven()
Definition: NodeFactoryTest.php:236
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructorThrowsExceptionIfResolverTwoNodesWithSamePriorityAndSameNodeNameAreRegistered
‪constructorThrowsExceptionIfResolverTwoNodesWithSamePriorityAndSameNodeNameAreRegistered()
Definition: NodeFactoryTest.php:198
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverMissesNodeNameKey
‪constructThrowsExceptionIfResolverMissesNodeNameKey()
Definition: NodeFactoryTest.php:127
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverrideMissesNodeNameKey
‪constructThrowsExceptionIfOverrideMissesNodeNameKey()
Definition: NodeFactoryTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverrideMissesPriorityKey
‪constructThrowsExceptionIfOverrideMissesPriorityKey()
Definition: NodeFactoryTest.php:50
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructorThrowsNoExceptionIfResolverWithSamePriorityButDifferentNodeNameAreRegistered
‪constructorThrowsNoExceptionIfResolverWithSamePriorityButDifferentNodeNameAreRegistered()
Definition: NodeFactoryTest.php:218
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverPriorityIsHigherThanHundred
‪constructThrowsExceptionIfResolverPriorityIsHigherThanHundred()
Definition: NodeFactoryTest.php:183
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesElementRegisteredWithHigherPriorityWithOneGivenOrder
‪createInstantiatesElementRegisteredWithHigherPriorityWithOneGivenOrder()
Definition: NodeFactoryTest.php:301
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\FooResolver
Definition: FooResolver.php:24
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement
Definition: SelectTreeElement.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\FooElement
Definition: FooElement.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest
Definition: NodeFactoryTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesResolverWithHighestPriorityFirstWithOneGivenOrder
‪createInstantiatesResolverWithHighestPriorityFirstWithOneGivenOrder()
Definition: NodeFactoryTest.php:341
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createReturnsInstanceOfUnknownElementIfTypeIsNotRegistered
‪createReturnsInstanceOfUnknownElementIfTypeIsNotRegistered()
Definition: NodeFactoryTest.php:245
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverPriorityIsLowerThanZero
‪constructThrowsExceptionIfResolverPriorityIsLowerThanZero()
Definition: NodeFactoryTest.php:169
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesNodeClassReturnedByResolver
‪createInstantiatesNodeClassReturnedByResolver()
Definition: NodeFactoryTest.php:397
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverridePriorityIsHigherThanHundred
‪constructThrowsExceptionIfOverridePriorityIsHigherThanHundred()
Definition: NodeFactoryTest.php:92
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesElementRegisteredWithHigherPriorityWithOtherGivenOrder
‪createInstantiatesElementRegisteredWithHigherPriorityWithOtherGivenOrder()
Definition: NodeFactoryTest.php:321
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverMissesClassKey
‪constructThrowsExceptionIfResolverMissesClassKey()
Definition: NodeFactoryTest.php:155
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesNewRegisteredElement
‪createInstantiatesNewRegisteredElement()
Definition: NodeFactoryTest.php:285
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Form\Element\SelectSingleElement
Definition: SelectSingleElement.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createReturnsInstanceOfSelectTreeElementIfNeeded
‪createReturnsInstanceOfSelectTreeElementIfNeeded()
Definition: NodeFactoryTest.php:254
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverMissesPriorityKey
‪constructThrowsExceptionIfResolverMissesPriorityKey()
Definition: NodeFactoryTest.php:141
‪TYPO3\CMS\Backend\Tests\Unit\Form