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