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