TYPO3  7.6
OnTheFlyTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup;
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 Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
22 use TYPO3\CMS\Core\Tests\UnitTestCase;
23 
27 class OnTheFlyTest extends UnitTestCase
28 {
32  protected $subject;
33 
34  protected function setUp()
35  {
36  $this->subject = new OnTheFly();
37  }
38 
43  {
44  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1441108674);
45  $this->subject->compile([]);
46  }
47 
48 
52  public function compileReturnsIncomingData()
53  {
55  $formDataProviderProphecy = $this->prophesize(FormDataProviderInterface::class);
56  GeneralUtility::addInstance(FormDataProviderInterface::class, $formDataProviderProphecy->reveal());
57  $formDataProviderProphecy->addData(Argument::cetera())->willReturnArgument(0);
58  $providerList = [
59  FormDataProviderInterface::class,
60  ];
61  $this->subject->setProviderList($providerList);
62 
63  $input = [
64  'foo',
65  ];
66 
67  $this->assertEquals($input, $this->subject->compile($input));
68  }
69 
73  public function compileReturnsResultChangedByDataProvider()
74  {
76  $formDataProviderProphecy = $this->prophesize(FormDataProviderInterface::class);
77  GeneralUtility::addInstance(FormDataProviderInterface::class, $formDataProviderProphecy->reveal());
78 
79  $providerList = [
80  FormDataProviderInterface::class,
81  ];
82  $this->subject->setProviderList($providerList);
83  $providerResult = array('foo');
84  $formDataProviderProphecy->addData(Argument::cetera())->shouldBeCalled()->willReturn($providerResult);
85 
86  $this->assertEquals($providerResult, $this->subject->compile([]));
87  }
88 
92  public function compileThrowsExceptionIfDataProviderDoesNotImplementInterface()
93  {
95  $formDataProviderProphecy = $this->prophesize(\stdClass::class);
96  GeneralUtility::addInstance(\stdClass::class, $formDataProviderProphecy->reveal());
97  $providerList = [
98  \stdClass::class,
99  ];
100  $this->subject->setProviderList($providerList);
101 
102  $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1441108719);
103  $this->subject->compile([]);
104  }
105 }