Skip to content

Commit 68b3d21

Browse files
committed
Merge branch 'main' into task/docker-composer-v2
2 parents e9dc7bd + 3f32491 commit 68b3d21

File tree

71 files changed

+1235
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1235
-502
lines changed

.github/workflows/ci.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
php: [ '7.4', '7.3', '7.2' ]
17-
TYPO3: [ '10' ]
16+
php: [ '7.4', '8.0', '8.1' ]
17+
TYPO3: [ '11' ]
1818
include:
19-
- TYPO3: '11'
19+
- TYPO3: '12'
2020
php: '8.1'
21-
- TYPO3: '11'
22-
php: '8.0'
23-
- TYPO3: '11'
24-
php: '7.4'
21+
- TYPO3: '13'
22+
php: '8.3'
2523
steps:
2624
- name: Checkout
2725
uses: actions/checkout@v2

Build/phpstan10.neon

-14
This file was deleted.

Build/phpstan11.neon

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ parameters:
44
paths:
55
- %currentWorkingDirectory%/Classes
66
- %currentWorkingDirectory%/Tests
7-
7+
excludePaths:
8+
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
89
ignoreErrors:
910
-
10-
message: '#.*TYPO3\\CMS\\Frontend\\Page\\PageRepository.*#'
11-
path: %currentWorkingDirectory%/Classes/Domain/Repository/MenuRepository.php
11+
message: '#Cannot call method getLanguageCode\(\) on string.#'
12+
path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php
1213
-
13-
message: '#Constant ORIGINAL_ROOT not found.#'
14-
path: %currentWorkingDirectory%/Tests
14+
message: '#Class TYPO3\\CMS\\Frontend\\Cache\\CacheLifetimeCalculator not found.#'
15+
path: %currentWorkingDirectory%/Classes/CacheHelper.php
1516
-
16-
message: '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::.*#'
17-
path: %currentWorkingDirectory%/Tests
17+
message: '#.*unknown class TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript.#'
18+
path: %currentWorkingDirectory%/Classes/CacheHelper.php

Build/phpstan12.neon

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
parameters:
2+
level: 5
3+
4+
paths:
5+
- %currentWorkingDirectory%/Classes
6+
- %currentWorkingDirectory%/Tests
7+
excludePaths:
8+
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
9+
ignoreErrors:
10+
-
11+
message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#'
12+
path: %currentWorkingDirectory%/Classes/ContentObject/*
13+
-
14+
message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#'
15+
path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php
16+
-
17+
message: '#Call to an undefined method TYPO3\\CMS\\Core\\TypoScript\\FrontendTypoScript::getConfigArray\(\).#'
18+
path: %currentWorkingDirectory%/Classes/CacheHelper.php

Build/phpstan13.neon

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
parameters:
2+
level: 5
3+
4+
paths:
5+
- %currentWorkingDirectory%/Classes
6+
- %currentWorkingDirectory%/Tests
7+
excludePaths:
8+
- %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
9+
ignoreErrors:
10+
-
11+
message: '#Call to an undefined method TYPO3\\CMS\\Core\\Site\\Entity\\SiteLanguage::getTwoLetterIsoCode\(\).#'
12+
path: %currentWorkingDirectory%/Classes/Compiler/LanguageMenuCompiler.php
13+
-
14+
message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#'
15+
path: %currentWorkingDirectory%/Classes/Domain/Repository/MenuRepository.php
16+
-
17+
message: '#Access to undefined constant TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::DOKTYPE_RECYCLER.#'
18+
path: %currentWorkingDirectory%/Tests/Unit/Domain/Repository/MenuRepositoryTest.php
19+
-
20+
message: '#.*get_cache_timeout\(\).*#'
21+
path: %currentWorkingDirectory%/Classes/CacheHelper.php
22+
-
23+
message: '#Call to an undefined static method TYPO3\\CMS\\Frontend\\ContentObject\\AbstractContentObject::__construct\(\).#'
24+
path: %currentWorkingDirectory%/Classes/ContentObject/*
25+
-
26+
message: '#Property TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController::\$id \(int\) does not accept string.#'
27+
path: %currentWorkingDirectory%/Tests/Functional/Compiler/LanguageMenuCompilerTest.php

Build/phpunit/FunctionalTests.xml

-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@
2424
<const name="TYPO3_MODE" value="BE" />
2525
<ini name="display_errors" value="1" />
2626
<env name="TYPO3_CONTEXT" value="Testing" />
27-
<const name="TYPO3_TESTING_FUNCTIONAL_REMOVE_ERROR_HANDLER" value="true" />
2827
</php>
2928
</phpunit>

Build/phpunit/UnitTestsBootstrap.php

+4-30
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,9 @@
1212
* The TYPO3 project - inspiring people to share!
1313
*/
1414

15-
use TYPO3\CMS\Core\Information\Typo3Version;
16-
1715
call_user_func(function () {
18-
if (!class_exists(\TYPO3\CMS\Frontend\Page\PageRepository::class)) {
19-
class_alias(\TYPO3\CMS\Core\Domain\Repository\PageRepository::class, \TYPO3\CMS\Frontend\Page\PageRepository::class);
20-
}
2116
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
2217

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

3920
$requestType = \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE | \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_CLI;
@@ -57,17 +38,10 @@ class_alias(\TYPO3\CMS\Core\Domain\Repository\PageRepository::class, \TYPO3\CMS\
5738
new \TYPO3\CMS\Core\Cache\Backend\NullBackend('production', [])
5839
);
5940
// Set all packages to active
60-
if (version_compare((new Typo3Version())->getVersion(), '11.3.0', '>')) {
61-
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
62-
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
63-
\TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache)
64-
);
65-
} else {
66-
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
67-
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
68-
$cache
69-
);
70-
}
41+
$packageManager = \TYPO3\CMS\Core\Core\Bootstrap::createPackageManager(
42+
\TYPO3\CMS\Core\Package\UnitTestPackageManager::class,
43+
\TYPO3\CMS\Core\Core\Bootstrap::createPackageCache($cache)
44+
);
7145
\TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Package\PackageManager::class, $packageManager);
7246
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::setPackageManager($packageManager);
7347

Build/testing-docker/docker-compose.yml

+14-9
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ services:
8282
set -x
8383
fi
8484
php -v | grep '^PHP';
85-
if [ ${TYPO3} -eq 10 ]; then
86-
composer install --no-progress --no-interaction;
85+
if [ ${TYPO3} -eq 11 ]; then
86+
composer require typo3/cms-install:^11.5 typo3/cms-fluid-styled-content:^11.5 --dev -W --no-progress --no-interaction
87+
composer prepare-tests
88+
elif [ ${TYPO3} -eq 12 ]; then
89+
composer require typo3/cms-install:^12.4 typo3/cms-fluid-styled-content:^12.4 --dev -W --no-progress --no-interaction
90+
composer prepare-tests
8791
else
88-
composer remove typo3/cms* --dev --no-progress --no-interaction && composer require typo3/cms-install:^11.5 typo3/cms-fluid-styled-content:^11.5 --dev -W --no-progress --no-interaction
92+
composer install --no-progress --no-interaction
93+
composer prepare-tests
8994
fi
9095
"
9196
@@ -122,7 +127,7 @@ services:
122127
typo3DatabaseUsername: root
123128
typo3DatabasePassword: funcp
124129
typo3DatabaseHost: mariadb10
125-
working_dir: ${ROOT_DIR}/.Build
130+
working_dir: ${ROOT_DIR}
126131
command: >
127132
/bin/sh -c "
128133
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
@@ -136,13 +141,13 @@ services:
136141
php -v | grep '^PHP';
137142
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
138143
export XDEBUG_MODE=\"off\"
139-
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
144+
.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
140145
else
141146
DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
142147
export XDEBUG_MODE=\"debug,develop\" \
143148
XDEBUG_TRIGGER=\"foo\" \
144149
XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\"
145-
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
150+
.Build/bin/phpunit -c Build/phpunit/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
146151
fi
147152
"
148153
lint:
@@ -188,7 +193,7 @@ services:
188193
- ${HOST_HOME}:${HOST_HOME}
189194
- /etc/passwd:/etc/passwd:ro
190195
- /etc/group:/etc/group:ro
191-
working_dir: ${ROOT_DIR}/.Build
196+
working_dir: ${ROOT_DIR}
192197
command: >
193198
/bin/sh -c "
194199
if [ ${SCRIPT_VERBOSE} -eq 1 ]; then
@@ -197,12 +202,12 @@ services:
197202
php -v | grep '^PHP';
198203
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
199204
XDEBUG_MODE=\"off\" \
200-
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
205+
.Build/bin/phpunit -c Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
201206
else
202207
DOCKER_HOST=`route -n | awk '/^0.0.0.0/ { print $$2 }'`
203208
XDEBUG_MODE=\"debug,develop\" \
204209
XDEBUG_TRIGGER=\"foo\" \
205210
XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=$${DOCKER_HOST}\" \
206-
bin/phpunit -c Web/typo3conf/ext/menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
211+
.Build/bin/phpunit -c menus/Build/phpunit/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
207212
fi
208213
"

Classes/CacheHelper.php

+61-26
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
* of the License, or any later version.
1212
*/
1313

14-
use TYPO3\CMS\Core\Cache\CacheManager;
14+
use Psr\Http\Message\ServerRequestInterface;
1515
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
1616
use TYPO3\CMS\Core\Context\Context;
1717
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
1818
use TYPO3\CMS\Core\Information\Typo3Version;
1919
use TYPO3\CMS\Core\SingletonInterface;
20+
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
2021
use TYPO3\CMS\Core\Utility\GeneralUtility;
22+
use TYPO3\CMS\Frontend\Cache\CacheLifetimeCalculator;
2123
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
2224

2325
/**
@@ -28,23 +30,14 @@
2830
*/
2931
class CacheHelper implements SingletonInterface
3032
{
31-
/**
32-
* @var FrontendInterface
33-
*/
34-
protected $cache;
35-
36-
protected $disableCaching = false;
33+
protected FrontendInterface $cache;
34+
protected bool $disableCaching = false;
35+
protected Context $context;
3736

38-
public function __construct(FrontendInterface $cache = null, Context $context = null)
37+
public function __construct(FrontendInterface $cache, Context $context)
3938
{
40-
if ((new Typo3Version())->getMajorVersion() < 10) {
41-
$this->cache = $cache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_hash');
42-
} else {
43-
$this->cache = $cache ?? GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
44-
}
45-
if ($context === null) {
46-
$context = GeneralUtility::makeInstance(Context::class);
47-
}
39+
$this->context = $context;
40+
$this->cache = $cache;
4841
try {
4942
$this->disableCaching = $context->getPropertyFromAspect('workspace', 'id', 0) > 0;
5043
} catch (AspectNotFoundException $e) {
@@ -60,10 +53,6 @@ public function __construct(FrontendInterface $cache = null, Context $context =
6053
/**
6154
* Looks up the items inside the cache, if it exists, takes the cached entry, otherwise computes the data
6255
* via the $loader().
63-
*
64-
* @param string $cacheIdentifier
65-
* @param callable $loader
66-
* @return array
6756
*/
6857
public function get(string $cacheIdentifier, callable $loader): array
6958
{
@@ -81,7 +70,8 @@ public function get(string $cacheIdentifier, callable $loader): array
8170

8271
// Calculate tags + lifetime
8372
$tags = $this->buildTagsAndAddThemToPageCache($pages);
84-
$maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $this->getFrontendController()->get_cache_timeout());
73+
$defaultMaxLifeTime = $this->getDefaultMaxLifeTime();
74+
$maximumLifeTime = $this->getMaxLifetimeOfPages($pages, $defaultMaxLifeTime);
8575
$this->cache->set($cacheIdentifier, $pages, $tags, $maximumLifeTime);
8676
return $pages;
8777
}
@@ -126,15 +116,58 @@ protected function getAllPageIdsFromItems(array $pages): array
126116
return $pageIds;
127117
}
128118

119+
protected function getDefaultMaxLifeTime(): int
120+
{
121+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 13) {
122+
$maxLifetime = (int)$this->getFrontendController()->get_cache_timeout();
123+
} else {
124+
$request = $this->getServerRequest();
125+
$pageInformation = $request->getAttribute('frontend.page.information');
126+
/** @var ?FrontendTypoScript $typoScript */
127+
$typoScript = $request->getAttribute('frontend.typoscript');
128+
if ($typoScript === null || $pageInformation === null) {
129+
return 0;
130+
}
131+
$typoScriptConfigArray = $typoScript->getConfigArray();
132+
$maxLifetime = GeneralUtility::makeInstance(CacheLifetimeCalculator::class)
133+
->calculateLifetimeForPage(
134+
$pageInformation->getId(),
135+
$pageInformation->getPageRecord(),
136+
$typoScriptConfigArray,
137+
0,
138+
$this->context
139+
);
140+
}
141+
return $maxLifetime;
142+
}
143+
129144
/**
130145
* pages.cache_timeout is not used here, as this is supposed to be relevant for content of a page, not the
131146
* metadata.
132147
*/
133-
protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null): ?int
148+
protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime): int
134149
{
135150
foreach ($pages as $page) {
136151
if (!empty($page['endtime'])) {
137-
$maxLifetimeOfPage = $page['endtime'] - $GLOBALS['EXEC_TIME'];
152+
$maxLifetimeOfPage = (int)$page['endtime'] - $GLOBALS['EXEC_TIME'];
153+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() === 13) {
154+
$request = $this->getServerRequest();
155+
/** @var ?FrontendTypoScript $typoScript */
156+
$typoScript = $request->getAttribute('frontend.typoscript');
157+
if ($typoScript === null) {
158+
$typoScriptConfigArray = [];
159+
} else {
160+
$typoScriptConfigArray = $typoScript->getConfigArray();
161+
}
162+
$maxLifetimeOfPage = GeneralUtility::makeInstance(CacheLifetimeCalculator::class)
163+
->calculateLifetimeForPage(
164+
$page['uid'],
165+
$page,
166+
$typoScriptConfigArray,
167+
0,
168+
$this->context
169+
);
170+
}
138171
if ($maxLifetimeOfPage < $maxLifetime) {
139172
$maxLifetime = $maxLifetimeOfPage;
140173
}
@@ -146,9 +179,11 @@ protected function getMaxLifetimeOfPages(array $pages, int $maxLifetime = null):
146179
return $maxLifetime;
147180
}
148181

149-
/**
150-
* @return TypoScriptFrontendController
151-
*/
182+
protected function getServerRequest(): ServerRequestInterface
183+
{
184+
return $GLOBALS['TYPO3_REQUEST'];
185+
}
186+
152187
protected function getFrontendController(): TypoScriptFrontendController
153188
{
154189
return $GLOBALS['TSFE'];

0 commit comments

Comments
 (0)