TYPO3  7.6
TcaSelectTreeItemsTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
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;
26 
34 class TcaSelectTreeItemsTest extends UnitTestCase
35 {
39  protected $subject;
40 
44  protected $singletonInstances = [];
45 
49  public function setUp()
50  {
51  $this->singletonInstances = GeneralUtility::getSingletonInstances();
52  $this->subject = new TcaSelectTreeItems();
53  }
54 
55  protected function tearDown()
56  {
58  GeneralUtility::resetSingletonInstances($this->singletonInstances);
59  parent::tearDown();
60  }
61 
65  public function addDataAddsTreeConfigurationForExtJs()
66  {
67  $GLOBALS['TCA']['foreignTable'] = [];
68 
70  $database = $this->prophesize(DatabaseConnection::class);
71  $GLOBALS['TYPO3_DB'] = $database->reveal();
72 
74  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
75  $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
76 
78  $treeDataProviderProphecy = $this->prophesize(DatabaseTreeDataProvider::class);
79  GeneralUtility::addInstance(DatabaseTreeDataProvider::class, $treeDataProviderProphecy->reveal());
80 
82  $tableConfigurationTreeProphecy = $this->prophesize(TableConfigurationTree::class);
83  GeneralUtility::addInstance(TableConfigurationTree::class, $tableConfigurationTreeProphecy->reveal());
84  $tableConfigurationTreeProphecy->setDataProvider(Argument::cetera())->shouldBeCalled();
85  $tableConfigurationTreeProphecy->setNodeRenderer(Argument::cetera())->shouldBeCalled();
86  $tableConfigurationTreeProphecy->render()->shouldBeCalled()->willReturn(['fake', 'tree', 'data']);
87 
88  $input = [
89  'tableName' => 'aTable',
90  'databaseRow' => [
91  'aField' => '1'
92  ],
93  'processedTca' => [
94  'columns' => [
95  'aField' => [
96  'config' => [
97  'type' => 'select',
98  'renderType' => 'selectTree',
99  'treeConfig' => [
100  'childrenField' => 'childrenField'
101  ],
102  'foreign_table' => 'foreignTable',
103  'items' => [],
104  'maxitems' => 1
105  ],
106  ],
107  ],
108  ],
109  ];
110 
111  $expected = $input;
112  $expected['databaseRow']['aField'] = ['1'];
113  $expected['processedTca']['columns']['aField']['config']['treeData'] = [
114  'items' => [['fake', 'tree', 'data']],
115  'selectedNodes' => []
116  ];
117  $this->assertEquals($expected, $this->subject->addData($input));
118  }
119 }