Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add
RedirectService
tests as preparation for a bugfix
Issue with the `RedirectService` has been reported wiht #103395 related to non-matching SiteConfig in cases no TypoScript template records exists, like when `b13/bolt` is used in instances. Changes #103437, #103439 and #103554 fixed the mentioned issue #103395 for TYPO3 v13, leaving the issue open for TYPO3 v12. Note: For v12 the regression test dataset needs to be disabled for now, and will be enabled with the upcoming fix. This change adds now some tests for non matching SiteConfiguration for `source_hosts`. Resolves: #103555 Related: #103395 Related: #103554 Related: #103439 Related: #103437 Releases: main, 12.4 Change-Id: I2c72de3fa5f8d8aae5e6d2ca702ea4685cd367b3 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83695 Tested-by: core-ci <typo3@b13.com> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: Stefan Bürk <stefan@buerk.tech>
- Loading branch information
Showing
7 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
...xtensions/test_bolt/Classes/EventListener/AddTypoScriptFromSiteExtensionEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3Tests\TestBolt\EventListener; | ||
|
||
use TYPO3\CMS\Core\Site\Entity\Site; | ||
use TYPO3\CMS\Core\TypoScript\IncludeTree\Event\AfterTemplatesHaveBeenDeterminedEvent; | ||
|
||
final class AddTypoScriptFromSiteExtensionEventListener | ||
{ | ||
// 2024-04-07T13:58:03+00:00 (UTC/GMT) | ||
private const SIMULATED_TIME = 1712498283; | ||
|
||
public function __invoke(AfterTemplatesHaveBeenDeterminedEvent $event): void | ||
{ | ||
$site = $event->getSite(); | ||
if (!$site instanceof Site) { | ||
return; | ||
} | ||
|
||
$emulateBolt = (bool)($site->getConfiguration()['test_bolt_enabled'] ?? false); | ||
if (!$emulateBolt) { | ||
return; | ||
} | ||
$constants = (string)($site->getConfiguration()['test_bolt_constants'] ?? ''); | ||
$setup = (string)($site->getConfiguration()['test_bolt_setup'] ?? ''); | ||
|
||
$siteRootPageId = $site->getRootPageId(); | ||
$rootline = $event->getRootline(); | ||
$sysTemplateRows = $event->getTemplateRows(); | ||
|
||
$highestUid = 1; | ||
foreach ($sysTemplateRows as $sysTemplateRow) { | ||
if ((int)($sysTemplateRow['uid'] ?? 0) > $highestUid) { | ||
$highestUid = (int)$sysTemplateRow['uid']; | ||
} | ||
} | ||
|
||
$fakeRow = [ | ||
'uid' => $highestUid + 1, | ||
'pid' => $siteRootPageId, | ||
'title' => 'Site extension include by test_bolt', | ||
'root' => 1, | ||
'clear' => 3, | ||
'include_static_file' => null, | ||
'constants' => $constants, | ||
'config' => $setup, | ||
]; | ||
// Set various "db" fields conditionally to be as robust as possible in case | ||
// core or some other loaded extension fiddles with them. | ||
$deleteField = $GLOBALS['TCA']['sys_template']['ctrl']['delete'] ?? null; | ||
if ($deleteField) { | ||
$fakeRow[$deleteField] = 0; | ||
} | ||
$disableField = $GLOBALS['TCA']['sys_template']['ctrl']['enablecolumns']['disabled'] ?? null; | ||
if ($disableField) { | ||
$fakeRow[$disableField] = 0; | ||
} | ||
$endtimeField = $GLOBALS['TCA']['sys_template']['ctrl']['enablecolumns']['endtime'] ?? null; | ||
if ($endtimeField) { | ||
$fakeRow[$endtimeField] = 0; | ||
} | ||
$starttimeField = $GLOBALS['TCA']['sys_template']['ctrl']['enablecolumns']['starttime'] ?? null; | ||
if ($starttimeField) { | ||
$fakeRow[$starttimeField] = 0; | ||
} | ||
$sortbyField = $GLOBALS['TCA']['sys_template']['ctrl']['sortby'] ?? null; | ||
if ($sortbyField) { | ||
$fakeRow[$sortbyField] = 0; | ||
} | ||
$tstampField = $GLOBALS['TCA']['sys_template']['ctrl']['tstamp'] ?? null; | ||
if ($tstampField) { | ||
$fakeRow[$tstampField] = self::SIMULATED_TIME; | ||
} | ||
if ($GLOBALS['TCA']['sys_template']['columns']['basedOn'] ?? false) { | ||
$fakeRow['basedOn'] = null; | ||
} | ||
if ($GLOBALS['TCA']['sys_template']['columns']['includeStaticAfterBasedOn'] ?? false) { | ||
$fakeRow['includeStaticAfterBasedOn'] = 0; | ||
} | ||
if ($GLOBALS['TCA']['sys_template']['columns']['static_file_mode'] ?? false) { | ||
$fakeRow['static_file_mode'] = 0; | ||
} | ||
|
||
if (empty($sysTemplateRows)) { | ||
// Simple things first: If there are no sys_template records yet, add our fake row and done. | ||
$sysTemplateRows[] = $fakeRow; | ||
$event->setTemplateRows($sysTemplateRows); | ||
return; | ||
} | ||
|
||
// When there are existing sys_template rows, we try to add our fake row at the most useful position. | ||
$newSysTemplateRows = []; | ||
$pidsBeforeSite = [0]; | ||
$reversedRootline = array_reverse($rootline); | ||
foreach ($reversedRootline as $page) { | ||
if (($page['uid'] ?? 0) !== $siteRootPageId) { | ||
$pidsBeforeSite[] = (int)($page['uid'] ?? 0); | ||
} else { | ||
break; | ||
} | ||
} | ||
$pidsBeforeSite = array_unique($pidsBeforeSite); | ||
|
||
$fakeRowAdded = false; | ||
foreach ($sysTemplateRows as $sysTemplateRow) { | ||
if ($fakeRowAdded) { | ||
// We added the fake row already. Just add all other templates below this. | ||
$newSysTemplateRows[] = $sysTemplateRow; | ||
continue; | ||
} | ||
if (in_array((int)($sysTemplateRow['pid'] ?? 0), $pidsBeforeSite)) { | ||
$newSysTemplateRows[] = $sysTemplateRow; | ||
// If there is a sys_template row *before* our site, we assume settings from above | ||
// templates should "fall through", so we unset the clear flags. If this is not | ||
// wanted, an instance may need to register another event listener after this one | ||
// to set the clear flag again. | ||
$fakeRow['clear'] = 0; | ||
} elseif ((int)($sysTemplateRow['pid'] ?? 0) === $siteRootPageId) { | ||
// There is a sys_template on the site root page already. We add our fake row before | ||
// this one, then force the root and the clear flag of the sys_template row to 0. | ||
$newSysTemplateRows[] = $fakeRow; | ||
$fakeRowAdded = true; | ||
$sysTemplateRow['root'] = 0; | ||
$sysTemplateRow['clear'] = 0; | ||
$newSysTemplateRows[] = $sysTemplateRow; | ||
} else { | ||
// Not a sys_template row before, not an sys_template record on same page. Add our | ||
// fake row and mark we added it. | ||
$newSysTemplateRows[] = $fakeRow; | ||
$newSysTemplateRows[] = $sysTemplateRow; | ||
$fakeRowAdded = true; | ||
} | ||
} | ||
$event->setTemplateRows($newSysTemplateRows); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...sext/redirects/Tests/Functional/Fixtures/Extensions/test_bolt/Configuration/Services.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
TYPO3Tests\TestBolt\: | ||
resource: '../Classes/*' | ||
|
||
TYPO3Tests\TestBolt\EventListener\AddTypoScriptFromSiteExtensionEventListener: | ||
public: true | ||
tags: | ||
- name: event.listener | ||
identifier: 'test-bolt/add-typoscript-from-site-extension' |
20 changes: 20 additions & 0 deletions
20
typo3/sysext/redirects/Tests/Functional/Fixtures/Extensions/test_bolt/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "typo3tests/test-bolt", | ||
"type": "typo3-cms-extension", | ||
"description": "This extension simulates b13/bolt.", | ||
"license": "GPL-2.0-or-later", | ||
"require": { | ||
"typo3/cms-core": "13.1.*@dev", | ||
"typo3/cms-frontend": "13.1.*@dev" | ||
}, | ||
"extra": { | ||
"typo3/cms": { | ||
"extension-key": "test_bolt" | ||
} | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"TYPO3Tests\\TestBolt\\": "Classes/" | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
typo3/sysext/redirects/Tests/Functional/Fixtures/Extensions/test_bolt/ext_emconf.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$EM_CONF[$_EXTKEY] = [ | ||
'title' => 'This extension simulates b13/bolt.', | ||
'description' => 'This extension simulates b13/bolt.', | ||
'category' => 'example', | ||
'version' => '13.1.0', | ||
'state' => 'beta', | ||
'author' => 'Stefan Bürk', | ||
'author_email' => 'stefan@buerk.tech', | ||
'author_company' => '', | ||
'constraints' => [ | ||
'depends' => [ | ||
'typo3' => '13.1.0', | ||
], | ||
'conflicts' => [], | ||
'suggests' => [], | ||
], | ||
]; |
8 changes: 8 additions & 0 deletions
8
...ext/redirects/Tests/Functional/Service/Fixtures/SourceHostWithoutSourceConfigRedirect.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
"pages",,,,,,,, | ||
,"uid","pid","title","slug","hidden","deleted","fe_group", | ||
,1,0,"Root","/",0,0,0, | ||
,2,1,"Page2","/page2",0,0,0, | ||
"sys_redirect",,,,,,,, | ||
,"uid","pid","target_statuscode","disabled","deleted","source_host","source_path","target" | ||
,1,0,301,0,0,"non-configured.domain.tld","/redirect-to-pid1","t3://page?uid=1" | ||
,2,0,301,0,0,"non-configured.domain.tld","/redirect-to-pid2","t3://page?uid=2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters