TYPO3 CMS  TYPO3_7-6
TcaSelectTreeItemsTest.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 
26 
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 
123  public function addDataHandsPageTsConfigSettingsOverToTableConfigurationTree()
124  {
125  $GLOBALS['TCA']['foreignTable'] = [];
126 
128  $database = $this->prophesize(DatabaseConnection::class);
129  $GLOBALS['TYPO3_DB'] = $database->reveal();
130 
132  $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
133  $GLOBALS['BE_USER'] = $backendUserProphecy->reveal();
134 
136  $treeDataProviderProphecy = $this->prophesize(DatabaseTreeDataProvider::class);
137  GeneralUtility::addInstance(DatabaseTreeDataProvider::class, $treeDataProviderProphecy->reveal());
138 
140  $tableConfigurationTreeProphecy = $this->prophesize(TableConfigurationTree::class);
141  GeneralUtility::addInstance(TableConfigurationTree::class, $tableConfigurationTreeProphecy->reveal());
142 
143  $input = [
144  'tableName' => 'aTable',
145  'databaseRow' => [
146  'aField' => '1'
147  ],
148  'processedTca' => [
149  'columns' => [
150  'aField' => [
151  'config' => [
152  'type' => 'select',
153  'renderType' => 'selectTree',
154  'treeConfig' => [
155  'childrenField' => 'childrenField'
156  ],
157  'foreign_table' => 'foreignTable',
158  'items' => [],
159  'maxitems' => 1
160  ],
161  ],
162  ],
163  ],
164  'pageTsConfig' => [
165  'TCEFORM.' => [
166  'aTable.' => [
167  'aField.' => [
168  'config.' => [
169  'treeConfig.' => [
170  'rootUid' => '42',
171  'appearance.' => [
172  'expandAll' => 1,
173  'maxLevels' => 4,
174  'nonSelectableLevels' => '0,1',
175  ],
176  ],
177  ],
178  ],
179  ],
180  ],
181  ],
182  ];
183 
184  $this->subject->addData($input);
185 
186  $treeDataProviderProphecy->setRootUid(42)->shouldHaveBeenCalled();
187  $treeDataProviderProphecy->setExpandAll(true)->shouldHaveBeenCalled();
188  $treeDataProviderProphecy->setLevelMaximum(4)->shouldHaveBeenCalled();
189  $treeDataProviderProphecy->setNonSelectableLevelList('0,1')->shouldHaveBeenCalled();
190  }
191 }
static addInstance($className, $instance)
$database
Definition: server.php:40
static resetSingletonInstances(array $newSingletonInstances)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']