diff --git a/Classes/Controller/SearchController.php b/Classes/Controller/SearchController.php index 1079740892..dff1e1c67c 100644 --- a/Classes/Controller/SearchController.php +++ b/Classes/Controller/SearchController.php @@ -26,10 +26,9 @@ use ApacheSolrForTypo3\Solr\System\Solr\SolrUnavailableException; use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\View\FluidViewAdapter; use TYPO3\CMS\Extbase\Http\ForwardResponse; -use TYPO3\CMS\Fluid\View\TemplateView; use TYPO3Fluid\Fluid\View\AbstractTemplateView; -use TYPO3Fluid\Fluid\View\ViewInterface; /** * Class SearchController @@ -57,30 +56,28 @@ protected function mapGlobalQueryStringWhenEnabled(): void } } - /** - * @param ViewInterface $view - */ - public function initializeView($view): void + public function initializeView(FluidViewAdapter $view): void { - if ($view instanceof TemplateView) { - $variableProvider = GeneralUtility::makeInstance(SolrVariableProvider::class); - $variableProvider->setSource($view->getRenderingContext()->getVariableProvider()->getSource()); - $view->getRenderingContext()->setVariableProvider($variableProvider); - $view->getRenderingContext()->getVariableProvider()->add( - 'typoScriptConfiguration', - $this->typoScriptConfiguration - ); + $variableProvider = GeneralUtility::makeInstance(SolrVariableProvider::class); + $variableProvider->setSource($view->getRenderingContext()->getVariableProvider()->getSource()); + $view->getRenderingContext()->setVariableProvider($variableProvider); + $view->getRenderingContext()->getVariableProvider()->add( + 'typoScriptConfiguration', + $this->typoScriptConfiguration + ); - $customTemplate = $this->getCustomTemplateFromConfiguration(); - if ($customTemplate === '') { - return; - } + $customTemplate = $this->getCustomTemplateFromConfiguration(); + if ($customTemplate === '') { + return; + } - if (str_contains($customTemplate, 'EXT:')) { - $view->setTemplatePathAndFilename($customTemplate); - } else { - $view->setTemplate($customTemplate); - } + if (str_contains($customTemplate, 'EXT:')) { + $view->getRenderingContext() + ->getTemplatePaths() + ->setTemplatePathAndFilename($customTemplate); + } else { + $view->getRenderingContext() + ->setControllerAction($customTemplate); } } diff --git a/Classes/ViewHelpers/SearchFormViewHelper.php b/Classes/ViewHelpers/SearchFormViewHelper.php index 8e908d47d3..ffe5df850a 100644 --- a/Classes/ViewHelpers/SearchFormViewHelper.php +++ b/Classes/ViewHelpers/SearchFormViewHelper.php @@ -18,9 +18,11 @@ namespace ApacheSolrForTypo3\Solr\ViewHelpers; use ApacheSolrForTypo3\Solr\System\Url\UrlHelper; +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; use TYPO3\CMS\Core\Utility\ArrayUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Mvc\RequestInterface; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext; use TYPO3Fluid\Fluid\Core\Variables\VariableProviderInterface; @@ -84,13 +86,14 @@ public function initializeArguments(): void */ public function render() { - /** @phpstan-ignore-next-line */ - $this->uriBuilder->setRequest($this->renderingContext->getRequest()); + /** @var RequestInterface $request */ + $request = $this->renderingContext->getAttribute(ServerRequestInterface::class); + $this->uriBuilder->setRequest($request); $pageUid = $this->arguments['pageUid'] ?? null; if ($pageUid === null && !empty($this->getTypoScriptConfiguration()->getSearchTargetPage())) { $pageUid = $this->getTypoScriptConfiguration()->getSearchTargetPage(); } elseif ($pageUid === null) { - $pageUid = $this->renderingContext->getRequest()->getAttribute('routing')?->getPageId(); + $pageUid = $this->renderingContext->getAttribute(ServerRequestInterface::class)->getAttribute('routing')?->getPageId(); } $pageUid = (int)$pageUid; @@ -128,7 +131,7 @@ protected function getExistingSearchParameters(): array { $searchParameters = []; if ($this->getTypoScriptConfiguration()->getSearchKeepExistingParametersForNewSearches()) { - $request = $this->renderingContext->getRequest(); + $request = $this->renderingContext->getAttribute(ServerRequestInterface::class); $pluginNamespace = $this->getTypoScriptConfiguration()->getSearchPluginNamespace(); $arguments = $request->getQueryParams()[$pluginNamespace] ?? []; ArrayUtility::mergeRecursiveWithOverrule($arguments, $request->getParsedBody()[$pluginNamespace] ?? []); diff --git a/Tests/Integration/SearchTest.php b/Tests/Integration/SearchTest.php index bcab41d3e4..7ff535f8e2 100644 --- a/Tests/Integration/SearchTest.php +++ b/Tests/Integration/SearchTest.php @@ -71,7 +71,6 @@ public function canSearchForADocument(): void $this->indexPages([2]); - $query = $this->queryBuilder ->newSearchQuery('hello') ->useQueryFields(QueryFields::fromString('content^40.0, title^5.0, keywords^2.0, tagsH1^5.0, tagsH2H3^3.0, tagsH4H5H6^2.0, tagsInline^1.0, description^4.0, abstract^1.0, subtitle^1.0, navtitle^1.0, author^1.0')) @@ -95,7 +94,6 @@ public function canHighlightTerms(): void $this->addTypoScriptToTemplateRecord(1, 'config.index_enable = 1'); $this->indexPages(range(2, 16)); - // fragmentSize 50 => fastVector $typoScriptConfiguration = new TypoScriptConfiguration([ 'plugin.' => [ diff --git a/Tests/Unit/IndexQueue/AbstractIndexerTest.php b/Tests/Unit/IndexQueue/AbstractIndexerTest.php index d146b9300e..b4d948bfc1 100644 --- a/Tests/Unit/IndexQueue/AbstractIndexerTest.php +++ b/Tests/Unit/IndexQueue/AbstractIndexerTest.php @@ -97,7 +97,7 @@ public function isSerializedValueCanHandleCustomValidSerializedValueDetector(): #[Test] public function resolveFieldValue(array $indexingConfiguration, string $solrFieldName, array $data, $expectedValue): void { - $subject = new class () extends AbstractIndexer {}; + $subject = new class extends AbstractIndexer {}; $tsfe = $this->createMock(TypoScriptFrontendController::class); self::assertEquals( $this->callInaccessibleMethod( diff --git a/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php b/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php index e4985eedeb..2884c1f65e 100644 --- a/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php +++ b/Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php @@ -53,7 +53,7 @@ protected function setUp(): void ->getMock(); /* @see \TYPO3\CMS\Frontend\Tests\Unit\Middleware\PageResolverTest::setUp */ - $this->responseOutputHandler = new class () implements RequestHandlerInterface { + $this->responseOutputHandler = new class implements RequestHandlerInterface { protected ServerRequestInterface $request; public function handle(ServerRequestInterface $request): ResponseInterface { diff --git a/Tests/Unit/ViewHelpers/Facet/Area/GroupViewHelperTest.php b/Tests/Unit/ViewHelpers/Facet/Area/GroupViewHelperTest.php index 64a0a6ebc1..03effc713a 100644 --- a/Tests/Unit/ViewHelpers/Facet/Area/GroupViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Facet/Area/GroupViewHelperTest.php @@ -21,19 +21,31 @@ use ApacheSolrForTypo3\Solr\Tests\Unit\SetUpUnitTestCase; use ApacheSolrForTypo3\Solr\ViewHelpers\Facet\Area\GroupViewHelper; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\MockObject\Exception as MockObjectException; +use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode; use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; use TYPO3Fluid\Fluid\Core\Variables\StandardVariableProvider; class GroupViewHelperTest extends SetUpUnitTestCase { + /** + * @throws MockObjectException + */ #[Test] public function canMakeOnlyExpectedFacetsAvailableInStaticContext(): void { $facetCollection = $this->getTestFacetCollection(); - $variableContainer = $this->getMockBuilder(StandardVariableProvider::class)->onlyMethods(['remove'])->getMock(); + $variableContainer = $this->getMockBuilder(StandardVariableProvider::class) + ->onlyMethods([ + 'remove', + ]) + ->getMock(); $renderingContextMock = $this->createMock(RenderingContextInterface::class); - $renderingContextMock->expects(self::any())->method('getVariableProvider')->willReturn($variableContainer); + $renderingContextMock + ->expects(self::any()) + ->method('getVariableProvider') + ->willReturn($variableContainer); $testArguments['facets'] = $facetCollection; $testArguments['groupName'] = 'left'; @@ -49,17 +61,33 @@ public function canMakeOnlyExpectedFacetsAvailableInStaticContext(): void self::assertEquals(['color', 'brand'], $facetKeys); } + /** + * @throws MockObjectException + */ #[Test] public function canMakeOnlyExpectedFacetsAvailableInstanceContext(): void { $facetCollection = $this->getTestFacetCollection(); - $variableContainer = $this->getMockBuilder(StandardVariableProvider::class)->onlyMethods(['remove'])->getMock(); + $variableContainer = $this->getMockBuilder(StandardVariableProvider::class) + ->onlyMethods([ + 'remove', + ]) + ->getMock(); $renderingContextMock = $this->createMock(RenderingContextInterface::class); - $renderingContextMock->expects(self::any())->method('getVariableProvider')->willReturn($variableContainer); - - $viewHelper = $this->getMockBuilder(GroupViewHelper::class)->onlyMethods(['renderChildren'])->getMock(); + $renderingContextMock + ->expects(self::any()) + ->method('getVariableProvider') + ->willReturn($variableContainer); + + $viewHelper = $this->getMockBuilder(GroupViewHelper::class) + ->onlyMethods([ + 'renderChildren', + ]) + ->getMock(); $viewHelper->setRenderingContext($renderingContextMock); + $viewHelperNodeMock = $this->createMock(ViewHelperNode::class); + $viewHelper->setViewHelperNode($viewHelperNodeMock); $viewHelper->setArguments(['facets' => $facetCollection, 'groupName' => 'left']); $viewHelper->render(); @@ -74,9 +102,9 @@ public function canMakeOnlyExpectedFacetsAvailableInstanceContext(): void } /** - * @return FacetCollection + * @throws MockObjectException */ - protected function getTestFacetCollection() + protected function getTestFacetCollection(): FacetCollection { $facetCollection = new FacetCollection(); $resultSetMock = $this->createMock(SearchResultSet::class); diff --git a/Tests/Unit/ViewHelpers/SearchFormViewHelperTest.php b/Tests/Unit/ViewHelpers/SearchFormViewHelperTest.php index c3f93a416a..fda6a252ee 100644 --- a/Tests/Unit/ViewHelpers/SearchFormViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/SearchFormViewHelperTest.php @@ -21,6 +21,7 @@ use ApacheSolrForTypo3\Solr\ViewHelpers\SearchFormViewHelper; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Http\ServerRequest; use TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters; use TYPO3\CMS\Extbase\Mvc\Request; @@ -63,7 +64,7 @@ protected function setUp(): void new TemplatePaths() ); $request = new Request((new ServerRequest())->withAttribute('extbase', new ExtbaseRequestParameters(SearchController::class))); - $renderingContext->setRequest($request); + $renderingContext->setAttribute(ServerRequestInterface::class, $request); $this->viewHelper->setRenderingContext($renderingContext); $this->viewHelper->expects(self::any())->method('getTypoScriptConfiguration')->willReturn($this->typoScriptConfigurationMock); $this->viewHelper->expects(self::any())->method('getTemplateVariableContainer')->willReturn($this->createMock(VariableProviderInterface::class));