73f695c0eaf6a7169cb0efb8d3bb9d3812c7e458
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Controller / FormInlineAjaxControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Controller;
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 TYPO3\CMS\Backend\Controller\FormInlineAjaxController;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19
20 /**
21 * Test case
22 */
23 class FormInlineAjaxControllerTest extends \TYPO3\Components\TestingFramework\Core\UnitTestCase
24 {
25 /**
26 * Checks if the given file type may be uploaded without *ANY* limit to file types being given
27 *
28 * @test
29 */
30 public function checkInlineFileTypeAccessForFieldForFieldNoFiletypesReturnsTrue()
31 {
32 $selectorData = [];
33 $fileData['extension'] = 'png';
34 $mockObject = $this->getAccessibleMock(FormInlineAjaxController::class, ['dummy'], [], '', false);
35 $mayUploadFile = $mockObject->_call('checkInlineFileTypeAccessForField', $selectorData, $fileData);
36 $this->assertTrue($mayUploadFile);
37 }
38
39 /**
40 * Checks if the given file type may be uploaded and the given file type is *NOT* in the list of allowed files
41 *
42 * @test
43 */
44 public function checkInlineFileTypeAccessForFieldFiletypesSetRecordTypeNotInListReturnsFalse()
45 {
46 $selectorData['PA']['fieldConf']['config']['appearance']['elementBrowserAllowed'] = 'doc, png, jpg, tiff';
47 $fileData['extension'] = 'php';
48 $mockObject = $this->getAccessibleMock(FormInlineAjaxController::class, ['dummy'], [], '', false);
49 $mayUploadFile = $mockObject->_call('checkInlineFileTypeAccessForField', $selectorData, $fileData);
50 $this->assertFalse($mayUploadFile);
51 }
52
53 /**
54 * Checks if the given file type may be uploaded and the given file type *is* in the list of allowed files
55 * @test
56 */
57 public function checkInlineFileTypeAccessForFieldFiletypesSetRecordTypeInListReturnsTrue()
58 {
59 $selectorData['PA']['fieldConf']['config']['appearance']['elementBrowserAllowed'] = 'doc, png, jpg, tiff';
60 $fileData['extension'] = 'png';
61 $mockObject = $this->getAccessibleMock(FormInlineAjaxController::class, ['dummy'], [], '', false);
62 $mayUploadFile = $mockObject->_call('checkInlineFileTypeAccessForField', $selectorData, $fileData);
63 $this->assertTrue($mayUploadFile);
64 }
65
66 /**
67 * @dataProvider splitDomObjectIdDataProviderForTableName
68 * @param string $dataStructure
69 * @param string $expectedTableName
70 * @test
71 *
72 * test for the flexform domobject identifier split
73 */
74 public function splitDomObjectIdResolvesTablenameCorrectly($dataStructure, $expectedTableName)
75 {
76 $mock = $this->getAccessibleMock(FormInlineAjaxController::class, ['dummy'], [], '', false);
77 $result = $mock->_call('splitDomObjectId', $dataStructure);
78 $this->assertSame($expectedTableName, $result[1]);
79 }
80
81 /**
82 * @return array
83 */
84 public function splitDomObjectIdDataProviderForTableName()
85 {
86 return [
87 'news new' => [
88 'data-335-tx_news_domain_model_news-2-content_elements-tt_content-999-pi_flexform---data---sheet.tabGeneral---lDEF---settings.related_files---vDEF-tx_news_domain_model_file',
89 'tx_news_domain_model_file'
90 ],
91 'load existing child' => [
92 'data-318-tx_styleguide_flex-4-flex_3---data---sInline---lDEF---inline_1---vDEF-tx_styleguide_flex_flex_3_inline_1_child-4',
93 'tx_styleguide_flex_flex_3_inline_1_child'
94 ],
95 'create new child' => [
96 'data-318-tx_styleguide_flex-4-flex_3---data---sInline---lDEF---inline_1---vDEF-tx_styleguide_flex_flex_3_inline_1_child',
97 'tx_styleguide_flex_flex_3_inline_1_child'
98 ],
99 'insert new after' => [
100 'data-336-tt_content-1000-pi_flexform---data---sheet.tabGeneral---lDEF---settings.related_files---vDEF-tx_news_domain_model_file-6',
101 'tx_news_domain_model_file'
102 ],
103 'fal simple' => [
104 'data-336-tt_content-998-pi_flexform---data---sheet.tabGeneral---lDEF---settings.image---vDEF-sys_file_reference-837',
105 'sys_file_reference'
106 ],
107 'fal down deep' => [
108 'data-335-tx_news_domain_model_news-2-content_elements-tt_content-999-pi_flexform---data---sheet.tabGeneral---lDEF---settings.image---vDEF-sys_file_reference',
109 'sys_file_reference'
110 ],
111 'new record after others' => ['data-336-tt_content-1000-pi_flexform---data---sheet.tabGeneral---lDEF---settings.related_files---vDEF-tx_news_domain_model_file-NEW5757f36287214984252204', 'tx_news_domain_model_file'],
112 ];
113 }
114
115 /**
116 * @dataProvider splitDomObjectIdDataProviderForFlexFormPath
117 *
118 * @param string $dataStructure
119 * @param string $expectedFlexformPath
120 *
121 * @test
122 *
123 * test for the flexform domobject identifier split
124 */
125 public function splitDomObjectIdResolvesFlexformPathCorrectly($dataStructure, $expectedFlexformPath)
126 {
127 $mock = $this->getAccessibleMock(FormInlineAjaxController::class, ['dummy'], [], '', false);
128 $result = $mock->_call('splitDomObjectId', $dataStructure);
129 $this->assertSame($expectedFlexformPath, $result[0]);
130 }
131
132 /**
133 * @return array
134 */
135 public function splitDomObjectIdDataProviderForFlexFormPath()
136 {
137 return [
138 'news new' => [
139 'data-335-tx_news_domain_model_news-2-content_elements-tt_content-999-pi_flexform---data---sheet.tabGeneral---lDEF---settings.related_files---vDEF-tx_news_domain_model_file',
140 'sheet.tabGeneral:lDEF:settings.related_files:vDEF'
141 ],
142 'load existing child' => [
143 'data-318-tx_styleguide_flex-4-flex_3---data---sInline---lDEF---inline_1---vDEF-tx_styleguide_flex_flex_3_inline_1_child-4',
144 'sInline:lDEF:inline_1:vDEF'
145 ],
146 'create new child' => [
147 'data-318-tx_styleguide_flex-4-flex_3---data---sInline---lDEF---inline_1---vDEF-tx_styleguide_flex_flex_3_inline_1_child',
148 'sInline:lDEF:inline_1:vDEF'
149 ],
150 'insert new after' => [
151 'data-336-tt_content-1000-pi_flexform---data---sheet.tabGeneral---lDEF---settings.related_files---vDEF-tx_news_domain_model_file-6',
152 'sheet.tabGeneral:lDEF:settings.related_files:vDEF'
153 ],
154 'fal simple' => [
155 'data-336-tt_content-998-pi_flexform---data---sheet.tabGeneral---lDEF---settings.image---vDEF-sys_file_reference-837',
156 'sheet.tabGeneral:lDEF:settings.image:vDEF'
157 ],
158 'fal down deep' => [
159 'data-335-tx_news_domain_model_news-2-content_elements-tt_content-999-pi_flexform---data---sheet.tabGeneral---lDEF---settings.image---vDEF-sys_file_reference',
160 'sheet.tabGeneral:lDEF:settings.image:vDEF'
161 ],
162 'new record after others' => [
163 'data-336-tt_content-1000-pi_flexform---data---sheet.tabGeneral---lDEF---settings.related_files---vDEF-tx_news_domain_model_file-NEW5757f36287214984252204',
164 'sheet.tabGeneral:lDEF:settings.related_files:vDEF'
165 ],
166 ];
167 }
168
169 /**
170 * Fallback for IRRE items without inline view attribute
171 * @issue https://forge.typo3.org/issues/76561
172 *
173 * @test
174 */
175 public function getInlineExpandCollapseStateArraySwitchesToFallbackIfTheBackendUserDoesNotHaveAnUCInlineViewProperty()
176 {
177 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
178 $backendUserProphecy->uc = [];
179 $backendUser = $backendUserProphecy->reveal();
180
181 $mockObject = $this->getAccessibleMock(
182 FormInlineAjaxController::class,
183 ['getBackendUserAuthentication'],
184 [],
185 '',
186 false
187 );
188 $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
189 $result = $mockObject->_call('getInlineExpandCollapseStateArray');
190
191 $this->assertEmpty($result);
192 }
193
194 /**
195 * Unserialize uc inline view string for IRRE item
196 * @issue https://forge.typo3.org/issues/76561
197 *
198 * @test
199 */
200 public function getInlineExpandCollapseStateArrayWillUnserializeUCInlineViewPropertyAsAnArrayWithData()
201 {
202 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
203 $backendUserProphecy->uc = ['inlineView' => serialize(['foo' => 'bar'])];
204 $backendUser = $backendUserProphecy->reveal();
205
206 $mockObject = $this->getAccessibleMock(
207 FormInlineAjaxController::class,
208 ['getBackendUserAuthentication'],
209 [],
210 '',
211 false
212 );
213 $mockObject->method('getBackendUserAuthentication')->willReturn($backendUser);
214 $result = $mockObject->_call('getInlineExpandCollapseStateArray');
215
216 $this->assertNotEmpty($result);
217 }
218 }