‪TYPO3CMS  9.5
EditDocumentControllerTest.php
Go to the documentation of this file.
1 <?php
2 
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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪EditDocumentControllerTest extends UnitTestCase
27 {
31  protected ‪$resetSingletonInstances = true;
32 
37  {
38  $typoScript = [
39  'tx_myext.' => [
40  'controller' => 'test',
41  'action' => 'run'
42  ],
43  'magic' => 'yes'
44  ];
45  $expectedParameters = [
46  'tx_myext' => [
47  'controller' => 'test',
48  'action' => 'run'
49  ],
50  'magic' => 'yes'
51  ];
52  $result = [];
53  $uriBuilder = $this->prophesize(UriBuilder::class);
54  GeneralUtility::setSingletonInstance(UriBuilder::class, $uriBuilder->reveal());
55  $mock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', false);
56  $mock->_callRef('parseAdditionalGetParameters', $result, $typoScript);
57  $this->assertSame($expectedParameters, $result);
58  }
59 
64  public function ‪slugDependendFieldsAreAddedToColumnsOnly(string $result, string $selectedFields, string $tableName, array $configuration): void
65  {
66  ‪$GLOBALS['TCA'][$tableName]['columns'] = $configuration;
67 
68  $editDocumentControllerMock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', false);
69  $editDocumentControllerMock->_set('columnsOnly', $selectedFields);
70  $queryParams = [
71  'edit' => [
72  $tableName => [
73  '123,456' => 'edit'
74  ]
75  ],
76  ];
77  $editDocumentControllerMock->_call('addSlugFieldsToColumnsOnly', $queryParams);
78 
79  $this->assertEquals($result, $editDocumentControllerMock->_get('columnsOnly'));
80  }
81 
83  {
84  return [
85  'fields in string' => [
86  'fo,bar,slug,title',
87  'fo,bar,slug',
88  'fake',
89  [
90  'slug' => [
91  'config' => [
92  'type' => 'slug',
93  'generatorOptions' => [
94  'fields' => ['title'],
95  ],
96  ]
97  ],
98  ]
99  ],
100  'fields in string and array' => [
101  'slug,fo,title,nav_title,title,other_field',
102  'slug,fo,title',
103  'fake',
104  [
105  'slug' => [
106  'config' => [
107  'type' => 'slug',
108  'generatorOptions' => [
109  'fields' => [['nav_title', 'title'], 'other_field']
110  ],
111  ]
112  ],
113  ]
114  ],
115  'no slug field given' => [
116  'slug,fo',
117  'slug,fo',
118  'fake',
119  [
120  'slug' => [
121  'config' => [
122  'type' => 'input',
123  'generatorOptions' => [
124  'fields' => [['nav_title', 'title'], 'other_field']
125  ],
126  ]
127  ],
128  ]
129  ],
130  ];
131  }
132 
133  public function ‪resolvePreviewRecordIdDataProvider(): array
134  {
135  return [
136  'default useDefaultLanguageRecord' => [
137  1,
138  [],
139  ],
140  'explicit useDefaultLanguageRecord' => [
141  1,
142  ['useDefaultLanguageRecord' => '1'],
143  ],
144  'useDefaultLanguageRecord = 0' => [
145  2,
146  ['useDefaultLanguageRecord' => '0'],
147  ]
148  ];
149  }
150 
157  public function ‪resolvePreviewRecordIdReturnsExpectedUid(int $expected, array $previewConfiguration): void
158  {
159  $recordArray = ['uid' => 2, 'l10n_parent' => 1];
160  $table = 'pages';
161  ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] = 'l10n_parent';
162 
163  $mock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', false);
164  $result = $mock->_call('resolvePreviewRecordId', $table, $recordArray, $previewConfiguration);
165  self::assertSame($expected, $result);
166  }
167 
169  {
170  return [
171  'default useDefaultLanguageRecord' => [
172  2,
173  [],
174  ],
175  'explicit useDefaultLanguageRecord' => [
176  2,
177  ['useDefaultLanguageRecord' => '1'],
178  ],
179  'useDefaultLanguageRecord = 0' => [
180  2,
181  ['useDefaultLanguageRecord' => '0'],
182  ]
183  ];
184  }
185 
190  public function ‪resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable(int $expected, array $previewConfiguration): void
191  {
192  $recordArray = ['uid' => 2];
193  $table = 'dummy_table';
194 
195  $mock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', false);
196  $result = $mock->_call('resolvePreviewRecordId', $table, $recordArray, $previewConfiguration);
197  self::assertSame($expected, $result);
198  }
199 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdReturnsExpectedUid
‪resolvePreviewRecordIdReturnsExpectedUid(int $expected, array $previewConfiguration)
Definition: EditDocumentControllerTest.php:156
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\parseAdditionalGetParametersCreatesCorrectParameterArray
‪parseAdditionalGetParametersCreatesCorrectParameterArray()
Definition: EditDocumentControllerTest.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: EditDocumentControllerTest.php:30
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdForNonTranslatableTableDataProvider
‪resolvePreviewRecordIdForNonTranslatableTableDataProvider()
Definition: EditDocumentControllerTest.php:167
‪TYPO3\CMS\Backend\Controller\EditDocumentController
Definition: EditDocumentController.php:64
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest
Definition: EditDocumentControllerTest.php:27
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable
‪resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable(int $expected, array $previewConfiguration)
Definition: EditDocumentControllerTest.php:189
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdDataProvider
‪resolvePreviewRecordIdDataProvider()
Definition: EditDocumentControllerTest.php:132
‪TYPO3\CMS\Backend\Tests\Unit\Controller
Definition: EditDocumentControllerTest.php:3
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\slugDependendFieldsAreAddedToColumnsOnlyDataProvider
‪slugDependendFieldsAreAddedToColumnsOnlyDataProvider()
Definition: EditDocumentControllerTest.php:81
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\slugDependendFieldsAreAddedToColumnsOnly
‪slugDependendFieldsAreAddedToColumnsOnly(string $result, string $selectedFields, string $tableName, array $configuration)
Definition: EditDocumentControllerTest.php:63