‪TYPO3CMS  ‪main
RootlineUtilityTest.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;
28 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
29 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
30 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
31 
32 final class ‪RootlineUtilityTest extends FunctionalTestCase
33 {
35 
36  protected const ‪LANGUAGE_PRESETS = [
37  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
38  'FR' => ['id' => 1, 'title' => 'French', 'locale' => 'fr_FR.UTF8'],
39  'FR-CA' => ['id' => 2, 'title' => 'Franco-Canadian', 'locale' => 'fr_CA.UTF8'],
40  'ES' => ['id' => 3, 'title' => 'Spanish', 'locale' => 'es_ES.UTF8'],
41  ];
42 
43  protected array ‪$coreExtensionsToLoad = ['workspaces'];
44 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48 
50  'main',
51  $this->‪buildSiteConfiguration(1000, 'https://acme.com/'),
52  [
53  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
54  $this->‪buildLanguageConfiguration('FR', '/fr/', ['EN']),
55  $this->‪buildLanguageConfiguration('FR-CA', '/fr-ca/', ['FR', 'EN']),
56  ]
57  );
58  $this->withDatabaseSnapshot(function () {
59  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
60  $backendUser = $this->setUpBackendUser(1);
61  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
62  $factory = DataHandlerFactory::fromYamlFile(__DIR__ . '/Fixtures/RootlineScenario.yaml');
63  $writer = DataHandlerWriter::withBackendUser($backendUser);
64  $writer->invokeFactory($factory);
65  static::failIfArrayIsNotEmpty($writer->getErrors());
66  });
67  }
68 
69  #[Test]
71  {
72  $rootPageUid = 1000;
73  $subject = new ‪RootlineUtility($rootPageUid);
74 
75  $result = $subject->get();
76 
77  self::assertCount(1, $result);
78  self::assertSame($rootPageUid, (int)$result[0]['uid']);
79  }
80 
81  #[Test]
83  {
84  $rootPageUid = 1000;
85  $subject = new ‪RootlineUtility($rootPageUid);
86 
87  unset(‪$GLOBALS['TCA']['pages']['columns']);
88  $result = $subject->get();
89 
90  self::assertCount(1, $result);
91  self::assertSame($rootPageUid, (int)$result[0]['uid']);
92  }
93 
94  #[Test]
96  {
97  $rootPageUid = 1000;
98  $subject = new ‪RootlineUtility($rootPageUid);
99 
100  ‪$GLOBALS['TCA']['pages']['columns'] = 'This is not an array.';
101  $result = $subject->get();
102 
103  self::assertCount(1, $result);
104  self::assertSame($rootPageUid, (int)$result[0]['uid']);
105  }
106 
107  #[Test]
108  public function ‪resolveLivePagesAndSkipWorkspacedVersions(): void
109  {
110  $context = GeneralUtility::makeInstance(Context::class);
111  $context->setAspect('workspace', new ‪WorkspaceAspect(0));
112  $subject = new ‪RootlineUtility(1330, '', $context);
113  $result = $subject->get();
114 
115  $expected = [
116  2 => [
117  'pid' => 1300,
118  'uid' => 1330,
119  't3ver_oid' => 0,
120  't3ver_wsid' => 0,
121  't3ver_state' => 0,
122  'title' => 'EN: Board Games',
123  ],
124  1 => [
125  'pid' => 1000,
126  'uid' => 1300,
127  't3ver_oid' => 0,
128  't3ver_wsid' => 0,
129  't3ver_state' => 0,
130  'title' => 'EN: Products',
131  ],
132  0 => [
133  'pid' => 0,
134  'uid' => 1000,
135  't3ver_oid' => 0,
136  't3ver_wsid' => 0,
137  't3ver_state' => 0,
138  'title' => 'ACME Global',
139  ],
140  ];
141  self::assertSame($expected, $this->‪filterExpectedValues($result, ['pid', 'uid', 't3ver_oid', 't3ver_wsid', 't3ver_state', 'title']));
142  }
143 
144  #[Test]
146  {
147  $context = GeneralUtility::makeInstance(Context::class);
148  $context->setAspect('workspace', new ‪WorkspaceAspect(1));
149  $subject = new ‪RootlineUtility(1400, '', $context);
150  $result = $subject->get();
151 
152  $expected = [
153  1 => [
154  'pid' => 1000,
155  'uid' => 1400,
156  't3ver_oid' => 0,
157  't3ver_wsid' => 1,
158  't3ver_state' => 1,
159  'title' => 'EN: A new page in workspace',
160  ],
161  0 => [
162  'pid' => 0,
163  'uid' => 1000,
164  't3ver_oid' => 1000,
165  't3ver_wsid' => 1,
166  't3ver_state' => 0,
167  'title' => 'ACME Global modified in Workspace 1',
168  '_ORIG_uid' => 10000,
169  ],
170  ];
171  self::assertSame($expected, $this->‪filterExpectedValues($result, ['pid', 'uid', 't3ver_oid', 't3ver_wsid', 't3ver_state', 'title', '_ORIG_uid', '_ORIG_pid']));
172  }
173 
174  #[Test]
175  public function ‪resolveLiveRootLineForMovedPage(): void
176  {
177  $context = GeneralUtility::makeInstance(Context::class);
178  $context->setAspect('workspace', new ‪WorkspaceAspect(0));
179  $subject = new ‪RootlineUtility(1333, '', $context);
180  $result = $subject->get();
181 
182  $expected = [
183  3 => [
184  'pid' => 1330,
185  'uid' => 1333,
186  't3ver_oid' => 0,
187  't3ver_wsid' => 0,
188  't3ver_state' => 0,
189  'title' => 'EN: Risk',
190  ],
191  2 => [
192  'pid' => 1300,
193  'uid' => 1330,
194  't3ver_oid' => 0,
195  't3ver_wsid' => 0,
196  't3ver_state' => 0,
197  'title' => 'EN: Board Games',
198  ],
199  1 => [
200  'pid' => 1000,
201  'uid' => 1300,
202  't3ver_oid' => 0,
203  't3ver_wsid' => 0,
204  't3ver_state' => 0,
205  'title' => 'EN: Products',
206  ],
207  0 => [
208  'pid' => 0,
209  'uid' => 1000,
210  't3ver_oid' => 0,
211  't3ver_wsid' => 0,
212  't3ver_state' => 0,
213  'title' => 'ACME Global',
214  ],
215  ];
216  self::assertSame($expected, $this->‪filterExpectedValues($result, ['pid', 'uid', 't3ver_oid', 't3ver_wsid', 't3ver_state', 'title', '_ORIG_uid', '_ORIG_pid']));
217  }
218 
219  #[Test]
220  public function ‪resolveWorkspaceOverlaysOfMovedPage(): void
221  {
222  $context = GeneralUtility::makeInstance(Context::class);
223  $context->setAspect('workspace', new ‪WorkspaceAspect(1));
224  $subject = new ‪RootlineUtility(1333, '', $context);
225  $result = $subject->get();
226 
227  $expected = [
228  3 => [
229  'pid' => 1320,
230  'uid' => 1333,
231  't3ver_oid' => 1333,
232  't3ver_wsid' => 1,
233  't3ver_state' => 4,
234  'title' => 'EN: Risk',
235  '_ORIG_pid' => 1330, // Pointing to the LIVE pid! WHY? All others point to the same PID! @todo
236  '_ORIG_uid' => 10001,
237  ],
238  2 => [
239  'pid' => 1300,
240  'uid' => 1320,
241  't3ver_oid' => 0,
242  't3ver_wsid' => 0,
243  't3ver_state' => 0,
244  'title' => 'EN: Card Games',
245  ],
246  1 => [
247  'pid' => 1000,
248  'uid' => 1300,
249  't3ver_oid' => 0,
250  't3ver_wsid' => 0,
251  't3ver_state' => 0,
252  'title' => 'EN: Products',
253  ],
254  0 => [
255  'pid' => 0,
256  'uid' => 1000,
257  't3ver_oid' => 1000,
258  't3ver_wsid' => 1,
259  't3ver_state' => 0,
260  'title' => 'ACME Global modified in Workspace 1',
261  '_ORIG_uid' => 10000,
262  ],
263  ];
264  self::assertSame($expected, $this->‪filterExpectedValues($result, ['pid', 'uid', 't3ver_oid', 't3ver_wsid', 't3ver_state', 'title', '_ORIG_uid', '_ORIG_pid']));
265 
266  // Now explicitly requesting the versioned ID, which holds the same result
267  $subject = new ‪RootlineUtility(10001, '', $context);
268  $result = $subject->get();
269  self::assertSame($expected, $this->‪filterExpectedValues($result, ['pid', 'uid', 't3ver_oid', 't3ver_wsid', 't3ver_state', 'title', '_ORIG_uid', '_ORIG_pid']));
270  }
271 
272  #[Test]
274  {
275  $this->expectException(PageNotFoundException::class);
276  $this->expectExceptionCode(1343464101);
277  $context = GeneralUtility::makeInstance(Context::class);
278  $context->setAspect('workspace', new ‪WorkspaceAspect(2));
279  $subject = new ‪RootlineUtility(1310, '', $context);
280  $subject->get();
281  }
282 
283  protected function ‪filterExpectedValues(array $incomingData, array ‪$fields): array
284  {
285  $result = [];
286  foreach ($incomingData as $pos => $values) {
287  array_walk($values, static function (&$val) {
288  if (is_numeric($val)) {
289  $val = (int)$val;
290  }
291  });
292  $result[$pos] = array_filter($values, static function ($fieldName) use (‪$fields) {
293  return in_array($fieldName, ‪$fields, true);
294  }, ARRAY_FILTER_USE_KEY);
295  }
296  return $result;
297  }
298 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\resolveLiveRootLineForMovedPage
‪resolveLiveRootLineForMovedPage()
Definition: RootlineUtilityTest.php:174
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:108
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\resolveWorkspaceOverlaysOfNewPageInWorkspace
‪resolveWorkspaceOverlaysOfNewPageInWorkspace()
Definition: RootlineUtilityTest.php:144
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest
Definition: RootlineUtilityTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: RootlineUtilityTest.php:35
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:40
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\rootlineFailsForDeletedParentPageInWorkspace
‪rootlineFailsForDeletedParentPageInWorkspace()
Definition: RootlineUtilityTest.php:272
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪$fields
‪$fields
Definition: pages.php:5
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\resolveWorkspaceOverlaysOfMovedPage
‪resolveWorkspaceOverlaysOfMovedPage()
Definition: RootlineUtilityTest.php:219
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\resolveLivePagesAndSkipWorkspacedVersions
‪resolveLivePagesAndSkipWorkspacedVersions()
Definition: RootlineUtilityTest.php:107
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: RootlineUtilityTest.php:42
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\getForRootPageAndWithNonArrayTableColumnsTcaReturnsEmptyArray
‪getForRootPageAndWithNonArrayTableColumnsTcaReturnsEmptyArray()
Definition: RootlineUtilityTest.php:94
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\getForRootPageOnlyReturnsRootPageInformation
‪getForRootPageOnlyReturnsRootPageInformation()
Definition: RootlineUtilityTest.php:69
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\Utility
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\setUp
‪setUp()
Definition: RootlineUtilityTest.php:44
‪TYPO3\CMS\Core\Exception\Page\PageNotFoundException
Definition: PageNotFoundException.php:23
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\filterExpectedValues
‪filterExpectedValues(array $incomingData, array $fields)
Definition: RootlineUtilityTest.php:282
‪TYPO3\CMS\Core\Tests\Functional\Utility\RootlineUtilityTest\getForRootPageAndWithMissingTableColumnsTcaReturnsEmptyArray
‪getForRootPageAndWithMissingTableColumnsTcaReturnsEmptyArray()
Definition: RootlineUtilityTest.php:81