TYPO3 CMS  TYPO3_7-6
NodeFactoryTest.php
Go to the documentation of this file.
1 <?php
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 
22 
27 {
34  {
35  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
36  1433089391 => [
37  'class' => 'foo',
38  'priority' => 23,
39  ],
40  ];
41  new NodeFactory();
42  }
43 
50  {
51  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
52  1433089393 => [
53  'nodeName' => 'foo',
54  'class' => 'bar',
55  ],
56  ];
57  new NodeFactory();
58  }
59 
66  {
67  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
68  1433089392 => [
69  'nodeName' => 'foo',
70  'priority' => 23,
71  ],
72  ];
73  new NodeFactory();
74  }
75 
82  {
83  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
84  1433089394 => [
85  'nodeName' => 'foo',
86  'class' => 'bar',
87  'priority' => -23,
88  ],
89  ];
90  new NodeFactory();
91  }
98  {
99  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
100  1433089395 => [
101  'nodeName' => 'foo',
102  'class' => 'bar',
103  'priority' => 142,
104  ],
105  ];
106  new NodeFactory();
107  }
108 
115  {
116  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
117  1433089396 => [
118  'nodeName' => 'foo',
119  'priority' => 20,
120  'class' => 'fooClass',
121  ],
122  1433089397 => [
123  'nodeName' => 'foo',
124  'priority' => 20,
125  'class' => 'barClass',
126  ],
127  ];
128  new NodeFactory();
129  }
130 
137  {
138  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
139  1433154905 => [
140  'class' => 'foo',
141  'priority' => 23,
142  ],
143  ];
144  new NodeFactory();
145  }
146 
153  {
154  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
155  1433154905 => [
156  'nodeName' => 'foo',
157  'class' => 'bar',
158  ],
159  ];
160  new NodeFactory();
161  }
162 
169  {
170  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
171  1433154906 => [
172  'nodeName' => 'foo',
173  'priority' => 23,
174  ],
175  ];
176  new NodeFactory();
177  }
178 
185  {
186  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
187  1433154907 => [
188  'nodeName' => 'foo',
189  'class' => 'bar',
190  'priority' => -23,
191  ],
192  ];
193  new NodeFactory();
194  }
201  {
202  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
203  1433154908 => [
204  'nodeName' => 'foo',
205  'class' => 'bar',
206  'priority' => 142,
207  ],
208  ];
209  new NodeFactory();
210  }
211 
218  {
219  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
220  1433154909 => [
221  'nodeName' => 'foo',
222  'priority' => 20,
223  'class' => 'fooClass',
224  ],
225  1433154910 => [
226  'nodeName' => 'foo',
227  'priority' => 20,
228  'class' => 'barClass',
229  ],
230  ];
231  new NodeFactory();
232  }
233 
238  {
239  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
240  1433154909 => [
241  'nodeName' => 'foo',
242  'priority' => 20,
243  'class' => 'fooClass',
244  ],
245  1433154910 => [
246  'nodeName' => 'bar',
247  'priority' => 20,
248  'class' => 'barClass',
249  ],
250  ];
251  new NodeFactory();
252  }
253 
260  {
261  $subject = new NodeFactory();
262  $subject->create([]);
263  }
264 
270  public function createThrowsExceptionIfNodeDoesNotImplementNodeInterface()
271  {
272  $mockNode = new \stdClass();
274  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate'], [], '', false);
275  $mockSubject->expects($this->once())->method('instantiate')->will($this->returnValue($mockNode));
276  $mockSubject->create(['renderType' => 'foo']);
277  }
278 
283  {
284  $subject = new NodeFactory();
285  $this->assertInstanceOf(Element\UnknownElement::class, $subject->create(['renderType' => 'foo']));
286  }
287 
292  {
293  $data = [
294  'type' => 'select',
295  'renderType' => 'selectTree',
296  ];
297  $subject = new NodeFactory();
298  $this->assertInstanceOf(Element\SelectTreeElement::class, $subject->create($data));
299  }
300 
305  {
306  $data = [
307  'type' => 'select',
308  'renderType' => 'selectSingle',
309  'parameterArray' => [
310  'fieldConf' => [
311  'config' => [
312  'maxitems' => 1,
313  ],
314  ],
315  ],
316  ];
317  $subject = new NodeFactory();
318  $this->assertInstanceOf(Element\SelectSingleElement::class, $subject->create($data));
319  }
320 
324  public function createInstantiatesNewRegisteredElement()
325  {
326  $data = ['renderType' => 'foo'];
327  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
328  [
329  'nodeName' => 'foo',
330  'priority' => 20,
331  'class' => \stdClass::class,
332  ],
333  ];
334  $mockNode = $this->getMock(NodeInterface::class, [], [], '', false);
336  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
337  $mockSubject->expects($this->once())->method('instantiate')->with('stdClass')->will($this->returnValue($mockNode));
338  $mockSubject->create($data);
339  }
340 
344  public function createInstantiatesElementRegisteredWithHigherPriorityWithOneGivenOrder()
345  {
346  $data = ['renderType' => 'foo'];
347  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
348  1433089467 => [
349  'nodeName' => 'foo',
350  'priority' => 20,
351  'class' => 'foo1Class',
352  ],
353  1433089468 => [
354  'nodeName' => 'foo',
355  'priority' => 30,
356  'class' => 'foo2Class',
357  ],
358  ];
359  $mockNode = $this->getMock(NodeInterface::class, [], [], '', false);
361  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
362  $mockSubject->expects($this->once())->method('instantiate')->with('foo2Class')->will($this->returnValue($mockNode));
363  $mockSubject->create($data);
364  }
365 
369  public function createInstantiatesElementRegisteredWithHigherPriorityWithOtherGivenOrder()
370  {
371  $data = ['renderType' => 'foo'];
372  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
373  1433089469 => [
374  'nodeName' => 'foo',
375  'priority' => 30,
376  'class' => 'foo2Class',
377  ],
378  1433089470 => [
379  'nodeName' => 'foo',
380  'priority' => 20,
381  'class' => 'foo1Class',
382  ],
383  ];
384  $mockNode = $this->getMock(NodeInterface::class, [], [], '', false);
386  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
387  $mockSubject->expects($this->once())->method('instantiate')->with('foo2Class')->will($this->returnValue($mockNode));
388  $mockSubject->create($data);
389  }
390 
396  public function createThrowsExceptionIfResolverDoesNotImplementNodeResolverInterface()
397  {
398  $data = ['renderType' => 'foo'];
399  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
400  1433156887 => [
401  'nodeName' => 'foo',
402  'priority' => 10,
403  'class' => 'fooClass',
404  ],
405  ];
406  $mockResolver = $this->getMock(\stdClass::class);
407 
409  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
410  $mockSubject->expects($this->at(0))->method('instantiate')->will($this->returnValue($mockResolver));
411  $mockSubject->create($data);
412  }
413 
417  public function createInstantiatesResolverWithHighestPriorityFirstWithOneGivenOrder()
418  {
419  $data = ['renderType' => 'foo'];
420  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
421  [
422  'nodeName' => 'foo',
423  'priority' => 20,
424  'class' => \stdClass::class,
425  ],
426  ];
427  $mockNode = $this->getMock(NodeInterface::class, [], [], '', false);
428 
429  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
430  1433156887 => [
431  'nodeName' => 'foo',
432  'priority' => 10,
433  'class' => 'foo1Class',
434  ],
435  1433156888 => [
436  'nodeName' => 'foo',
437  'priority' => 30,
438  'class' => 'foo2Class',
439  ],
440  ];
441  $mockResolver1 = $this->getMock(NodeResolverInterface::class);
442  $mockResolver2 = $this->getMock(NodeResolverInterface::class);
443 
445  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
446  $mockSubject->expects($this->at(0))->method('instantiate')->with('foo2Class')->will($this->returnValue($mockResolver2));
447  $mockSubject->expects($this->at(1))->method('instantiate')->with('foo1Class')->will($this->returnValue($mockResolver1));
448  $mockSubject->expects($this->at(2))->method('instantiate')->will($this->returnValue($mockNode));
449  $mockSubject->create($data);
450  }
451 
455  public function createInstantiatesResolverWithHighestPriorityFirstWithOtherGivenOrder()
456  {
457  $data = ['renderType' => 'foo'];
458  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
459  [
460  'nodeName' => 'foo',
461  'priority' => 20,
462  'class' => \stdClass::class,
463  ],
464  ];
465  $mockNode = $this->getMock(NodeInterface::class, [], [], '', false);
466 
467  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
468  1433156887 => [
469  'nodeName' => 'foo',
470  'priority' => 30,
471  'class' => 'foo1Class',
472  ],
473  1433156888 => [
474  'nodeName' => 'foo',
475  'priority' => 10,
476  'class' => 'foo2Class',
477  ],
478  ];
479  $mockResolver1 = $this->getMock(NodeResolverInterface::class);
480  $mockResolver2 = $this->getMock(NodeResolverInterface::class);
481 
483  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
484  $mockSubject->expects($this->at(0))->method('instantiate')->with('foo1Class')->will($this->returnValue($mockResolver1));
485  $mockSubject->expects($this->at(1))->method('instantiate')->with('foo2Class')->will($this->returnValue($mockResolver2));
486  $mockSubject->expects($this->at(2))->method('instantiate')->will($this->returnValue($mockNode));
487  $mockSubject->create($data);
488  }
489 
493  public function createInstantiatesNodeClassReturnedByResolver()
494  {
495  $data = ['renderType' => 'foo'];
496  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
497  [
498  'nodeName' => 'foo',
499  'priority' => 20,
500  'class' => \stdClass::class,
501  ],
502  ];
503  $mockNode = $this->getMock(NodeInterface::class, [], [], '', false);
504 
505  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
506  1433156887 => [
507  'nodeName' => 'foo',
508  'priority' => 30,
509  'class' => 'foo1Class',
510  ],
511  ];
512  $mockResolver1 = $this->getMock(NodeResolverInterface::class);
513  $mockResolver1->expects($this->once())->method('resolve')->will($this->returnValue('fooNodeClass'));
514 
516  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
517  $mockSubject->expects($this->at(0))->method('instantiate')->will($this->returnValue($mockResolver1));
518  $mockSubject->expects($this->at(1))->method('instantiate')->with('fooNodeClass')->will($this->returnValue($mockNode));
519  $mockSubject->create($data);
520  }
521 
525  public function createDoesNotCallSecondResolverWithLowerPriorityIfFirstResolverReturnedClassName()
526  {
527  $data = ['renderType' => 'foo'];
528  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'] = [
529  [
530  'nodeName' => 'foo',
531  'priority' => 20,
532  'class' => \stdClass::class,
533  ],
534  ];
535  $mockNode = $this->getMock(NodeInterface::class, [], [], '', false);
536 
537  $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeResolver'] = [
538  1433156887 => [
539  'nodeName' => 'foo',
540  'priority' => 30,
541  'class' => 'foo1Class',
542  ],
543  1433156888 => [
544  'nodeName' => 'foo',
545  'priority' => 10,
546  'class' => 'foo2Class',
547  ],
548  ];
549  $mockResolver1 = $this->getMock(NodeResolverInterface::class);
550  $mockResolver1->expects($this->once())->method('resolve')->will($this->returnValue('fooNodeClass'));
551 
553  $mockSubject = $this->getMock(NodeFactory::class, ['instantiate']);
554  $mockSubject->expects($this->at(0))->method('instantiate')->with('foo1Class')->will($this->returnValue($mockResolver1));
555  $mockSubject->expects($this->at(1))->method('instantiate')->with('fooNodeClass')->will($this->returnValue($mockNode));
556  $mockSubject->create($data);
557  }
558 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']