Skip to content

Commit

Permalink
Merge pull request #107 from b13/task/v13
Browse files Browse the repository at this point in the history
!!! [TASK] change requirements
  • Loading branch information
achimfritz authored Aug 1, 2024
2 parents 355780f + fcfe3d5 commit b9c971f
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 180 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ jobs:
php: [ '7.4', '8.0', '8.1' ]
TYPO3: [ '11' ]
include:
- TYPO3: '10'
php: '7.4'
- TYPO3: '12'
php: '8.1'
- TYPO3: '13'
php: '8.3'
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Patch 10
if: matrix.TYPO3 == '10'
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t ${{ matrix.TYPO3 }} -s patchV10

- name: Install testing system
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -t ${{ matrix.TYPO3 }} -s composerInstall

Expand Down
6 changes: 0 additions & 6 deletions Build/Scripts/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@ case ${TEST_SUITE} in
SUITE_EXIT_CODE=$?
docker-compose down
;;
patchV10)
setUpDockerComposeDotEnv
docker-compose run patchV10
SUITE_EXIT_CODE=$?
docker-compose down
;;
functional)
setUpDockerComposeDotEnv
case ${DBMS} in
Expand Down
11 changes: 0 additions & 11 deletions Build/phpstan10.neon

This file was deleted.

12 changes: 12 additions & 0 deletions Build/phpstan11.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@ parameters:
paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests
excludePaths:
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
ignoreErrors:
-
message: '#Cannot call method getLanguageCode\(\) on string.#'
path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php
-
message: '#Class TYPO3\\CMS\\Frontend\\Cache\\CacheLifetimeCalculator not found.#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
-
message: '#.*unknown class TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript.#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
6 changes: 5 additions & 1 deletion Build/phpstan12.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ parameters:
paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests

excludePaths:
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
ignoreErrors:
-
message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#'
path: %currentWorkingDirectory%/Classes/ContentObject/*
-
message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#'
path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php
-
message: '#Call to an undefined method TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript::getConfigArray\(\).#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
27 changes: 27 additions & 0 deletions Build/phpstan13.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
parameters:
level: 5

paths:
- %currentWorkingDirectory%/Classes
- %currentWorkingDirectory%/Tests
excludePaths:
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
ignoreErrors:
-
message: '#Call to an undefined method TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage::getTwoLetterIsoCode\(\).#'
path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php
-
message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#'
path: %currentWorkingDirectory%/Classes/Domain/Repository/MenuRepository.php
-
message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#'
path: %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
-
message: '#.*get_cache_timeout\(\).*#'
path: %currentWorkingDirectory%/Classes/CacheHelper.php
-
message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#'
path: %currentWorkingDirectory%/Classes/ContentObject/*
-
message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#'
path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php
31 changes: 4 additions & 27 deletions Build/phpunit/UnitTestsBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,9 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Information\Typo3Version;

call_user_func(function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();

// These if's are for core testing (package typo3/cms) only. cms-composer-installer does
// not create the autoload-include.php file that sets these env vars and sets composer
// mode to true. testing-framework can not be used without composer anyway, so it is safe
// to do this here. This way it does not matter if 'bin/phpunit' or 'vendor/phpunit/phpunit/phpunit'
// is called to run the tests since the 'relative to entry script' path calculation within
// SystemEnvironmentBuilder is not used. However, the binary must be called from the document
// root since getWebRoot() uses 'getcwd()'.
if (!getenv('TYPO3_PATH_ROOT')) {
putenv('TYPO3_PATH_ROOT=' . rtrim($testbase->getWebRoot(), '/'));
}
if (!getenv('TYPO3_PATH_WEB')) {
putenv('TYPO3_PATH_WEB=' . rtrim($testbase->getWebRoot(), '/'));
}

$testbase->defineSitePath();

$requestType = \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE | \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI;
Expand All @@ -54,17 +38,10 @@
new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production', [])
);
// Set all packages to active
if (version_compare((new Typo3Version())->getVersion(), '11.3.0', '>')) {
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
\TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache)
);
} else {
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
$cache
);
}
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
\TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache)
);
\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager);

Expand Down
31 changes: 5 additions & 26 deletions Build/testing-docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,17 @@ services:
fi
php -v | grep '^PHP';
if [ ${TYPO3} -eq 11 ]; then
composer install --no-progress --no-interaction
composer require typo3/cms-install:^11.5 typo3/cms-fluid-styled-content:^11.5 --dev -W --no-progress --no-interaction
composer prepare-tests
elif [ ${TYPO3} -eq 10 ]; then
composer require friendsofphp/php-cs-fixer:^3.4 typo3/cms-install:^10.4 typo3/cms-fluid-styled-content:^10.4 typo3/testing-framework:^6 --dev -W --no-progress --no-interaction
if [ "${PHP_VERSION}" == "7.4" ]; then
composer require friendsofphp/php-cs-fixer:~3.9.0 --dev --no-progress --no-interaction
fi
composer prepare-tests-10 && composer prepare-tests
else
elif [ ${TYPO3} -eq 12 ]; then
composer require typo3/cms-install:^12.4 typo3/cms-fluid-styled-content:^12.4 --dev -W --no-progress --no-interaction
composer prepare-tests
else
composer install --no-progress --no-interaction
composer prepare-tests
fi
"
patchV10:
image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
user: ${HOST_UID}
volumes:
- ${ROOT_DIR}:${ROOT_DIR}
- ${HOST_HOME}:${HOST_HOME}
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
working_dir: ${ROOT_DIR}
command: >
/bin/sh -c "
find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)testExtensionsToLoad = \[/protected \1testExtensionsToLoad = [/g';
find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected bool \(.*\)resetSingletonInstances = /protected \1resetSingletonInstances = /g';
find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)coreExtensionsToLoad = \[/protected \1coreExtensionsToLoad = [/g';
find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)pathsToLinkInTestInstance = \[/protected \1pathsToLinkInTestInstance = [/g';
find Tests -name \\*.php -print0 | xargs -0 sed -i 's/protected array \(.*\)configurationToUseInTestInstance = \[/protected \1configurationToUseInTestInstance = [/g';
"
composer_validate:
image: typo3/core-testing-${DOCKER_PHP_IMAGE}:latest
user: ${HOST_UID}
Expand Down
62 changes: 59 additions & 3 deletions Classes/CacheHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
* of the License, or any later version.
*/

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
Expand All @@ -27,9 +32,11 @@ class CacheHelper implements SingletonInterface
{
protected FrontendInterface $cache;
protected bool $disableCaching = false;
protected Context $context;

public function __construct(FrontendInterface $cache, Context $context)
{
$this->context = $context;
$this->cache = $cache;
try {
$this->disableCaching = $context->getPropertyFromAspect('workspace', 'id', 0) > 0;
Expand Down Expand Up @@ -63,7 +70,8 @@ public function get(string $cacheIdentifier, callable $loader): array

// Calculate tags + lifetime
$tags = $this->buildTagsAndAddThemToPageCache($pages);
$maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $this->getFrontendController()->get_cache_timeout());
$defaultMaxLifeTime = $this->getDefaultMaxLifeTime();
$maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $defaultMaxLifeTime);
$this->cache->set($cacheIdentifier, $pages, $tags, $maximumLifeTime);
return $pages;
}
Expand Down Expand Up @@ -108,15 +116,58 @@ protected function getAllPageIdsFromItems(array $pages): array
return $pageIds;
}

protected function getDefaultMaxLifeTime(): int
{
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
$maxLifetime = (int)$this->getFrontendController()->get_cache_timeout();
} else {
$request = $this->getServerRequest();
$pageInformation = $request->getAttribute('frontend.page.information');
/** @var ?FrontendTypoScript $typoScript */
$typoScript = $request->getAttribute('frontend.typoscript');
if ($typoScript === null || $pageInformation === null) {
return 0;
}
$typoScriptConfigArray = $typoScript->getConfigArray();
$maxLifetime = GeneralUtility::makeInstance(CacheLifetimeCalculator::class)
->calculateLifetimeForPage(
$pageInformation->getId(),
$pageInformation->getPageRecord(),
$typoScriptConfigArray,
0,
$this->context
);
}
return $maxLifetime;
}

/**
* pages.cache_timeout is not used here, as this is supposed to be relevant for content of a page, not the
* metadata.
*/
protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null): ?int
protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime): int
{
foreach ($pages as $page) {
if (!empty($page['endtime'])) {
$maxLifetimeOfPage = $page['endtime'] - $GLOBALS['EXEC_TIME'];
$maxLifetimeOfPage = (int)$page['endtime'] - $GLOBALS['EXEC_TIME'];
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() === 13) {
$request = $this->getServerRequest();
/** @var ?FrontendTypoScript $typoScript */
$typoScript = $request->getAttribute('frontend.typoscript');
if ($typoScript === null) {
$typoScriptConfigArray = [];
} else {
$typoScriptConfigArray = $typoScript->getConfigArray();
}
$maxLifetimeOfPage = GeneralUtility::makeInstance(CacheLifetimeCalculator::class)
->calculateLifetimeForPage(
$page['uid'],
$page,
$typoScriptConfigArray,
0,
$this->context
);
}
if ($maxLifetimeOfPage < $maxLifetime) {
$maxLifetime = $maxLifetimeOfPage;
}
Expand All @@ -128,6 +179,11 @@ protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null):
return $maxLifetime;
}

protected function getServerRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}

protected function getFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
Expand Down
12 changes: 11 additions & 1 deletion Classes/Compiler/LanguageMenuCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspectFactory;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

Expand All @@ -38,7 +40,7 @@ public function compile(ContentObjectRenderer $contentObjectRenderer, array $con
$context = clone GeneralUtility::makeInstance(Context::class);
$pages = [];
foreach ($site->getLanguages() as $language) {
if (in_array($language->getTwoLetterIsoCode(), $excludedLanguages, true)) {
if (in_array($this->getLanguageCode($language), $excludedLanguages, true)) {
continue;
}
if (in_array((string)$language->getLanguageId(), $excludedLanguages, true)) {
Expand All @@ -62,4 +64,12 @@ public function compile(ContentObjectRenderer $contentObjectRenderer, array $con
return $pages;
});
}

protected function getLanguageCode(SiteLanguage $language): string
{
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() === 11) {
return $language->getTwoLetterIsoCode();
}
return $language->getLocale()->getLanguageCode();
}
}
5 changes: 4 additions & 1 deletion Classes/Domain/Repository/MenuRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\LanguageAspect;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand All @@ -31,7 +32,6 @@ class MenuRepository
// Never show or query them.
protected $excludedDoktypes = [
PageRepository::DOKTYPE_BE_USER_SECTION,
PageRepository::DOKTYPE_RECYCLER,
PageRepository::DOKTYPE_SYSFOLDER,
];

Expand All @@ -40,6 +40,9 @@ public function __construct(Context $context, PageRepository $pageRepository, Ev
$this->context = $context;
$this->pageRepository = $pageRepository;
$this->eventDispatcher = $eventDispatcher;
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
$this->excludedDoktypes[] = PageRepository::DOKTYPE_RECYCLER;
}
}

public function getBreadcrumbsMenu(array $originalRootLine, array $configuration): array
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/DataProcessing/BreadcrumbsMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

class BreadcrumbsMenuTest extends DataProcessingTest
class BreadcrumbsMenuTest extends DataProcessing
{
/**
* @return array
*/
public function setupDataProvider()
public static function setupDataProvider()
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

abstract class DataProcessingTest extends FunctionalTestCase
abstract class DataProcessing extends FunctionalTestCase
{
protected array $testExtensionsToLoad = ['typo3conf/ext/menus'];

Expand Down
Loading

0 comments on commit b9c971f

Please sign in to comment.