‪TYPO3CMS  ‪main
TcaInlineTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
21 use PHPUnit\Framework\MockObject\MockObject;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪TcaInlineTest extends UnitTestCase
27 {
29 
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  $this->beUserMock = $this->createMock(BackendUserAuthentication::class);
34  ‪$GLOBALS['BE_USER'] = ‪$this->beUserMock;
35  }
36 
37  #[Test]
39  {
40  $input = [
41  'processedTca' => [
42  'columns' => [
43  'aField' => [
44  'config' => [
45  'type' => 'inline',
46  'foreign_table' => 'aForeignTableName',
47  ],
48  ],
49  ],
50  ],
51  'inlineFirstPid' => 0,
52  ];
53 
54  $this->beUserMock
55  ->expects(self::atLeastOnce())
56  ->method('check')
57  ->with(
58  'tables_modify',
59  $input['processedTca']['columns']['aField']['config']['foreign_table']
60  )
61  ->willReturn(false);
62 
63  $expected = $input;
64  $expected['processedTca']['columns']['aField']['children'] = [];
65  self::assertEquals($expected, (new ‪TcaInline())->addData($input));
66  }
67 
68  #[Test]
70  {
71  $input = [
72  'processedTca' => [
73  'columns' => [
74  'aField' => [
75  'config' => [
76  'type' => 'input',
77  'foreign_table' => 'aForeignTableName',
78  ],
79  ],
80  ],
81  ],
82  'inlineFirstPid' => 0,
83  ];
84 
85  $this->beUserMock
86  ->expects(self::never())
87  ->method('check')
88  ->with(
89  'tables_modify',
90  $input['processedTca']['columns']['aField']['config']['foreign_table']
91  );
92 
93  $expected = $input;
94  $expected['processedTca']['columns']['aField']['config']['type'] = 'input';
95  self::assertEquals($expected, (new ‪TcaInline())->addData($input));
96  }
97 
98  #[Test]
100  {
101  $input = [
102  'processedTca' => [
103  'columns' => [
104  'aField' => [
105  'config' => [
106  'type' => 'inline',
107  'foreign_table' => 'aForeignTableName',
108  ],
109  ],
110  ],
111  ],
112  'inlineFirstPid' => 0,
113  'inlineResolveExistingChildren' => false,
114  ];
115 
116  $this->beUserMock
117  ->expects(self::atLeastOnce())
118  ->method('check')
119  ->with(
120  'tables_modify',
121  $input['processedTca']['columns']['aField']['config']['foreign_table']
122  )
123  ->willReturn(true);
124 
125  $expected = $input;
126  $expected['processedTca']['columns']['aField']['children'] = [];
127  self::assertEquals($expected, (new ‪TcaInline())->addData($input));
128  }
129 }
‪TYPO3\CMS\Backend\Form\FormDataProvider\TcaInline
Definition: TcaInline.php:39
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineTest\addDataWithoutModifyRightsButWithInlineTypeWillNotParseChildren
‪addDataWithoutModifyRightsButWithInlineTypeWillNotParseChildren()
Definition: TcaInlineTest.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineTest\setUp
‪setUp()
Definition: TcaInlineTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineTest\addDataWithInlineTypeAndModifyRightsWillAddChildren
‪addDataWithInlineTypeAndModifyRightsWillAddChildren()
Definition: TcaInlineTest.php:99
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineTest\addDataWithUserRightsButWithoutInlineTypeWillNotParseChildren
‪addDataWithUserRightsButWithoutInlineTypeWillNotParseChildren()
Definition: TcaInlineTest.php:69
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineTest\$beUserMock
‪BackendUserAuthentication &MockObject $beUserMock
Definition: TcaInlineTest.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider\TcaInlineTest
Definition: TcaInlineTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider
Definition: DatabaseDefaultLanguagePageRowTest.php:18