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