‪TYPO3CMS  10.4
NodeFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪NodeFactoryTest extends UnitTestCase
36 {
41  {
42  $this->expectException(Exception::class);
43  $this->expectExceptionCode(1432207533);
44  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
45  1433089391 => [
46  'class' => 'foo',
47  'priority' => 23,
48  ],
49  ];
50  new ‪NodeFactory();
51  }
52 
57  {
58  $this->expectException(Exception::class);
59  $this->expectExceptionCode(1432207533);
60  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
61  1433089393 => [
62  'nodeName' => 'foo',
63  'class' => 'bar',
64  ],
65  ];
66  new ‪NodeFactory();
67  }
68 
73  {
74  $this->expectException(Exception::class);
75  $this->expectExceptionCode(1432207533);
76  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
77  1433089392 => [
78  'nodeName' => 'foo',
79  'priority' => 23,
80  ],
81  ];
82  new ‪NodeFactory();
83  }
84 
89  {
90  $this->expectException(Exception::class);
91  $this->expectExceptionCode(1432223531);
92  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
93  1433089394 => [
94  'nodeName' => 'foo',
95  'class' => 'bar',
96  'priority' => -23,
97  ],
98  ];
99  new ‪NodeFactory();
100  }
105  {
106  $this->expectException(Exception::class);
107  $this->expectExceptionCode(1432223531);
108  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
109  1433089395 => [
110  'nodeName' => 'foo',
111  'class' => 'bar',
112  'priority' => 142,
113  ],
114  ];
115  new ‪NodeFactory();
116  }
117 
122  {
123  $this->expectException(Exception::class);
124  $this->expectExceptionCode(1432223893);
125  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
126  1433089396 => [
127  'nodeName' => 'foo',
128  'priority' => 20,
129  'class' => 'fooClass',
130  ],
131  1433089397 => [
132  'nodeName' => 'foo',
133  'priority' => 20,
134  'class' => 'barClass',
135  ],
136  ];
137  new ‪NodeFactory();
138  }
139 
144  {
145  $this->expectException(Exception::class);
146  $this->expectExceptionCode(1433155522);
147  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
148  1433154905 => [
149  'class' => 'foo',
150  'priority' => 23,
151  ],
152  ];
153  new ‪NodeFactory();
154  }
155 
160  {
161  $this->expectException(Exception::class);
162  $this->expectExceptionCode(1433155522);
163  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
164  1433154905 => [
165  'nodeName' => 'foo',
166  'class' => 'bar',
167  ],
168  ];
169  new ‪NodeFactory();
170  }
171 
176  {
177  $this->expectException(Exception::class);
178  $this->expectExceptionCode(1433155522);
179  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
180  1433154906 => [
181  'nodeName' => 'foo',
182  'priority' => 23,
183  ],
184  ];
185  new ‪NodeFactory();
186  }
187 
192  {
193  $this->expectException(Exception::class);
194  $this->expectExceptionCode(1433155563);
195  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
196  1433154907 => [
197  'nodeName' => 'foo',
198  'class' => 'bar',
199  'priority' => -23,
200  ],
201  ];
202  new ‪NodeFactory();
203  }
208  {
209  $this->expectException(Exception::class);
210  $this->expectExceptionCode(1433155563);
211  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
212  1433154908 => [
213  'nodeName' => 'foo',
214  'class' => 'bar',
215  'priority' => 142,
216  ],
217  ];
218  new ‪NodeFactory();
219  }
220 
225  {
226  $this->expectException(Exception::class);
227  $this->expectExceptionCode(1433155705);
228  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
229  1433154909 => [
230  'nodeName' => 'foo',
231  'priority' => 20,
232  'class' => 'fooClass',
233  ],
234  1433154910 => [
235  'nodeName' => 'foo',
236  'priority' => 20,
237  'class' => 'barClass',
238  ],
239  ];
240  new ‪NodeFactory();
241  }
242 
247  {
248  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
249  1433154909 => [
250  'nodeName' => 'foo',
251  'priority' => 20,
252  'class' => 'fooClass',
253  ],
254  1433154910 => [
255  'nodeName' => 'bar',
256  'priority' => 20,
257  'class' => 'barClass',
258  ],
259  ];
260  new ‪NodeFactory();
261  }
262 
267  {
268  $this->expectException(Exception::class);
269  $this->expectExceptionCode(1431452406);
270  $subject = new ‪NodeFactory();
271  $subject->create([]);
272  }
273 
278  {
279  $this->expectException(Exception::class);
280  $this->expectExceptionCode(1431872546);
281  $mockNode = new \stdClass();
283  $mockSubject = $this->getMockBuilder(NodeFactory::class)
284  ->setMethods(['instantiate'])
285  ->disableOriginalConstructor()
286  ->getMock();
287  $mockSubject->expects(self::once())->method('instantiate')->willReturn($mockNode);
288  $mockSubject->create(['renderType' => 'foo']);
289  }
290 
295  {
296  $unknownElementProphecy = $this->prophesize(UnknownElement::class);
297  $unknownElementRevelation = $unknownElementProphecy->reveal();
298  GeneralUtility::addInstance(UnknownElement::class, $unknownElementRevelation);
299  $subject = new ‪NodeFactory();
300  self::assertSame($unknownElementRevelation, $subject->create(['renderType' => 'foo']));
301  }
302 
307  {
308  $data = [
309  'type' => 'select',
310  'renderType' => 'selectTree',
311  ];
312  $selectTreeElementProphecy = $this->prophesize(SelectTreeElement::class);
313  $selectTreeElementRevelation = $selectTreeElementProphecy->reveal();
314  GeneralUtility::addInstance(SelectTreeElement::class, $selectTreeElementRevelation);
315  $subject = new ‪NodeFactory();
316  self::assertSame($selectTreeElementRevelation, $subject->create($data));
317  }
318 
323  {
324  $data = [
325  'type' => 'select',
326  'renderType' => 'selectSingle',
327  'parameterArray' => [
328  'fieldConf' => [
329  'config' => [],
330  ],
331  ],
332  ];
333  $subject = new ‪NodeFactory();
334  $selectSingleElementProphecy = $this->prophesize(SelectSingleElement::class);
335  $selectSingleElementRevelation = $selectSingleElementProphecy->reveal();
336  GeneralUtility::addInstance(SelectSingleElement::class, $selectSingleElementRevelation);
337  self::assertSame($selectSingleElementRevelation, $subject->create($data));
338  }
339 
344  {
345  $data = ['renderType' => 'foo'];
346  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
347  [
348  'nodeName' => 'foo',
349  'priority' => 20,
350  'class' => FooElement::class,
351  ],
352  ];
353 
354  $subject = new ‪NodeFactory();
355  self::assertInstanceOf(FooElement::class, ($subject->create($data)));
356  }
357 
362  {
363  $data = ['renderType' => 'foo'];
364  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
365  1433089467 => [
366  'nodeName' => 'foo',
367  'priority' => 20,
368  'class' => FooElement::class,
369  ],
370  1433089468 => [
371  'nodeName' => 'foo',
372  'priority' => 30,
373  'class' => BarElement::class,
374  ],
375  ];
376  $subject = new ‪NodeFactory();
377  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
378  }
379 
384  {
385  $data = ['renderType' => 'foo'];
386  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
387  1433089469 => [
388  'nodeName' => 'foo',
389  'priority' => 30,
390  'class' => FooElement::class,
391  ],
392  1433089470 => [
393  'nodeName' => 'foo',
394  'priority' => 20,
395  'class' => BarElement::class,
396  ],
397  ];
398  $subject = new ‪NodeFactory();
399  self::assertInstanceOf(FooElement::class, ($subject->create($data)));
400  }
401 
406  {
407  $this->expectException(Exception::class);
408  $this->expectExceptionCode(1433157422);
409  $data = ['renderType' => 'foo'];
410  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
411  1433156887 => [
412  'nodeName' => 'foo',
413  'priority' => 10,
414  'class' => InvalidNodeResolverClass::class,
415  ],
416  ];
417  $subject = new ‪NodeFactory();
418  $subject->create($data);
419  }
420 
425  {
426  $data = ['renderType' => 'foo'];
427  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
428  [
429  'nodeName' => 'foo',
430  'priority' => 20,
431  'class' => FooElement::class,
432  ],
433  ];
434  $mockNode = $this->createMock(NodeInterface::class);
435 
436  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
437  1433156887 => [
438  'nodeName' => 'foo',
439  'priority' => 10,
440  'class' => FooResolver::class,
441  ],
442  1433156888 => [
443  'nodeName' => 'foo',
444  'priority' => 30,
445  'class' => BarResolver::class,
446  ],
447  ];
448  $subject = new ‪NodeFactory();
449  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
450  }
451 
456  {
457  $data = ['renderType' => 'foo'];
458  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
459  [
460  'nodeName' => 'foo',
461  'priority' => 20,
462  'class' => FooElement::class,
463  ],
464  ];
465 
466  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
467  1433156887 => [
468  'nodeName' => 'foo',
469  'priority' => 30,
470  'class' => BarResolver::class,
471  ],
472  1433156888 => [
473  'nodeName' => 'foo',
474  'priority' => 10,
475  'class' => FooResolver::class,
476  ],
477  ];
478  $subject = new ‪NodeFactory();
479  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
480  }
481 
486  {
487  $data = ['renderType' => 'foo'];
488  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
489  [
490  'nodeName' => 'foo',
491  'priority' => 20,
492  'class' => FooElement::class,
493  ],
494  ];
495 
496  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
497  1433156887 => [
498  'nodeName' => 'foo',
499  'priority' => 30,
500  'class' => BarResolver::class,
501  ],
502  ];
503  $subject = new ‪NodeFactory();
504  self::assertInstanceOf(BarElement::class, ($subject->create($data)));
505  }
506 }
‪TYPO3\CMS\Backend\Form\Element\UnknownElement
Definition: UnknownElement.php:22
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\BarResolver
Definition: BarResolver.php:12
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\InvalidNodeResolverClass
Definition: InvalidNodeResolverClass.php:8
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createReturnsInstanceOfSelectSingleElementIfNeeded
‪createReturnsInstanceOfSelectSingleElementIfNeeded()
Definition: NodeFactoryTest.php:322
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createThrowsExceptionIfResolverDoesNotImplementNodeResolverInterface
‪createThrowsExceptionIfResolverDoesNotImplementNodeResolverInterface()
Definition: NodeFactoryTest.php:405
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverrideMissesClassKey
‪constructThrowsExceptionIfOverrideMissesClassKey()
Definition: NodeFactoryTest.php:72
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructorThrowsExceptionIfOverrideTwoNodesWithSamePriorityAndSameNodeNameAreRegistered
‪constructorThrowsExceptionIfOverrideTwoNodesWithSamePriorityAndSameNodeNameAreRegistered()
Definition: NodeFactoryTest.php:121
‪TYPO3\CMS\Backend\Form\Exception
Definition: AccessDeniedContentEditException.php:16
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverridePriorityIsLowerThanZero
‪constructThrowsExceptionIfOverridePriorityIsLowerThanZero()
Definition: NodeFactoryTest.php:88
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\BarElement
Definition: BarElement.php:11
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesResolverWithHighestPriorityFirstWithOtherGivenOrder
‪createInstantiatesResolverWithHighestPriorityFirstWithOtherGivenOrder()
Definition: NodeFactoryTest.php:455
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createThrowsExceptionIfRenderTypeIsNotGiven
‪createThrowsExceptionIfRenderTypeIsNotGiven()
Definition: NodeFactoryTest.php:266
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructorThrowsExceptionIfResolverTwoNodesWithSamePriorityAndSameNodeNameAreRegistered
‪constructorThrowsExceptionIfResolverTwoNodesWithSamePriorityAndSameNodeNameAreRegistered()
Definition: NodeFactoryTest.php:224
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverMissesNodeNameKey
‪constructThrowsExceptionIfResolverMissesNodeNameKey()
Definition: NodeFactoryTest.php:143
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverrideMissesNodeNameKey
‪constructThrowsExceptionIfOverrideMissesNodeNameKey()
Definition: NodeFactoryTest.php:40
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverrideMissesPriorityKey
‪constructThrowsExceptionIfOverrideMissesPriorityKey()
Definition: NodeFactoryTest.php:56
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructorThrowsNoExceptionIfResolverWithSamePriorityButDifferentNodeNameAreRegistered
‪constructorThrowsNoExceptionIfResolverWithSamePriorityButDifferentNodeNameAreRegistered()
Definition: NodeFactoryTest.php:246
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverPriorityIsHigherThanHundred
‪constructThrowsExceptionIfResolverPriorityIsHigherThanHundred()
Definition: NodeFactoryTest.php:207
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesElementRegisteredWithHigherPriorityWithOneGivenOrder
‪createInstantiatesElementRegisteredWithHigherPriorityWithOneGivenOrder()
Definition: NodeFactoryTest.php:361
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeResolvers\FooResolver
Definition: FooResolver.php:12
‪TYPO3\CMS\Backend\Form\Element\SelectTreeElement
Definition: SelectTreeElement.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Form\Fixtures\NodeFactory\NodeElements\FooElement
Definition: FooElement.php:11
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest
Definition: NodeFactoryTest.php:36
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesResolverWithHighestPriorityFirstWithOneGivenOrder
‪createInstantiatesResolverWithHighestPriorityFirstWithOneGivenOrder()
Definition: NodeFactoryTest.php:424
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createReturnsInstanceOfUnknownElementIfTypeIsNotRegistered
‪createReturnsInstanceOfUnknownElementIfTypeIsNotRegistered()
Definition: NodeFactoryTest.php:294
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverPriorityIsLowerThanZero
‪constructThrowsExceptionIfResolverPriorityIsLowerThanZero()
Definition: NodeFactoryTest.php:191
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createThrowsExceptionIfNodeDoesNotImplementNodeInterface
‪createThrowsExceptionIfNodeDoesNotImplementNodeInterface()
Definition: NodeFactoryTest.php:277
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesNodeClassReturnedByResolver
‪createInstantiatesNodeClassReturnedByResolver()
Definition: NodeFactoryTest.php:485
‪TYPO3\CMS\Backend\Form\NodeInterface
Definition: NodeInterface.php:22
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:37
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfOverridePriorityIsHigherThanHundred
‪constructThrowsExceptionIfOverridePriorityIsHigherThanHundred()
Definition: NodeFactoryTest.php:104
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesElementRegisteredWithHigherPriorityWithOtherGivenOrder
‪createInstantiatesElementRegisteredWithHigherPriorityWithOtherGivenOrder()
Definition: NodeFactoryTest.php:383
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverMissesClassKey
‪constructThrowsExceptionIfResolverMissesClassKey()
Definition: NodeFactoryTest.php:175
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createInstantiatesNewRegisteredElement
‪createInstantiatesNewRegisteredElement()
Definition: NodeFactoryTest.php:343
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Form\Element\SelectSingleElement
Definition: SelectSingleElement.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\createReturnsInstanceOfSelectTreeElementIfNeeded
‪createReturnsInstanceOfSelectTreeElementIfNeeded()
Definition: NodeFactoryTest.php:306
‪TYPO3\CMS\Backend\Tests\Unit\Form\NodeFactoryTest\constructThrowsExceptionIfResolverMissesPriorityKey
‪constructThrowsExceptionIfResolverMissesPriorityKey()
Definition: NodeFactoryTest.php:159
‪TYPO3\CMS\Backend\Tests\Unit\Form