From 68c0e06e3fe7c09de44660cfa7034622f8f3cdd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Tue, 9 Jul 2024 12:46:43 +0200 Subject: [PATCH] [FIX] tests for TYPO3 13 @ 2024.07.09 Relates: #3995 --- .../UpdateHandler/AbstractUpdateHandler.php | 22 ++++++++++ .../Queue/UpdateHandler/DataUpdateHandler.php | 22 ---------- .../Queue/UpdateHandler/GarbageHandler.php | 8 +++- Tests/Integration/GarbageCollectorTest.php | 42 ++++--------------- .../UpdateHandler/DataUpdateHandlerTest.php | 2 +- .../UpdateHandler/GarbageHandlerTest.php | 16 ++++--- 6 files changed, 48 insertions(+), 64 deletions(-) diff --git a/Classes/Domain/Index/Queue/UpdateHandler/AbstractUpdateHandler.php b/Classes/Domain/Index/Queue/UpdateHandler/AbstractUpdateHandler.php index aa777c38ce..d7d3dc6c43 100644 --- a/Classes/Domain/Index/Queue/UpdateHandler/AbstractUpdateHandler.php +++ b/Classes/Domain/Index/Queue/UpdateHandler/AbstractUpdateHandler.php @@ -23,6 +23,7 @@ use ApacheSolrForTypo3\Solr\System\Records\Pages\PagesRepository; use ApacheSolrForTypo3\Solr\System\TCA\TCAService; use Doctrine\DBAL\Exception as DBALException; +use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -279,4 +280,25 @@ protected function getQueryBuilderForTable(string $table): QueryBuilder return $this->queryBuilders[$table]; } + + /** + * Wraps {@link BackendUtility::getRecord()} + * + * Purpose: Unit-Tests + */ + protected function getRecord( + string $table, + int|string $uid, + string $fields = '*', + string $where = '', + bool $useDeleteClause = true, + ): ?array { + return BackendUtility::getRecord( + $table, + $uid, + $fields, + $where, + $useDeleteClause, + ); + } } diff --git a/Classes/Domain/Index/Queue/UpdateHandler/DataUpdateHandler.php b/Classes/Domain/Index/Queue/UpdateHandler/DataUpdateHandler.php index 613f246834..3299d077b8 100644 --- a/Classes/Domain/Index/Queue/UpdateHandler/DataUpdateHandler.php +++ b/Classes/Domain/Index/Queue/UpdateHandler/DataUpdateHandler.php @@ -33,7 +33,6 @@ use ApacheSolrForTypo3\Solr\Util; use Doctrine\DBAL\Exception as DBALException; use Throwable; -use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -548,25 +547,4 @@ protected function getSiteRepository(): SiteRepository { return GeneralUtility::makeInstance(SiteRepository::class); } - - /** - * Wraps {@link BackendUtility::getRecord()} - * - * Purpose: Unit-Tests - */ - protected function getRecord( - string $table, - int|string $uid, - string $fields = '*', - string $where = '', - bool $useDeleteClause = true, - ): ?array { - return BackendUtility::getRecord( - $table, - $uid, - $fields, - $where, - $useDeleteClause, - ); - } } diff --git a/Classes/Domain/Index/Queue/UpdateHandler/GarbageHandler.php b/Classes/Domain/Index/Queue/UpdateHandler/GarbageHandler.php index 1d516410b6..58daa43cd0 100644 --- a/Classes/Domain/Index/Queue/UpdateHandler/GarbageHandler.php +++ b/Classes/Domain/Index/Queue/UpdateHandler/GarbageHandler.php @@ -125,7 +125,13 @@ public function performRecordGarbageCheck( } if ($table === 'pages') { - $this->deleteSubEntriesWhenRecursiveTriggerIsRecognized($table, $uid, $updatedFields); + // We need to get the full record to find out if this is a page translation + $fullRecord = $this->getRecord('pages', $uid); + $uidForRecursiveTriggers = $uid; + if (($fullRecord['sys_language_uid'] ?? null) > 0) { + $uidForRecursiveTriggers = (int)$fullRecord['l10n_parent']; + } + $this->deleteSubEntriesWhenRecursiveTriggerIsRecognized($table, $uidForRecursiveTriggers, $updatedFields); } $record = $this->tcaService->normalizeFrontendGroupField($table, $record); diff --git a/Tests/Integration/GarbageCollectorTest.php b/Tests/Integration/GarbageCollectorTest.php index 1ef206e1fb..db5781c2df 100644 --- a/Tests/Integration/GarbageCollectorTest.php +++ b/Tests/Integration/GarbageCollectorTest.php @@ -47,41 +47,13 @@ class GarbageCollectorTest extends IntegrationTestBase '../vendor/apache-solr-for-typo3/solr/Tests/Integration/Fixtures/Extensions/fake_extension', ]; - /** - * @var RecordMonitor - */ - protected $recordMonitor; - - /** - * @var DataHandler - */ - protected $dataHandler; - - /** - * @var Queue - */ - protected $indexQueue; - - /** - * @var GarbageCollector - */ - protected $garbageCollector; - - /** - * @var Indexer - */ - protected $indexer; - - /** - * @var ExtensionConfiguration - */ - protected $extensionConfiguration; - - /** - * @var EventQueueItemRepository - */ - protected $eventQueue; - + protected RecordMonitor $recordMonitor; + protected DataHandler $dataHandler; + protected Queue $indexQueue; + protected GarbageCollector $garbageCollector; + protected Indexer $indexer; + protected ExtensionConfiguration $extensionConfiguration; + protected EventQueueItemRepository $eventQueue; protected BackendUserAuthentication $backendUser; protected function setUp(): void diff --git a/Tests/Unit/Domain/Index/Queue/UpdateHandler/DataUpdateHandlerTest.php b/Tests/Unit/Domain/Index/Queue/UpdateHandler/DataUpdateHandlerTest.php index 25863c7541..b6d8842049 100644 --- a/Tests/Unit/Domain/Index/Queue/UpdateHandler/DataUpdateHandlerTest.php +++ b/Tests/Unit/Domain/Index/Queue/UpdateHandler/DataUpdateHandlerTest.php @@ -70,7 +70,7 @@ protected function setUp(): void $this->pagesRepositoryMock, $this->dataHandlerMock, $this->loggerMock, - ] + ], ); $this->dataUpdateHandler ->expects(self::any()) diff --git a/Tests/Unit/Domain/Index/Queue/UpdateHandler/GarbageHandlerTest.php b/Tests/Unit/Domain/Index/Queue/UpdateHandler/GarbageHandlerTest.php index 7ecb67ea34..de4a0da1b6 100644 --- a/Tests/Unit/Domain/Index/Queue/UpdateHandler/GarbageHandlerTest.php +++ b/Tests/Unit/Domain/Index/Queue/UpdateHandler/GarbageHandlerTest.php @@ -34,11 +34,17 @@ class GarbageHandlerTest extends SetUpUpdateHandler protected function setUp(): void { parent::setUp(); - $this->garbageHandler = new GarbageHandler( - $this->recordServiceMock, - $this->frontendEnvironmentMock, - $this->tcaServiceMock, - $this->indexQueueMock + $this->garbageHandler = $this->getAccessibleMock( + GarbageHandler::class, + [ + 'getRecord', + ], + [ + $this->recordServiceMock, + $this->frontendEnvironmentMock, + $this->tcaServiceMock, + $this->indexQueueMock, + ], ); }