Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] deprecations for Fluid viewHelpers and stack #4140

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
11 changes: 7 additions & 4 deletions Classes/ViewHelpers/SearchFormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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] ?? []);
Expand Down
2 changes: 0 additions & 2 deletions Tests/Integration/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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.' => [
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/IndexQueue/AbstractIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Middleware/SolrRoutingMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
44 changes: 36 additions & 8 deletions Tests/Unit/ViewHelpers/Facet/Area/GroupViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Unit/ViewHelpers/SearchFormViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
Loading