[BUGFIX] Show correct label for IRRE records
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaSelectTreeItemsTest.php
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;
19 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaSelectTreeItems;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Database\DatabaseConnection;
22 use TYPO3\CMS\Core\Tests\UnitTestCase;
23 use TYPO3\CMS\Core\Tree\TableConfiguration\DatabaseTreeDataProvider;
24 use TYPO3\CMS\Core\Tree\TableConfiguration\TableConfigurationTree;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26
27 /**
28 * Tests for the TcaSelectTreeItems provider.
29 *
30 * This test only covers the renderTree() method. All other methods are covered TcaSelecItemsTest
31 *
32 * @see TcaSelecItemsTest
33 */
34 class TcaSelectTreeItemsTest extends UnitTestCase
35 {
36 /**
37 * @var TcaSelectTreeItems
38 */
39 protected $subject;
40
41 /**
42 * @var array A backup of registered singleton instances
43 */
44 protected $singletonInstances = [];
45
46 /**
47 * Initializes the mock object.
48 */
49 public function setUp()
50 {
51 $this->singletonInstances = GeneralUtility::getSingletonInstances();
52 $this->subject = new TcaSelectTreeItems();
53 }
54
55 protected function tearDown()
56 {
57 GeneralUtility::purgeInstances();
58 GeneralUtility::resetSingletonInstances($this->singletonInstances);
59 parent::tearDown();
60 }
61
62 /**
63 * @test
64 */
65 public function addDataAddsTreeConfigurationForExtJs()
66 {
67 $GLOBALS['TCA']['foreignTable'] = [];
68
69 /** @var DatabaseConnection|ObjectProphecy $database */
70 $database = $this->prophesize(DatabaseConnection::class);
71 $GLOBALS['TYPO3_DB'] = $database->reveal();
72
73 /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */
74 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
75 $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
76
77 /** @var DatabaseTreeDataProvider|ObjectProphecy $treeDataProviderProphecy */
78 $treeDataProviderProphecy = $this->prophesize(DatabaseTreeDataProvider::class);
79 GeneralUtility::addInstance(DatabaseTreeDataProvider::class, $treeDataProviderProphecy->reveal());
80
81 /** @var TableConfigurationTree|ObjectProphecy $treeDataProviderProphecy */
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 }