49fc50e37fa891ac10c37cb279cb78f4bc32ab37
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaInlineTest.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\Prophecy\ObjectProphecy;
18 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaInline;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20
21 /**
22 * Test case
23 */
24 class TcaInlineTest extends \TYPO3\Components\TestingFramework\Core\UnitTestCase
25 {
26 /**
27 * @var TcaInline
28 */
29 protected $subject;
30
31 /**
32 * @var BackendUserAuthentication | ObjectProphecy
33 */
34 protected $beUserProphecy;
35
36 protected function setUp()
37 {
38 $this->beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
39 $GLOBALS['BE_USER'] = $this->beUserProphecy->reveal();
40
41 $this->subject = new TcaInline();
42 }
43
44 /**
45 * @var array Set of default controls
46 */
47 protected $defaultConfig = [
48 'processedTca' => [
49 'columns' => [
50 'aField' => [
51 'config' => [
52 'type' => 'inline',
53 'foreign_table' => 'aForeignTableName'
54 ],
55 ],
56 ],
57 ],
58 'inlineFirstPid' => 0,
59 ];
60
61 /**
62 * @test
63 */
64 public function addDataWithoutModifyRightsButWithInlineTypeWillNotParseChildren()
65 {
66 $input = [
67 'processedTca' => [
68 'columns' => [
69 'aField' => [
70 'config' => [
71 'type' => 'inline',
72 'foreign_table' => 'aForeignTableName',
73 ],
74 ],
75 ],
76 ],
77 ];
78
79 $this->beUserProphecy
80 ->check(
81 'tables_modify',
82 $input['processedTca']['columns']['aField']['config']['foreign_table']
83 )
84 ->shouldBeCalled()
85 ->willReturn(false);
86
87 $expected = $this->defaultConfig;
88 $expected['processedTca']['columns']['aField']['children'] = [];
89 $this->assertEquals($expected, $this->subject->addData($input));
90 }
91
92 /**
93 * @test
94 */
95 public function addDataWithUserRightsButWithoutInlineTypeWillNotParseChildren()
96 {
97 $input = [
98 'processedTca' => [
99 'columns' => [
100 'aField' => [
101 'config' => [
102 'type' => 'input',
103 'foreign_table' => 'aForeignTableName',
104 ],
105 ],
106 ],
107 ],
108 ];
109
110 $this->beUserProphecy
111 ->check(
112 'tables_modify',
113 $input['processedTca']['columns']['aField']['config']['foreign_table']
114 )
115 ->shouldNotBeCalled();
116
117 $expected = $this->defaultConfig;
118 $expected['processedTca']['columns']['aField']['config']['type'] = 'input';
119 $this->assertEquals($expected, $this->subject->addData($input));
120 }
121
122 /**
123 * @test
124 */
125 public function addDataWithInlineTypeAndModifyRightsWillAddChildren()
126 {
127 $input = [
128 'processedTca' => [
129 'columns' => [
130 'aField' => [
131 'config' => [
132 'type' => 'inline',
133 'foreign_table' => 'aForeignTableName',
134 ],
135 ],
136 ],
137 ],
138 ];
139
140 $this->beUserProphecy
141 ->check(
142 'tables_modify',
143 $input['processedTca']['columns']['aField']['config']['foreign_table']
144 )
145 ->shouldBeCalled()
146 ->willReturn(true);
147
148 $expected = $this->defaultConfig;
149 $expected['processedTca']['columns']['aField']['children'] = [];
150 $this->assertEquals($expected, $this->subject->addData($input));
151 }
152 }