‪TYPO3CMS  10.4
EditDocumentControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
19 use Psr\EventDispatcher\EventDispatcherInterface;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪EditDocumentControllerTest extends UnitTestCase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
41  {
42  $typoScript = [
43  'tx_myext.' => [
44  'controller' => 'test',
45  'action' => 'run'
46  ],
47  'magic' => 'yes'
48  ];
49  $expectedParameters = [
50  'tx_myext' => [
51  'controller' => 'test',
52  'action' => 'run'
53  ],
54  'magic' => 'yes'
55  ];
56  $result = [];
57  $uriBuilder = $this->prophesize(UriBuilder::class);
58  $moduleTemplate = $this->prophesize(ModuleTemplate::class);
59  $moduleTemplate->setUiBlock(Argument::any())->willReturn($moduleTemplate->reveal());
60  ‪$GLOBALS['LANG'] = $this->prophesize(LanguageService::class)->reveal();
61  GeneralUtility::setSingletonInstance(UriBuilder::class, $uriBuilder->reveal());
62  GeneralUtility::addInstance(ModuleTemplate::class, $moduleTemplate->reveal());
63 
64  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
65  $mock = \Closure::bind(static function (‪EditDocumentController $editDocumentController) use (&$result, $typoScript) {
66  return $editDocumentController->‪parseAdditionalGetParameters($result, $typoScript);
67  }, null, EditDocumentController::class);
68  $mock(new ‪EditDocumentController($eventDispatcher->reveal()));
69 
70  self::assertSame($expectedParameters, $result);
71  }
72 
77  public function ‪slugDependentFieldsAreAddedToColumnsOnly(string $result, string $selectedFields, string $tableName, array $configuration): void
78  {
79  ‪$GLOBALS['TCA'][$tableName]['columns'] = $configuration;
80 
81  $editDocumentControllerMock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', false);
82  $editDocumentControllerMock->_set('columnsOnly', $selectedFields);
83  $queryParams = [
84  'edit' => [
85  $tableName => [
86  '123,456' => 'edit'
87  ]
88  ],
89  ];
90  $editDocumentControllerMock->_call('addSlugFieldsToColumnsOnly', $queryParams);
91 
92  self::assertEquals($result, $editDocumentControllerMock->_get('columnsOnly'));
93  }
94 
96  {
97  return [
98  'fields in string' => [
99  'fo,bar,slug,title',
100  'fo,bar,slug',
101  'fake',
102  [
103  'slug' => [
104  'config' => [
105  'type' => 'slug',
106  'generatorOptions' => [
107  'fields' => ['title'],
108  ],
109  ]
110  ],
111  ]
112  ],
113  'fields in string and array' => [
114  'slug,fo,title,nav_title,title,other_field',
115  'slug,fo,title',
116  'fake',
117  [
118  'slug' => [
119  'config' => [
120  'type' => 'slug',
121  'generatorOptions' => [
122  'fields' => [['nav_title', 'title'], 'other_field']
123  ],
124  ]
125  ],
126  ]
127  ],
128  'no slug field given' => [
129  'slug,fo',
130  'slug,fo',
131  'fake',
132  [
133  'slug' => [
134  'config' => [
135  'type' => 'input',
136  'generatorOptions' => [
137  'fields' => [['nav_title', 'title'], 'other_field']
138  ],
139  ]
140  ],
141  ]
142  ],
143  ];
144  }
145 
146  public function ‪resolvePreviewRecordIdDataProvider(): array
147  {
148  return [
149  'default useDefaultLanguageRecord' => [
150  1,
151  [],
152  ],
153  'explicit useDefaultLanguageRecord' => [
154  1,
155  ['useDefaultLanguageRecord' => '1'],
156  ],
157  'useDefaultLanguageRecord = 0' => [
158  2,
159  ['useDefaultLanguageRecord' => '0'],
160  ]
161  ];
162  }
163 
170  public function ‪resolvePreviewRecordIdReturnsExpectedUid(int $expected, array $previewConfiguration): void
171  {
172  $recordArray = ['uid' => 2, 'l10n_parent' => 1];
173  $table = 'pages';
174  ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] = 'l10n_parent';
175 
176  $mock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', false);
177  $result = $mock->_call('resolvePreviewRecordId', $table, $recordArray, $previewConfiguration);
178  self::assertSame($expected, $result);
179  }
180 
182  {
183  return [
184  'default useDefaultLanguageRecord' => [
185  2,
186  [],
187  ],
188  'explicit useDefaultLanguageRecord' => [
189  2,
190  ['useDefaultLanguageRecord' => '1'],
191  ],
192  'useDefaultLanguageRecord = 0' => [
193  2,
194  ['useDefaultLanguageRecord' => '0'],
195  ]
196  ];
197  }
198 
203  public function ‪resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable(int $expected, array $previewConfiguration): void
204  {
205  $recordArray = ['uid' => 2];
206  $table = 'dummy_table';
207 
208  $mock = $this->getAccessibleMock(EditDocumentController::class, ['dummy'], [], '', false);
209  $result = $mock->_call('resolvePreviewRecordId', $table, $recordArray, $previewConfiguration);
210  self::assertSame($expected, $result);
211  }
212 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\slugDependentFieldsAreAddedToColumnsOnly
‪slugDependentFieldsAreAddedToColumnsOnly(string $result, string $selectedFields, string $tableName, array $configuration)
Definition: EditDocumentControllerTest.php:76
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdReturnsExpectedUid
‪resolvePreviewRecordIdReturnsExpectedUid(int $expected, array $previewConfiguration)
Definition: EditDocumentControllerTest.php:169
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\parseAdditionalGetParametersCreatesCorrectParameterArray
‪parseAdditionalGetParametersCreatesCorrectParameterArray()
Definition: EditDocumentControllerTest.php:39
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Backend\Controller\EditDocumentController\parseAdditionalGetParameters
‪parseAdditionalGetParameters(array &$parameters, array $typoScript)
Definition: EditDocumentController.php:962
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: EditDocumentControllerTest.php:34
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdForNonTranslatableTableDataProvider
‪resolvePreviewRecordIdForNonTranslatableTableDataProvider()
Definition: EditDocumentControllerTest.php:180
‪TYPO3\CMS\Backend\Controller\EditDocumentController
Definition: EditDocumentController.php:67
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\slugDependentFieldsAreAddedToColumnsOnlyDataProvider
‪slugDependentFieldsAreAddedToColumnsOnlyDataProvider()
Definition: EditDocumentControllerTest.php:94
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest
Definition: EditDocumentControllerTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable
‪resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable(int $expected, array $previewConfiguration)
Definition: EditDocumentControllerTest.php:202
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdDataProvider
‪resolvePreviewRecordIdDataProvider()
Definition: EditDocumentControllerTest.php:145
‪TYPO3\CMS\Backend\Tests\Unit\Controller
Definition: EditDocumentControllerTest.php:16
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46