‪TYPO3CMS  ‪main
EditDocumentControllerTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
25 final class ‪EditDocumentControllerTest extends UnitTestCase
26 {
27  protected bool ‪$resetSingletonInstances = true;
28 
29  #[DataProvider('slugDependentFieldsAreAddedToColumnsOnlyDataProvider')]
30  #[Test]
31  public function ‪slugDependentFieldsAreAddedToColumnsOnly(string $result, string $selectedFields, string $tableName, array $configuration): void
32  {
33  ‪$GLOBALS['TCA'][$tableName]['columns'] = $configuration;
34 
35  $editDocumentControllerMock = $this->getAccessibleMock(EditDocumentController::class, null, [], '', false);
36  $editDocumentControllerMock->_set('columnsOnly', $selectedFields);
37  $queryParams = [
38  'edit' => [
39  $tableName => [
40  '123,456' => 'edit',
41  ],
42  ],
43  ];
44  $editDocumentControllerMock->_call('addSlugFieldsToColumnsOnly', $queryParams);
45 
46  self::assertEquals($result, $editDocumentControllerMock->_get('columnsOnly'));
47  }
48 
50  {
51  return [
52  'fields in string' => [
53  'fo,bar,slug,title',
54  'fo,bar,slug',
55  'fake',
56  [
57  'slug' => [
58  'config' => [
59  'type' => 'slug',
60  'generatorOptions' => [
61  'fields' => ['title'],
62  ],
63  ],
64  ],
65  ],
66  ],
67  'fields in string and array' => [
68  'slug,fo,title,nav_title,title,other_field',
69  'slug,fo,title',
70  'fake',
71  [
72  'slug' => [
73  'config' => [
74  'type' => 'slug',
75  'generatorOptions' => [
76  'fields' => [['nav_title', 'title'], 'other_field'],
77  ],
78  ],
79  ],
80  ],
81  ],
82  'no slug field given' => [
83  'slug,fo',
84  'slug,fo',
85  'fake',
86  [
87  'slug' => [
88  'config' => [
89  'type' => 'input',
90  'generatorOptions' => [
91  'fields' => [['nav_title', 'title'], 'other_field'],
92  ],
93  ],
94  ],
95  ],
96  ],
97  ];
98  }
99 
100  public static function ‪resolvePreviewRecordIdDataProvider(): array
101  {
102  return [
103  'default useDefaultLanguageRecord' => [
104  1,
105  [],
106  ],
107  'explicit useDefaultLanguageRecord' => [
108  1,
109  ['useDefaultLanguageRecord' => '1'],
110  ],
111  'useDefaultLanguageRecord = 0' => [
112  2,
113  ['useDefaultLanguageRecord' => '0'],
114  ],
115  ];
116  }
117 
118  #[DataProvider('resolvePreviewRecordIdDataProvider')]
119  #[Test]
120  public function ‪resolvePreviewRecordIdReturnsExpectedUid(int $expected, array $previewConfiguration): void
121  {
122  $recordArray = ['uid' => 2, 'l10n_parent' => 1];
123  $table = 'pages';
124  ‪$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] = 'l10n_parent';
125 
126  $mock = $this->getAccessibleMock(EditDocumentController::class, null, [], '', false);
127  $result = $mock->_call('resolvePreviewRecordId', $table, $recordArray, $previewConfiguration);
128  self::assertSame($expected, $result);
129  }
130 
132  {
133  return [
134  'default useDefaultLanguageRecord' => [
135  2,
136  [],
137  ],
138  'explicit useDefaultLanguageRecord' => [
139  2,
140  ['useDefaultLanguageRecord' => '1'],
141  ],
142  'useDefaultLanguageRecord = 0' => [
143  2,
144  ['useDefaultLanguageRecord' => '0'],
145  ],
146  ];
147  }
148 
149  #[DataProvider('resolvePreviewRecordIdForNonTranslatableTableDataProvider')]
150  #[Test]
151  public function ‪resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable(int $expected, array $previewConfiguration): void
152  {
153  $recordArray = ['uid' => 2];
154  $table = 'dummy_table';
155 
156  $mock = $this->getAccessibleMock(EditDocumentController::class, null, [], '', false);
157  $result = $mock->_call('resolvePreviewRecordId', $table, $recordArray, $previewConfiguration);
158  self::assertSame($expected, $result);
159  }
160 }
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\slugDependentFieldsAreAddedToColumnsOnly
‪slugDependentFieldsAreAddedToColumnsOnly(string $result, string $selectedFields, string $tableName, array $configuration)
Definition: EditDocumentControllerTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdReturnsExpectedUid
‪resolvePreviewRecordIdReturnsExpectedUid(int $expected, array $previewConfiguration)
Definition: EditDocumentControllerTest.php:120
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdForNonTranslatableTableDataProvider
‪static resolvePreviewRecordIdForNonTranslatableTableDataProvider()
Definition: EditDocumentControllerTest.php:131
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\slugDependentFieldsAreAddedToColumnsOnlyDataProvider
‪static slugDependentFieldsAreAddedToColumnsOnlyDataProvider()
Definition: EditDocumentControllerTest.php:49
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: EditDocumentControllerTest.php:27
‪TYPO3\CMS\Backend\Controller\EditDocumentController
Definition: EditDocumentController.php:80
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest
Definition: EditDocumentControllerTest.php:26
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable
‪resolvePreviewRecordIdReturnsExpectedUidForNonTranslatableTable(int $expected, array $previewConfiguration)
Definition: EditDocumentControllerTest.php:151
‪TYPO3\CMS\Backend\Tests\Unit\Controller
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Controller\EditDocumentControllerTest\resolvePreviewRecordIdDataProvider
‪static resolvePreviewRecordIdDataProvider()
Definition: EditDocumentControllerTest.php:100