From c3d9db33b4e33509b638836338dd483cd7172eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Tue, 17 Sep 2024 03:22:45 +0200 Subject: [PATCH] [FIX] Translation handling by delegating requered context objects/values This change fixes the context losts by TSFE/ContentObjectRenderer stack for translations. Now is the language delegated directly or via reques object, instead of previously core context object. Relates: #3995 --- Classes/ContentObject/Relation.php | 53 ++++++++--- Classes/FrontendEnvironment.php | 9 +- Classes/IndexQueue/AbstractIndexer.php | 44 ++++++++- Classes/IndexQueue/Indexer.php | 8 +- .../Configuration/ConfigurationManager.php | 95 ++++++++++++++++--- .../ContentObject/RelationTest.php | 13 ++- Tests/Integration/IndexQueue/IndexerTest.php | 36 +------ Tests/Unit/IndexQueue/AbstractIndexerTest.php | 3 +- 8 files changed, 187 insertions(+), 74 deletions(-) diff --git a/Classes/ContentObject/Relation.php b/Classes/ContentObject/Relation.php index d381bff455..4ad6ea0d23 100644 --- a/Classes/ContentObject/Relation.php +++ b/Classes/ContentObject/Relation.php @@ -20,6 +20,8 @@ use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Result; use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; +use TYPO3\CMS\Core\Context\LanguageAspectFactory; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Database\RelationHandler; @@ -70,6 +72,7 @@ public function __construct( * * @throws ContentRenderingException * @throws DBALException + * @throws AspectNotFoundException * * @noinspection PhpMissingReturnTypeInspection, because foreign source inheritance See {@link AbstractContentObject::render()} */ @@ -104,6 +107,7 @@ public function render($conf = []) * * @throws ContentRenderingException * @throws DBALException + * @throws AspectNotFoundException */ protected function getRelatedItems(ContentObjectRenderer $parentContentObject): array { @@ -115,11 +119,16 @@ protected function getRelatedItems(ContentObjectRenderer $parentContentObject): return []; } - $overlayUid = $this->getFrontendOverlayService()->getUidOfOverlay($table, $field, $uid); + $overlayUid = $this->getFrontendOverlayService($parentContentObject)->getUidOfOverlay($table, $field, $uid); $fieldTCA = $this->tcaService->getConfigurationForField($table, $field); if (isset($fieldTCA['config']['MM']) && trim($fieldTCA['config']['MM']) !== '') { - $relatedItems = $this->getRelatedItemsFromMMTable($table, $overlayUid, $fieldTCA); + $relatedItems = $this->getRelatedItemsFromMMTable( + $table, + $overlayUid, + $fieldTCA, + $parentContentObject, + ); } else { $relatedItems = $this->getRelatedItemsFromForeignTable($table, $overlayUid, $fieldTCA, $parentContentObject); } @@ -138,9 +147,14 @@ protected function getRelatedItems(ContentObjectRenderer $parentContentObject): * * @throws ContentRenderingException * @throws DBALException + * @throws AspectNotFoundException */ - protected function getRelatedItemsFromMMTable(string $localTableName, int $localRecordUid, array $localFieldTca): array - { + protected function getRelatedItemsFromMMTable( + string $localTableName, + int $localRecordUid, + array $localFieldTca, + ContentObjectRenderer $parentContentObject, + ): array { $relatedItems = []; $foreignTableName = $localFieldTca['config']['foreign_table']; $foreignTableTca = $this->tcaService->getTableConfiguration($foreignTableName); @@ -161,7 +175,9 @@ protected function getRelatedItemsFromMMTable(string $localTableName, int $local return $relatedItems; } + /** @var ContentObjectRenderer $contentObject */ $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class); + $contentObject->setRequest($parentContentObject->getRequest()); $relatedRecords = $this->getRelatedRecords($foreignTableName, ...$selectUids); foreach ($relatedRecords as $record) { $contentObject->start($record, $foreignTableName); @@ -181,8 +197,9 @@ protected function getRelatedItemsFromMMTable(string $localTableName, int $local $relatedItems = array_merge($relatedItems, $this->getRelatedItems($contentObject)); continue; } - if ($this->getLanguageUid() > 0) { - $record = $this->getFrontendOverlayService()->getOverlay($foreignTableName, $record); + if ($this->getLanguageUid($parentContentObject) > 0) { + $record = $this->getFrontendOverlayService($parentContentObject) + ->getOverlay($foreignTableName, $record); } $relatedItems[] = $contentObject->stdWrap($record[$foreignTableLabelField] ?? '', $this->configuration) ?? ''; @@ -303,8 +320,8 @@ protected function resolveRelatedValue( ContentObjectRenderer $parentContentObject, string $foreignTableName = '' ): array { - if ($this->getLanguageUid() > 0 && !empty($foreignTableName)) { - $relatedRecord = $this->getFrontendOverlayService()->getOverlay($foreignTableName, $relatedRecord); + if ($this->getLanguageUid($parentContentObject) > 0 && !empty($foreignTableName)) { + $relatedRecord = $this->getFrontendOverlayService($parentContentObject)->getOverlay($foreignTableName, $relatedRecord); } $contentObject = clone $parentContentObject; @@ -396,25 +413,37 @@ protected function sortByKeyInIN(Result $statement, string $columnName, ...$arra /** * Returns current language id fetched from the Context + * + * @throws ContentRenderingException */ - protected function getLanguageUid(): int + protected function getLanguageUid(ContentObjectRenderer $parentContentObject): int { - return GeneralUtility::makeInstance(Context::class)->getAspect('language')->get('id'); + return $parentContentObject + ->getRequest() + ->getAttribute('language') + ->getLanguageId(); } /** * Returns and sets FrontendOverlayService instance to this object. + * + * @throws ContentRenderingException */ - protected function getFrontendOverlayService(): FrontendOverlayService + protected function getFrontendOverlayService(ContentObjectRenderer $parentContentObject): FrontendOverlayService { if ($this->frontendOverlayService !== null) { return $this->frontendOverlayService; } + $siteLanguage = $parentContentObject->getRequest()->getAttribute('language'); + + /** @var Context $coreContext */ + $coreContext = clone GeneralUtility::makeInstance(Context::class); + $coreContext->setAspect('language', LanguageAspectFactory::createFromSiteLanguage($siteLanguage)); return $this->frontendOverlayService = GeneralUtility::makeInstance( FrontendOverlayService::class, $this->tcaService, - GeneralUtility::makeInstance(Context::class) + $coreContext, ); } } diff --git a/Classes/FrontendEnvironment.php b/Classes/FrontendEnvironment.php index 9f79eea4f6..56fbec14ba 100644 --- a/Classes/FrontendEnvironment.php +++ b/Classes/FrontendEnvironment.php @@ -19,8 +19,8 @@ use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager; use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; -use Doctrine\DBAL\Exception as DBALException; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -37,7 +37,7 @@ class FrontendEnvironment implements SingletonInterface * Check whether the page record is within the configured allowed pages types(doktype) for indexing. * Uses TypoScript: plugin.tx_solr.index.queue..allowedPageTypes * - * @throws DBALException + * @throws SiteNotFoundException */ public function isAllowedPageType( array $pageRecord, @@ -74,7 +74,12 @@ public function isAllowedPageType( /** * Returns TypoScriptConfiguration for desired page ID and language id. * + * @throws SiteNotFoundException + * * @todo: check when to use $rootPageId and if it can be removed. + * Most probably that belongs to mounted pages or to plugin.tx_solr.index.queue.[indexConfig].additionalPageIds + * For both cases, the indexing configuration must be used from desired/current root page given by `tx_solr_indexqueue_item`.`root`. + * Note about Site-config languages mismatch troubles: https://github.com/TYPO3-Solr/ext-solr/issues/3325#issuecomment-1900091020 */ public function getSolrConfigurationFromPageId( int $pageId, diff --git a/Classes/IndexQueue/AbstractIndexer.php b/Classes/IndexQueue/AbstractIndexer.php index e59cfa4079..526e4028a1 100644 --- a/Classes/IndexQueue/AbstractIndexer.php +++ b/Classes/IndexQueue/AbstractIndexer.php @@ -20,14 +20,19 @@ use ApacheSolrForTypo3\Solr\ContentObject\Classification; use ApacheSolrForTypo3\Solr\ContentObject\Multivalue; use ApacheSolrForTypo3\Solr\ContentObject\Relation; +use ApacheSolrForTypo3\Solr\FrontendEnvironment\Exception\Exception as FrontendEnvironmentException; use ApacheSolrForTypo3\Solr\FrontendEnvironment\Tsfe; use ApacheSolrForTypo3\Solr\System\Solr\Document\Document; use ApacheSolrForTypo3\Solr\System\Util\ArrayAccessor; +use Doctrine\DBAL\Exception as DBALException; use TYPO3\CMS\Core\Core\Environment; +use TYPO3\CMS\Core\Exception\SiteNotFoundException; +use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\TypoScript\FrontendTypoScript; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; +use TYPO3\CMS\Frontend\ContentObject\Exception\ContentRenderingException; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use UnexpectedValueException; @@ -60,8 +65,13 @@ public static function isAllowedToOverrideField(string $solrFieldName): bool * @param array $data Record data * @return Document Modified document with added fields */ - protected function addDocumentFieldsFromTyposcript(Document $document, array $indexingConfiguration, array $data, TypoScriptFrontendController $tsfe): Document - { + protected function addDocumentFieldsFromTyposcript( + Document $document, + array $indexingConfiguration, + array $data, + TypoScriptFrontendController $tsfe, + int|SiteLanguage $language, + ): Document { $data = static::addVirtualContentFieldToRecord($document, $data); // mapping of record fields => solr document fields, resolving cObj @@ -78,7 +88,13 @@ protected function addDocumentFieldsFromTyposcript(Document $document, array $in ); } - $fieldValue = $this->resolveFieldValue($indexingConfiguration, $solrFieldName, $data, $tsfe); + $fieldValue = $this->resolveFieldValue( + $indexingConfiguration, + $solrFieldName, + $data, + $tsfe, + $language, + ); if ($fieldValue === null || $fieldValue === '' || (is_array($fieldValue) && empty($fieldValue)) @@ -115,13 +131,23 @@ public static function addVirtualContentFieldToRecord(Document $document, array * @param array $indexingConfiguration Indexing configuration as defined in plugin.tx_solr_index.queue.[indexingConfigurationName].fields * @param string $solrFieldName A Solr field name that is configured in the indexing configuration * @param array $data A record or item's data + * @param TypoScriptFrontendController $tsfe + * @param int|SiteLanguage $language The language to use in TSFE stack + * * @return array|float|int|string|null The resolved string value to be indexed; null if value could not be resolved + * + * + * @throws FrontendEnvironmentException + * @throws DBALException + * @throws SiteNotFoundException + * @throws ContentRenderingException */ protected function resolveFieldValue( array $indexingConfiguration, string $solrFieldName, array $data, TypoScriptFrontendController $tsfe, + int|SiteLanguage $language, ): mixed { if (isset($indexingConfiguration[$solrFieldName . '.'])) { // configuration found => need to resolve a cObj @@ -132,7 +158,11 @@ protected function resolveFieldValue( chdir(Environment::getPublicPath() . '/'); $cObject = GeneralUtility::makeInstance(ContentObjectRenderer::class, $tsfe); - $request = $GLOBALS['TYPO3_REQUEST'] ?? GeneralUtility::makeInstance(Tsfe::class)->getServerRequestForTsfeByPageIdAndLanguageId($tsfe->id); + $request = $GLOBALS['TYPO3_REQUEST'] ?? GeneralUtility::makeInstance(Tsfe::class) + ->getServerRequestForTsfeByPageIdAndLanguageId( + $tsfe->id, + $language instanceof SiteLanguage ? $language->getLanguageId() : $language + ); $cObject->setRequest($request); $cObject->start($data, $this->type); $fieldValue = $cObject->cObjGetSingle( @@ -170,7 +200,11 @@ protected function resolveFieldValue( chdir(Environment::getPublicPath() . '/'); $cObject = GeneralUtility::makeInstance(ContentObjectRenderer::class, $tsfe); - $request = $GLOBALS['TYPO3_REQUEST'] ?? GeneralUtility::makeInstance(Tsfe::class)->getServerRequestForTsfeByPageIdAndLanguageId($tsfe->id); + $request = $GLOBALS['TYPO3_REQUEST'] ?? GeneralUtility::makeInstance(Tsfe::class) + ->getServerRequestForTsfeByPageIdAndLanguageId( + $tsfe->id, + $language instanceof SiteLanguage ? $language->getLanguageId() : $language + ); $cObject->setRequest($request); $cObject->start($data, $this->type); $fieldValue = $cObject->cObjGetSingle($name, $conf); diff --git a/Classes/IndexQueue/Indexer.php b/Classes/IndexQueue/Indexer.php index 34a46d0ee1..ccc3d7ddcb 100644 --- a/Classes/IndexQueue/Indexer.php +++ b/Classes/IndexQueue/Indexer.php @@ -381,7 +381,13 @@ protected function itemToDocument(Item $item, int $language = 0): ?Document $itemIndexingConfiguration = $this->getItemTypeConfiguration($item, $language); $document = $this->getBaseDocument($item, $itemRecord); $tsfe = $this->getTsfeByItemAndLanguageId($item, $language); - $document = $this->addDocumentFieldsFromTyposcript($document, $itemIndexingConfiguration, $itemRecord, $tsfe); + $document = $this->addDocumentFieldsFromTyposcript( + $document, + $itemIndexingConfiguration, + $itemRecord, + $tsfe, + $language, + ); } return $document; diff --git a/Classes/System/Configuration/ConfigurationManager.php b/Classes/System/Configuration/ConfigurationManager.php index 99e81f4aad..d888d04947 100644 --- a/Classes/System/Configuration/ConfigurationManager.php +++ b/Classes/System/Configuration/ConfigurationManager.php @@ -15,14 +15,28 @@ namespace ApacheSolrForTypo3\Solr\System\Configuration; +use Doctrine\DBAL\Exception as DBALException; +use JsonException; +use Psr\Container\ContainerInterface; +use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Http\Message\ServerRequestInterface; +use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Context\VisibilityAspect; +use TYPO3\CMS\Core\Database\ConnectionPool; +use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Http\ServerRequest; use TYPO3\CMS\Core\Routing\PageArguments; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Site\Entity\Site; use TYPO3\CMS\Core\Site\SiteFinder; use TYPO3\CMS\Core\TypoScript\FrontendTypoScriptFactory; +use TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateRepository; +use TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder; +use TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\ConditionVerdictAwareIncludeTreeTraverser; +use TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverser; +use TYPO3\CMS\Core\TypoScript\Tokenizer\LossyTokenizer; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\RootlineUtility; /** * Configuration manager old the configuration instance. @@ -30,9 +44,12 @@ */ class ConfigurationManager implements SingletonInterface { + /** + * @throws DBALException + * @throws JsonException + */ public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoScriptConfiguration { - $fullConfig = $this->getTypoScriptFrontendFromCore($request); $pageId = $request->getParsedBody()['id'] ?? $request->getQueryParams()['id'] ?? null; if ($pageId !== null) { $pageId = (int)$pageId; @@ -48,18 +65,25 @@ public function getTypoScriptFromRequest(ServerRequestInterface $request): TypoS } } } + $fullConfig = $this->getTypoScriptFrontendFromCore($request); return GeneralUtility::makeInstance(TypoScriptConfiguration::class, $fullConfig, $pageId); } /** * Retrieves the TypoScriptConfiguration object from configuration array, pageId, languageId and TypoScript * path that is used in the current context. + * + * @throws DBALException + * @throws JsonException + * @throws SiteNotFoundException */ public function getTypoScriptConfiguration(int $contextPageId = null, int $contextLanguageId = 0): TypoScriptConfiguration { if ($contextPageId !== null) { - $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($contextPageId); + $site = GeneralUtility::makeInstance(SiteFinder::class) + ->getSiteByPageId($contextPageId); $language = $site->getLanguageById($contextLanguageId); + // @todo: Storage-Folder can not be used to get TypoScript Config!!! $uri = $site->getRouter()->generateUri($contextPageId, ['_language' => $language]); $request = (new ServerRequest($uri, 'GET')) ->withAttribute('site', $site) @@ -86,22 +110,23 @@ public function getTypoScriptConfiguration(int $contextPageId = null, int $conte return $this->getTypoScriptFromRequest($request); } + /** + * @throws DBALException + * @throws JsonException + */ protected function getTypoScriptFrontendFromCore(ServerRequestInterface $request): array { $typo3Site = $request->getAttribute('site'); - $sysTemplateRows = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class) - ->getConnectionForTable('sys_template') - ->select(['*'], 'sys_template', ['pid' => $typo3Site->getRootPageId()]) - ->fetchAllAssociative(); + $sysTemplateRows = $this->getSysTemplateRowsForAssociatedContextPageId($request); $frontendTypoScriptFactory = GeneralUtility::makeInstance( FrontendTypoScriptFactory::class, - GeneralUtility::makeInstance(\Psr\Container\ContainerInterface::class), - GeneralUtility::makeInstance(\Psr\EventDispatcher\EventDispatcherInterface::class), - GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\IncludeTree\SysTemplateTreeBuilder::class), - GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Tokenizer\LossyTokenizer::class), - GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\IncludeTreeTraverser::class), - GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\IncludeTree\Traverser\ConditionVerdictAwareIncludeTreeTraverser::class), + GeneralUtility::makeInstance(ContainerInterface::class), + GeneralUtility::makeInstance(EventDispatcherInterface::class), + GeneralUtility::makeInstance(SysTemplateTreeBuilder::class), + GeneralUtility::makeInstance(LossyTokenizer::class), + GeneralUtility::makeInstance(IncludeTreeTraverser::class), + GeneralUtility::makeInstance(ConditionVerdictAwareIncludeTreeTraverser::class), ); $frontendTypoScript = $frontendTypoScriptFactory->createSettingsAndSetupConditions( $typo3Site, @@ -120,7 +145,49 @@ protected function getTypoScriptFrontendFromCore(ServerRequestInterface $request null, ); - $configurationArray = $frontendTypoScript->getSetupArray(); - return $configurationArray; + return $frontendTypoScript->getSetupArray(); + } + + /** + * @throws DBALException + */ + protected function getSysTemplateRowsForAssociatedContextPageId(ServerRequestInterface $request): array + { + $pageUid = (int)( + $request->getParsedBody()['id'] + ?? $request->getQueryParams()['id'] + ?? $request->getAttribute('site')?->getRootPageId() + ); + + /** @var Context $coreContext */ + $coreContext = clone GeneralUtility::makeInstance(Context::class); + $coreContext->setAspect( + 'visibility', + GeneralUtility::makeInstance( + VisibilityAspect::class, + false, + false + ) + ); + /** @var RootLineUtility $rootlineUtility */ + $rootlineUtility = GeneralUtility::makeInstance( + RootLineUtility::class, + $pageUid, + '', // @todo: tag: MountPoint, + $coreContext, + ); + + /** @var SysTemplateRepository $sysTemplateRepository */ + $sysTemplateRepository = GeneralUtility::makeInstance( + SysTemplateRepository::class, + GeneralUtility::makeInstance(EventDispatcherInterface::class), + GeneralUtility::makeInstance(ConnectionPool::class), + $coreContext, + ); + + return $sysTemplateRepository->getSysTemplateRowsByRootline( + $rootlineUtility->get(), + $request + ); } } diff --git a/Tests/Integration/ContentObject/RelationTest.php b/Tests/Integration/ContentObject/RelationTest.php index e5e15e9fab..7599ad6bc2 100644 --- a/Tests/Integration/ContentObject/RelationTest.php +++ b/Tests/Integration/ContentObject/RelationTest.php @@ -21,10 +21,11 @@ use ApacheSolrForTypo3\Solr\Tests\Integration\IntegrationTestBase; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\MockObject\MockObject; use Traversable; use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; use TYPO3\CMS\Core\Http\ServerRequest; +use TYPO3\CMS\Core\Site\Entity\SiteLanguage; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; @@ -288,9 +289,13 @@ protected function getSolrRelation(string $table, int $uid): Relation { $tsfeMock = $this->createMock(TypoScriptFrontendController::class); $contentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class, $tsfeMock); - /** @var MockObject|ServerRequest $requestMock */ - $requestMock = $this->createMock(ServerRequest::class); - $contentObjectRenderer->setRequest($requestMock); + $serverRequest = (new ServerRequest('http://testone.site/')) + ->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_FE) + ->withAttribute( + 'language', + $this->createMock(SiteLanguage::class) + ); + $contentObjectRenderer->setRequest($serverRequest); $contentObjectRenderer->start( BackendUtility::getRecord($table, $uid), $table diff --git a/Tests/Integration/IndexQueue/IndexerTest.php b/Tests/Integration/IndexQueue/IndexerTest.php index 60f0379fdb..72e037cf27 100644 --- a/Tests/Integration/IndexQueue/IndexerTest.php +++ b/Tests/Integration/IndexQueue/IndexerTest.php @@ -70,12 +70,12 @@ protected function setUp(): void $handlerMock = $this->createMock(RequestHandlerInterface::class); $normalizer = new NormalizedParamsAttribute(); $normalizer->process($request, $handlerMock); + $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } protected function tearDown(): void { parent::tearDown(); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); unset( $this->indexQueue, $this->indexer, @@ -88,7 +88,6 @@ protected function tearDown(): void #[Test] public function canIndexItemWithMMRelation(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_mm_relation.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88); @@ -102,7 +101,6 @@ public function canIndexItemWithMMRelation(): void self::assertStringContainsString('"category_stringM":["the tag"]', $solrContent, 'Did not find MM related tag'); self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"title":"testnews"', $solrContent, 'Could not index document into solr'); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } public static function getTranslatedRecordDataProvider(): Traversable @@ -122,8 +120,6 @@ public static function getTranslatedRecordDataProvider(): Traversable #[Test] public function testCanIndexTranslatedCustomRecord(string $fixture): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); - $this->importCSVDataSet(__DIR__ . '/Fixtures/' . $fixture); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88); @@ -153,8 +149,6 @@ public function testCanIndexTranslatedCustomRecord(string $fixture): void } self::assertStringContainsString('"url":"http://testone.site/de/?tx_foo%5Buid%5D=88', $solrContent, 'Can not build typolink as expected'); self::assertStringContainsString('"url":"http://testone.site/de/?tx_foo%5Buid%5D=777', $solrContent, 'Can not build typolink as expected'); - - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -163,7 +157,6 @@ public function testCanIndexTranslatedCustomRecord(string $fixture): void #[Test] public function canIndexItemWithMMRelationsInTheExpectedOrder(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_multiple_mm_relations.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88); @@ -186,8 +179,6 @@ public function canIndexItemWithMMRelationsInTheExpectedOrder(): void self::assertArrayHasKey('category_stringM', $solrDocs[0], 'Did not find MM related tags.'); self::assertCount(2, $solrDocs[0]['category_stringM'], 'Did not find all MM related tags.'); self::assertSame(['the tag', 'another tag'], $solrDocs[0]['category_stringM']); - - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -198,7 +189,6 @@ public function canIndexItemWithMMRelationsInTheExpectedOrder(): void #[Test] public function canIndexTranslatedItemWithMMRelation(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_translated_record_with_mm_relation.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88); @@ -211,8 +201,6 @@ public function canIndexTranslatedItemWithMMRelation(): void self::assertStringContainsString('"category_stringM":["translated tag"]', $solrContent, 'Did not find MM related tag'); self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"title":"translation"', $solrContent, 'Could not index document into solr'); - - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -221,7 +209,6 @@ public function canIndexTranslatedItemWithMMRelation(): void #[Test] public function canIndexMultipleMMRelatedItems(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_multiple_mm_relations.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88); @@ -237,8 +224,6 @@ public function canIndexMultipleMMRelatedItems(): void self::assertSame(['the tag', 'another tag'], $tags, 'Did not find MM related tags'); self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"title":"testnews"', $solrContent, 'Could not index document into solr'); - - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -247,7 +232,6 @@ public function canIndexMultipleMMRelatedItems(): void #[Test] public function canIndexItemWithMMRelationAndAdditionalWhere(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_mm_relationAndAdditionalWhere.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88); @@ -260,7 +244,6 @@ public function canIndexItemWithMMRelationAndAdditionalWhere(): void self::assertStringContainsString('"category_stringM":["another tag"]', $solrContent, 'Did not find MM related tag'); self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"title":"testnews"', $solrContent, 'Could not index document into solr'); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -269,7 +252,6 @@ public function canIndexItemWithMMRelationAndAdditionalWhere(): void #[Test] public function canIndexItemWithMMRelationToATranslatedPage(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_translated_record_with_mm_relation_to_a_page.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 88); @@ -284,8 +266,6 @@ public function canIndexItemWithMMRelationToATranslatedPage(): void self::assertStringContainsString('"relatedPageTitles_stringM":["Related page"]', $solrContentEn, 'Can not find related page title'); self::assertStringContainsString('"relatedPageTitles_stringM":["Translated related page"]', $solrContentDe, 'Can not find translated related page title'); - - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -294,7 +274,6 @@ public function canIndexItemWithMMRelationToATranslatedPage(): void #[Test] public function canIndexItemWithDirectRelation(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_direct_relation.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 111); @@ -310,7 +289,6 @@ public function canIndexItemWithDirectRelation(): void self::assertStringContainsString('"sysCategoryId_stringM":["1"]', $solrContent, 'Uid of related sys_category couldn\'t be resolved by using "foreignLabelField"'); self::assertStringContainsString('"sysCategory_stringM":["sys_category"]', $solrContent, 'Label of related sys_category couldn\'t be resolved by using "foreignLabelField" and "enableRecursiveValueResolution"'); self::assertStringContainsString('"sysCategoryDescription_stringM":["sys_category description"]', $solrContent, 'Description of related sys_category couldn\'t be resolved by using "foreignLabelField" and "enableRecursiveValueResolution"'); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -319,7 +297,6 @@ public function canIndexItemWithDirectRelation(): void #[Test] public function canIndexItemWithMultipleDirectRelation(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_multiple_direct_relations.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 111); @@ -345,8 +322,6 @@ public function canIndexItemWithMultipleDirectRelation(): void // @extensionScannerIgnoreLine $sysCategoryDescription_stringM = $decodedSolrContent->response->docs[0]->sysCategoryDescription_stringM; self::assertSame(['sys_category description', 'second sys_category description'], $sysCategoryDescription_stringM, 'Unexpected sysCategoryDescription_stringM value'); - - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** @@ -356,7 +331,6 @@ public function canIndexItemWithMultipleDirectRelation(): void #[Test] public function canIndexItemWithDirectRelationAndAdditionalWhere(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_direct_relationAndAdditionalWhere.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 111); @@ -369,13 +343,11 @@ public function canIndexItemWithDirectRelationAndAdditionalWhere(): void self::assertStringContainsString('"category_stringM":["another category"]', $solrContent, 'Did not find direct related category'); self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"title":"testnews"', $solrContent, 'Could not index document into solr'); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } #[Test] public function canUseConfigurationFromTemplateInRootLine(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_with_configuration_in_rootline.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 111); @@ -388,7 +360,6 @@ public function canUseConfigurationFromTemplateInRootLine(): void self::assertStringContainsString('"fieldFromRootLine_stringS":"TESTNEWS"', $solrContent, 'Did not find field configured in rootline'); self::assertStringContainsString('"title":"testnews"', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } #[Test] @@ -411,7 +382,6 @@ public function canGetAdditionalDocumentsViaPsr14EventListener(): void #[Test] public function testCanIndexCustomRecordOutsideOfSiteRoot(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_outside_site_root.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 111); @@ -424,13 +394,11 @@ public function testCanIndexCustomRecordOutsideOfSiteRoot(): void self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"title":"external testnews"', $solrContent, 'Could not index document into solr'); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } #[Test] public function testCanIndexCustomRecordOutsideOfSiteRootWithTemplate(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_custom_record_outside_site_root_with_template.csv'); $result = $this->addToQueueAndIndexRecord('tx_fakeextension_domain_model_bar', 1); @@ -445,7 +413,6 @@ public function testCanIndexCustomRecordOutsideOfSiteRootWithTemplate(): void $solrContent = file_get_contents($this->getSolrConnectionUriAuthority() . '/solr/core_en/select?q=*:*&fq=site:testone.site'); self::assertStringContainsString('"numFound":1', $solrContent, 'Could not index document into solr'); self::assertStringContainsString('"url":"http://testone.site/en/"', $solrContent, 'Item was indexed with false site UID'); - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } protected function addToQueueAndIndexRecord(string $table, int $uid): bool @@ -510,7 +477,6 @@ public function getSolrConnectionsByItemReturnsNoDefaultConnectionDefaultLanguag #[Test] public function getSolrConnectionsByItemReturnsProperItemInNestedSite(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->writeDefaultSolrTestSiteConfiguration(); $this->importCSVDataSet(__DIR__ . '/Fixtures/can_index_with_multiple_sites.csv'); $result = $this->addToQueueAndIndexRecord('pages', 1); diff --git a/Tests/Unit/IndexQueue/AbstractIndexerTest.php b/Tests/Unit/IndexQueue/AbstractIndexerTest.php index b4d948bfc1..c34fa8b135 100644 --- a/Tests/Unit/IndexQueue/AbstractIndexerTest.php +++ b/Tests/Unit/IndexQueue/AbstractIndexerTest.php @@ -106,7 +106,8 @@ public function resolveFieldValue(array $indexingConfiguration, string $solrFiel $indexingConfiguration, $solrFieldName, $data, - $tsfe + $tsfe, + 0, ), $expectedValue );