Skip to content

Commit

Permalink
[TASK] Move FE rootline tests
Browse files Browse the repository at this point in the history
The rootline calculation has been moved around
with various patches in v12 & v13. Refactor some
related tests and move them to a more appropriate
place.
This also avoids another TSFE access in tests.

Resolves: #103701
Related: #102856
Related: #102715
Related: #103410
Releases: main
Change-Id: I0da5f0484ce90eab3909d1c202a13ce79250b0bb
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83956
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <ben@bnf.dev>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
lolli42 authored and bnf committed Apr 23, 2024
1 parent db6df19 commit a47f47c
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 199 deletions.

This file was deleted.

Expand Up @@ -17,11 +17,9 @@

namespace TYPO3\CMS\Frontend\Tests\Functional\Controller;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
use TYPO3\CMS\Frontend\Cache\CacheInstruction;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\TypoScriptInstruction;
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
Expand Down Expand Up @@ -154,200 +152,6 @@ public function localizationReturnsLocalizedStringWithLocallangLabel(): void
self::assertStringContainsString('Pagetree Overview', $body);
}

public static function getFromCacheSetsConfigRootlineToLocalRootlineDataProvider(): array
{
$page1 = [
'pid' => 0,
'uid' => 1,
't3ver_oid' => 0,
't3ver_wsid' => 0,
't3ver_state' => 0,
'title' => 'Pre page without template',
'nav_title' => '',
'media' => '',
'layout' => 0,
'hidden' => 0,
'starttime' => 0,
'endtime' => 0,
'fe_group' => '0',
'extendToSubpages' => 0,
'doktype' => 1,
'TSconfig' => null,
'tsconfig_includes' => '',
'is_siteroot' => 0,
'mount_pid' => 0,
'mount_pid_ol' => 0,
'backend_layout_next_level' => '',
];
$page2 = [
'pid' => 1,
'uid' => 2,
't3ver_oid' => 0,
't3ver_wsid' => 0,
't3ver_state' => 0,
'title' => 'Root page having template with root flag set by tests',
'nav_title' => '',
'media' => '',
'layout' => 0,
'hidden' => 0,
'starttime' => 0,
'endtime' => 0,
'fe_group' => '0',
'extendToSubpages' => 0,
'doktype' => 1,
'TSconfig' => null,
'tsconfig_includes' => '',
'is_siteroot' => 1,
'mount_pid' => 0,
'mount_pid_ol' => 0,
'backend_layout_next_level' => '',
];
$page88 = [
'pid' => 2,
'uid' => 88,
't3ver_oid' => 0,
't3ver_wsid' => 0,
't3ver_state' => 0,
'title' => 'Sub page 1',
'nav_title' => '',
'media' => '',
'layout' => 0,
'hidden' => 0,
'starttime' => 0,
'endtime' => 0,
'fe_group' => '0',
'extendToSubpages' => 0,
'doktype' => 1,
'TSconfig' => null,
'tsconfig_includes' => '',
'is_siteroot' => 0,
'mount_pid' => 0,
'mount_pid_ol' => 0,
'backend_layout_next_level' => '',
];
$page89 = [
'pid' => 88,
'uid' => 89,
't3ver_oid' => 0,
't3ver_wsid' => 0,
't3ver_state' => 0,
'title' => 'Sub sub page 1',
'nav_title' => '',
'media' => '',
'layout' => 0,
'hidden' => 0,
'starttime' => 0,
'endtime' => 0,
'fe_group' => '0',
'extendToSubpages' => 0,
'doktype' => 1,
'TSconfig' => null,
'tsconfig_includes' => '',
'is_siteroot' => 0,
'mount_pid' => 0,
'mount_pid_ol' => 0,
'backend_layout_next_level' => '',
];
$page98 = [
'pid' => 2,
'uid' => 98,
't3ver_oid' => 0,
't3ver_wsid' => 0,
't3ver_state' => 0,
'title' => 'Sub page 2 having template with root flag',
'nav_title' => '',
'media' => '',
'layout' => 0,
'hidden' => 0,
'starttime' => 0,
'endtime' => 0,
'fe_group' => '0',
'extendToSubpages' => 0,
'doktype' => 1,
'TSconfig' => null,
'tsconfig_includes' => '',
'is_siteroot' => 0,
'mount_pid' => 0,
'mount_pid_ol' => 0,
'backend_layout_next_level' => '',
];
$page99 = [
'pid' => 98,
'uid' => 99,
't3ver_oid' => 0,
't3ver_wsid' => 0,
't3ver_state' => 0,
'title' => 'Sub sub page 2',
'nav_title' => '',
'media' => '',
'layout' => 0,
'hidden' => 0,
'starttime' => 0,
'endtime' => 0,
'fe_group' => '0',
'extendToSubpages' => 0,
'doktype' => 1,
'TSconfig' => null,
'tsconfig_includes' => '',
'is_siteroot' => 0,
'mount_pid' => 0,
'mount_pid_ol' => 0,
'backend_layout_next_level' => '',
];
return [
'page with one root template on pid 2' => [
89,
[ 3 => $page89, 2 => $page88, 1 => $page2, 0 => $page1 ],
[ 0 => $page2, 1 => $page88, 2 => $page89 ],
false,
],
'page with one root template on pid 2 no cache' => [
89,
[ 3 => $page89, 2 => $page88, 1 => $page2, 0 => $page1 ],
[ 0 => $page2, 1 => $page88, 2 => $page89 ],
true,
],
'page with one root template on pid 2 and one on pid 98' => [
99,
[ 3 => $page99, 2 => $page98, 1 => $page2, 0 => $page1 ],
[ 0 => $page98, 1 => $page99 ],
false,
],
'page with one root template on pid 2 and one on pid 98 no cache' => [
99,
[ 3 => $page99, 2 => $page98, 1 => $page2, 0 => $page1 ],
[ 0 => $page98, 1 => $page99 ],
true,
],
];
}

#[DataProvider('getFromCacheSetsConfigRootlineToLocalRootlineDataProvider')]
#[Test]
public function getFromCacheSetsConfigRootlineToLocalRootline(int $pid, array $expectedRootLine, array $expectedConfigRootLine, bool $nocache): void
{
$this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
$this->setUpFrontendRootPage(
2,
['EXT:frontend/Tests/Functional/Controller/Fixtures/PageHelloWorld.typoscript']
);
$this->writeSiteConfiguration(
'test',
$this->buildSiteConfiguration(2, 'https://website.local/'),
[$this->buildDefaultLanguageConfiguration('EN', '/en/')]
);

$request = (new InternalRequest('https://website.local/en/'))->withPageId($pid);
if ($nocache) {
$cacheInstruction = new CacheInstruction();
$cacheInstruction->disableCache('EXT:frontend: Testing disables caching.');
$request = $request->withAttribute('frontend.cache.instruction', $cacheInstruction);
}
$this->executeFrontendSubRequest($request);
self::assertSame($expectedRootLine, $GLOBALS['TSFE']->rootLine);
self::assertSame($expectedConfigRootLine, $GLOBALS['TSFE']->config['rootLine']);
}

#[Test]
public function applicationConsidersTrueConditionVerdict(): void
{
Expand Down
@@ -0,0 +1,12 @@
"pages"
,"uid","pid","sorting","deleted","sys_language_uid","l10n_parent","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","title","slug","l10n_state"
,1,0,256,0,0,0,0,0,0,0,"Pre page without template","","{}"
,2,1,256,0,0,0,0,0,0,0,"Root page having template with root flag set by tests","/","{}"
,88,2,256,0,0,0,0,0,0,0,"Sub page 1","/subpage1/","{}"
,89,88,256,0,0,0,0,0,0,0,"Sub sub page 1","/subpage1/sub1/","{}"
,98,2,256,0,0,0,0,0,0,0,"Sub page 2 having template with root flag","/subpage2/","{}"
,99,98,256,0,0,0,0,0,0,0,"Sub sub page 2","/subpage2/sub2/","{}"
"sys_template"
,"uid","pid","sorting","deleted","hidden","starttime","endtime","root","clear","include_static_file","constants","config","basedOn","includeStaticAfterBasedOn","static_file_mode"
,1,98,256,0,0,0,0,1,0,"","","","",0,0
,2,2,256,0,0,0,0,1,3,"","","","",0,0
@@ -0,0 +1,69 @@
<?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 TYPO3\CMS\Frontend\Tests\Functional\Page;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Frontend\Page\PageInformationFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

final class PageInformationFactoryTest extends FunctionalTestCase
{
public static function getFromCacheSetsConfigRootlineToLocalRootlineDataProvider(): \Generator
{
$page1 = ['uid' => 1, 'pid' => 0, 'title' => 'Pre page without template'];
$page2 = ['uid' => 2, 'pid' => 1, 'title' => 'Root page having template with root flag set by tests'];
$page88 = ['uid' => 88, 'pid' => 2, 'title' => 'Sub page 1'];
$page89 = ['uid' => 89, 'pid' => 88, 'title' => 'Sub sub page 1'];
$page98 = ['uid' => 98, 'pid' => 2, 'title' => 'Sub page 2 having template with root flag'];
$page99 = ['uid' => 99, 'pid' => 98, 'title' => 'Sub sub page 2'];
yield 'page with one root template on pid 2' => [
'pid' => 89,
'expectedRootLine' => [ 3 => $page89, 2 => $page88, 1 => $page2, 0 => $page1 ],
'expectedLocalRootLine' => [ 0 => $page2, 1 => $page88, 2 => $page89 ],
];
yield 'page with one root template on pid 2 and one on pid 98' => [
'pid' => 99,
'expectedRootLine' => [ 3 => $page99, 2 => $page98, 1 => $page2, 0 => $page1 ],
'expectedLocalRootLine' => [ 0 => $page98, 1 => $page99 ],
];
}

#[DataProvider('getFromCacheSetsConfigRootlineToLocalRootlineDataProvider')]
#[Test]
public function getFromCacheSetsConfigRootlineToLocalRootline(int $pid, array $expectedRootLine, array $expectedLocalRootLine): void
{
$this->importCSVDataSet(__DIR__ . '/DataSet/PageInformationFactoryTestRootlineImport.csv');
$pageArguments = new PageArguments($pid, '0', []);
$site = new Site('test', 2, []);
$request = (new ServerRequest())
->withAttribute('routing', $pageArguments)
->withAttribute('site', $site);
$subject = $this->get(PageInformationFactory::class);
$pageInformation = $subject->create($request);
$rootLine = $pageInformation->getRootLine();
self::assertSame(array_keys($expectedRootLine), array_keys($rootLine));
self::assertArrayIsEqualToArrayOnlyConsideringListOfKeys($expectedRootLine, $rootLine, ['uid', 'pid', 'title']);
$localRootLine = $pageInformation->getLocalRootLine();
self::assertSame(array_keys($expectedLocalRootLine), array_keys($localRootLine));
self::assertArrayIsEqualToArrayOnlyConsideringListOfKeys($expectedLocalRootLine, $localRootLine, ['uid', 'pid', 'title']);
}
}

0 comments on commit a47f47c

Please sign in to comment.