From a0169dca7266acf5a7d1d647597faa3e7613d956 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Thu, 19 Oct 2023 15:07:50 +0200 Subject: [PATCH 1/5] Allowed injecting view type into content preview controller --- .../Resources/config/routing/internal.yml | 2 +- .../Controller/Content/PreviewController.php | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/bundle/Core/Resources/config/routing/internal.yml b/src/bundle/Core/Resources/config/routing/internal.yml index 54823daa02..9a15b9179b 100644 --- a/src/bundle/Core/Resources/config/routing/internal.yml +++ b/src/bundle/Core/Resources/config/routing/internal.yml @@ -20,7 +20,7 @@ ibexa.content.view: ibexa.version.preview: path: /content/versionview/{contentId}/{versionNo}/{language}/site_access/{siteAccessName} - defaults: { _controller: ibexa.controller.content.preview:previewContentAction } + controller: ibexa.controller.content.preview:previewContentAction methods: [GET] ibexa.content.preview.default: diff --git a/src/lib/MVC/Symfony/Controller/Content/PreviewController.php b/src/lib/MVC/Symfony/Controller/Content/PreviewController.php index ee706a62d3..2d0d5879cc 100644 --- a/src/lib/MVC/Symfony/Controller/Content/PreviewController.php +++ b/src/lib/MVC/Symfony/Controller/Content/PreviewController.php @@ -22,6 +22,7 @@ use Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker; use Ibexa\Core\MVC\Symfony\View\ViewManagerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; @@ -77,12 +78,12 @@ public function __construct( */ public function previewContentAction( Request $request, - $contentId, - $versionNo, - $language, - $siteAccessName = null, + int $contentId, + int $versionNo, + string $language, + ?string $siteAccessName = null, ?int $locationId = null - ) { + ): Response { $this->previewHelper->setPreviewActive(true); try { @@ -112,8 +113,9 @@ public function previewContentAction( } try { + $viewType = $request->query->get('viewType', ViewManagerInterface::VIEW_TYPE_FULL); $response = $this->kernel->handle( - $this->getForwardRequest($location, $content, $siteAccess, $request, $language), + $this->getForwardRequest($location, $content, $siteAccess, $request, $language, $viewType), HttpKernelInterface::SUB_REQUEST, false ); @@ -140,17 +142,15 @@ public function previewContentAction( /** * Returns the Request object that will be forwarded to the kernel for previewing the content. - * - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Location $location - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content - * @param \Ibexa\Core\MVC\Symfony\SiteAccess $previewSiteAccess - * @param \Symfony\Component\HttpFoundation\Request $request - * @param string $language - * - * @return \Symfony\Component\HttpFoundation\Request */ - protected function getForwardRequest(Location $location, Content $content, SiteAccess $previewSiteAccess, Request $request, $language) - { + protected function getForwardRequest( + Location $location, + Content $content, + SiteAccess $previewSiteAccess, + Request $request, + string $language, + string $viewType = ViewManagerInterface::VIEW_TYPE_FULL + ): Request { $forwardRequestParameters = [ '_controller' => UrlAliasRouter::VIEW_ACTION, // specify a route for RouteReference generator @@ -161,7 +161,7 @@ protected function getForwardRequest(Location $location, Content $content, SiteA ], 'location' => $location, 'content' => $content, - 'viewType' => ViewManagerInterface::VIEW_TYPE_FULL, + 'viewType' => $viewType, 'layout' => true, 'params' => [ 'content' => $content, From e87f3612d080a5e5636200cbe8f15870c09d69a4 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Fri, 20 Oct 2023 17:34:49 +0200 Subject: [PATCH 2/5] [Tests] Refactored PreviewControllerTest --- .../Content/PreviewControllerTest.php | 456 ++++++++---------- 1 file changed, 188 insertions(+), 268 deletions(-) diff --git a/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php b/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php index 9a3007ae04..4ca669e383 100644 --- a/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php +++ b/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php @@ -4,21 +4,20 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); + namespace Ibexa\Tests\Core\MVC\Symfony\Controller\Controller\Content; use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\Values\Content\Content; -use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\Location; use Ibexa\Core\Base\Exceptions\UnauthorizedException; use Ibexa\Core\Helper\ContentPreviewHelper; use Ibexa\Core\Helper\PreviewLocationProvider; use Ibexa\Core\MVC\Symfony\Controller\Content\PreviewController; -use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute as AuthorizationAttribute; use Ibexa\Core\MVC\Symfony\SiteAccess; use Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker; -use Ibexa\Core\MVC\Symfony\View\ViewManagerInterface; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -26,28 +25,31 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; -class PreviewControllerTest extends TestCase +/** + * @covers \Ibexa\Core\MVC\Symfony\Controller\Content\PreviewController + */ +final class PreviewControllerTest extends TestCase { - /** @var \Ibexa\Contracts\Core\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject */ - protected $contentService; + /** @var \Ibexa\Contracts\Core\Repository\ContentService&\PHPUnit\Framework\MockObject\MockObject */ + protected ContentService $contentService; - /** @var \Ibexa\Contracts\Core\Repository\LocationService|\PHPUnit\Framework\MockObject\MockObject */ - protected $locationService; + /** @var \Ibexa\Contracts\Core\Repository\LocationService&\PHPUnit\Framework\MockObject\MockObject */ + protected LocationService $locationService; - /** @var \Symfony\Component\HttpKernel\HttpKernelInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $httpKernel; + /** @var \Symfony\Component\HttpKernel\HttpKernelInterface&\PHPUnit\Framework\MockObject\MockObject */ + protected HttpKernelInterface $httpKernel; - /** @var \Ibexa\Core\Helper\ContentPreviewHelper|\PHPUnit\Framework\MockObject\MockObject */ - protected $previewHelper; + /** @var \Ibexa\Core\Helper\ContentPreviewHelper&\PHPUnit\Framework\MockObject\MockObject */ + protected ContentPreviewHelper $previewHelper; - /** @var \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $authorizationChecker; + /** @var \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface&\PHPUnit\Framework\MockObject\MockObject */ + protected AuthorizationCheckerInterface $authorizationChecker; - /** @var \Ibexa\Core\Helper\PreviewLocationProvider|\PHPUnit\Framework\MockObject\MockObject */ - protected $locationProvider; + /** @var \Ibexa\Core\Helper\PreviewLocationProvider&\PHPUnit\Framework\MockObject\MockObject */ + protected PreviewLocationProvider $locationProvider; - /** @var \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected $controllerChecker; + /** @var \Ibexa\Core\MVC\Symfony\View\CustomLocationControllerChecker&\PHPUnit\Framework\MockObject\MockObject */ + protected CustomLocationControllerChecker $controllerChecker; protected function setUp(): void { @@ -75,7 +77,10 @@ protected function getPreviewController(): PreviewController ); } - public function testPreviewUnauthorized() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testPreviewUnauthorized(): void { $this->expectException(AccessDeniedException::class); @@ -84,306 +89,221 @@ public function testPreviewUnauthorized() $lang = 'eng-GB'; $versionNo = 3; $this->contentService - ->expects($this->once()) + ->expects(self::once()) ->method('loadContent') ->with($contentId, [$lang], $versionNo) - ->will($this->throwException(new UnauthorizedException('foo', 'bar'))); + ->willThrowException(new UnauthorizedException('foo', 'bar')) + ; + $controller->previewContentAction(new Request(), $contentId, $versionNo, $lang, 'test'); } - public function testPreviewCanUserFail() + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception + */ + public function testPreviewCanUserFail(): void { - $this->expectException(AccessDeniedException::class); - $controller = $this->getPreviewController(); $contentId = 123; $lang = 'eng-GB'; $versionNo = 3; $content = $this->createMock(Content::class); - $contentInfo = $this->getMockBuilder(ContentInfo::class) - ->setConstructorArgs([['id' => $contentId]]) - ->getMockForAbstractClass(); + $location = $this->createMock(Location::class); $this->locationProvider - ->expects($this->once()) ->method('loadMainLocationByContent') ->with($content) - ->will($this->returnValue($this->createMock(Location::class))); + ->willReturn($location) + ; $this->contentService - ->expects($this->once()) ->method('loadContent') ->with($contentId, [$lang], $versionNo) - ->will($this->returnValue($content)); - $this->authorizationChecker - ->expects($this->once()) - ->method('isGranted') - ->with($this->equalTo(new AuthorizationAttribute('content', 'versionread', ['valueObject' => $content]))) - ->will($this->returnValue(false)); + ->willReturn($content) + ; - $controller->previewContentAction(new Request(), $contentId, $versionNo, $lang, 'test'); - } + $this->authorizationChecker->method('isGranted')->willReturn(false); - public function testPreview() - { - $contentId = 123; - $lang = 'eng-GB'; - $versionNo = 3; - $locationId = 456; - $content = $this->createMock(Content::class); - $location = $this->getMockBuilder(Location::class) - ->setConstructorArgs([['id' => $locationId]]) - ->getMockForAbstractClass(); - - // Repository expectations - $this->locationProvider - ->expects($this->once()) - ->method('loadMainLocationByContent') - ->with($content) - ->will($this->returnValue($location)); - $this->contentService - ->expects($this->once()) - ->method('loadContent') - ->with($contentId, [$lang], $versionNo) - ->will($this->returnValue($content)); - $this->authorizationChecker - ->expects($this->once()) - ->method('isGranted') - ->with($this->equalTo(new AuthorizationAttribute('content', 'versionread', ['valueObject' => $content]))) - ->will($this->returnValue(true)); - - $previewSiteAccessName = 'test'; - $previewSiteAccess = new SiteAccess($previewSiteAccessName, 'preview'); - $previousSiteAccessName = 'foo'; - $previousSiteAccess = new SiteAccess($previousSiteAccessName); - $request = $this->getMockBuilder(Request::class) - ->setMethods(['duplicate']) - ->getMock(); - - // PreviewHelper expectations - $this->previewHelper - ->expects($this->exactly(2)) - ->method('setPreviewActive') - ->will( - $this->returnValueMap( - [ - [true, null], - [false, null], - ] - ) - ); - $this->previewHelper - ->expects($this->once()) - ->method('setPreviewedContent') - ->with($content); - $this->previewHelper - ->expects($this->once()) - ->method('setPreviewedLocation') - ->with($location); - $this->previewHelper - ->expects($this->once()) - ->method('getOriginalSiteAccess') - ->will($this->returnValue($previousSiteAccess)); - $this->previewHelper - ->expects($this->once()) - ->method('changeConfigScope') - ->with($previewSiteAccessName) - ->will($this->returnValue($previewSiteAccess)); - $this->previewHelper - ->expects($this->once()) - ->method('restoreConfigScope'); - - // Request expectations - $duplicatedRequest = $this->getDuplicatedRequest($location, $content, $previewSiteAccess); - $request - ->expects($this->once()) - ->method('duplicate') - ->will($this->returnValue($duplicatedRequest)); - - // Kernel expectations - $expectedResponse = new Response(); - $this->httpKernel - ->expects($this->once()) - ->method('handle') - ->with($duplicatedRequest, HttpKernelInterface::SUB_REQUEST) - ->will($this->returnValue($expectedResponse)); + $this->expectException(AccessDeniedException::class); - $controller = $this->getPreviewController(); - $this->assertSame( - $expectedResponse, - $controller->previewContentAction($request, $contentId, $versionNo, $lang, $previewSiteAccessName) - ); + $controller->previewContentAction(new Request(), $contentId, $versionNo, $lang, 'test'); } - public function testPreviewDefaultSiteaccess() + /** + * @return iterable + */ + public static function getDataForTestPreview(): iterable { - $contentId = 123; - $lang = 'eng-GB'; - $versionNo = 3; - $locationId = 456; - $content = $this->createMock(Content::class); - $location = $this->getMockBuilder(Location::class) - ->setConstructorArgs([['id' => $locationId]]) - ->getMockForAbstractClass(); - - // Repository expectations - $this->locationProvider - ->expects($this->once()) - ->method('loadMainLocationByContent') - ->with($content) - ->will($this->returnValue($location)); - $this->contentService - ->expects($this->once()) - ->method('loadContent') - ->with($contentId, [$lang], $versionNo) - ->will($this->returnValue($content)); - $this->authorizationChecker - ->expects($this->once()) - ->method('isGranted') - ->with($this->equalTo(new AuthorizationAttribute('content', 'versionread', ['valueObject' => $content]))) - ->will($this->returnValue(true)); - - $previousSiteAccessName = 'foo'; - $previousSiteAccess = new SiteAccess($previousSiteAccessName); - $request = $this->getMockBuilder(Request::class) - ->setMethods(['duplicate']) - ->getMock(); - - $this->previewHelper - ->expects($this->once()) - ->method('getOriginalSiteAccess') - ->will($this->returnValue($previousSiteAccess)); - $this->previewHelper - ->expects($this->once()) - ->method('restoreConfigScope'); - - // Request expectations - $duplicatedRequest = $this->getDuplicatedRequest($location, $content, $previousSiteAccess); - $request - ->expects($this->once()) - ->method('duplicate') - ->will($this->returnValue($duplicatedRequest)); - - // Kernel expectations - $expectedResponse = new Response(); - $this->httpKernel - ->expects($this->once()) - ->method('handle') - ->with($duplicatedRequest, HttpKernelInterface::SUB_REQUEST) - ->will($this->returnValue($expectedResponse)); - - $controller = $this->getPreviewController(); - $this->assertSame( - $expectedResponse, - $controller->previewContentAction($request, $contentId, $versionNo, $lang) - ); + yield 'with different SiteAccess, main Location' => [ + new SiteAccess('test', 'preview'), + 123, // contentId + 'eng-GB', + 3, // versionNo + null, // secondary Location Id + ]; + + yield 'with default SiteAccess, main Location' => [ + null, + 234, // contentId + 'ger-DE', + 1, // versionNo + null, // secondary Location Id + ]; + + yield 'with different SiteAccess, secondary Location' => [ + new SiteAccess('test', 'preview'), + 567, // contentId + 'eng-GB', + 11, // versionNo + 220, // secondary Location Id + ]; + + yield 'with default SiteAccess, secondary Location' => [ + null, + 234, // contentId + 'ger-DE', + 1, // versionNo + 221, // secondary Location Id + ]; } /** - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotImplementedException + * @dataProvider getDataForTestPreview + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception */ - public function testPreviewWithLocationId(): void - { - $contentId = 123; - $lang = 'eng-GB'; - $versionNo = 3; - $locationId = 456; + public function testPreview( + ?SiteAccess $previewSiteAccess, + int $contentId, + string $language, + int $versionNo, + ?int $locationId + ): void { $content = $this->createMock(Content::class); $location = $this->getMockBuilder(Location::class) - ->setConstructorArgs([['id' => $locationId]]) - ->getMockForAbstractClass(); + ->setConstructorArgs([['id' => $locationId ?? 456]]) + ->getMockForAbstractClass(); + + if (null === $locationId) { + $this->locationProvider->method('loadMainLocationByContent')->with($content)->willReturn($location); + } else { + $this->locationService->method('loadLocation')->with($locationId)->willReturn($location); + } $this->contentService - ->expects(self::once()) ->method('loadContent') - ->with($contentId, [$lang], $versionNo) + ->with($contentId, [$language], $versionNo) ->willReturn($content); - $this->locationService - ->expects(self::once()) - ->method('loadLocation') - ->with($locationId) - ->willReturn($location); + $this->authorizationChecker->method('isGranted')->willReturn(true); - $this->authorizationChecker - ->expects(self::once()) - ->method('isGranted') - ->with(new AuthorizationAttribute('content', 'versionread', ['valueObject' => $content])) - ->willReturn(true); + $originalSiteAccess = new SiteAccess('foo'); - $previousSiteAccessName = 'foo'; - $previousSiteAccess = new SiteAccess($previousSiteAccessName); - $request = $this->getMockBuilder(Request::class) - ->onlyMethods(['duplicate']) - ->getMock(); + $request = new Request(); + $request->attributes->set('semanticPathinfo', '/foo/bar'); - $this->previewHelper - ->expects(self::once()) - ->method('getOriginalSiteAccess') - ->willReturn($previousSiteAccess); - - $this->previewHelper - ->expects(self::once()) - ->method('restoreConfigScope'); + $this->configurePreviewHelper( + $content, + $location, + $originalSiteAccess, + $previewSiteAccess + ); - $duplicatedRequest = $this->getDuplicatedRequest($location, $content, $previousSiteAccess); - $request - ->expects(self::once()) - ->method('duplicate') - ->willReturn($duplicatedRequest); + $forwardRequestParameters = $this->getExpectedForwardRequestParameters( + $location, + $content, + $previewSiteAccess ?? $originalSiteAccess, + $language + ); - $expectedResponse = new Response(); + // the actual assertion happens here, checking if the forward request params are correct $this->httpKernel - ->expects(self::once()) ->method('handle') - ->with($duplicatedRequest, HttpKernelInterface::SUB_REQUEST) - ->willReturn($expectedResponse); + ->with($request->duplicate(null, null, $forwardRequestParameters), HttpKernelInterface::SUB_REQUEST) + ->willReturn($this->createMock(Response::class)) + ; $controller = $this->getPreviewController(); - - self::assertSame( - $expectedResponse, - $controller->previewContentAction( - $request, - $contentId, - $versionNo, - $lang, - null, - $locationId - ) + $controller->previewContentAction( + $request, + $contentId, + $versionNo, + $language, + $previewSiteAccess !== null ? $previewSiteAccess->name : null, + $locationId ); } /** - * @param $location - * @param $content - * @param $previewSiteAccess - * - * @return \Symfony\Component\HttpFoundation\Request + * @return array */ - protected function getDuplicatedRequest(Location $location, Content $content, SiteAccess $previewSiteAccess) - { - $duplicatedRequest = new Request(); - $duplicatedRequest->attributes->add( - [ - '_controller' => 'ibexa_content::viewAction', + private function getExpectedForwardRequestParameters( + Location $location, + Content $content, + SiteAccess $previewSiteAccess, + string $language + ): array { + return [ + '_controller' => 'ibexa_content::viewAction', + '_route' => 'ibexa.content.view', + '_route_params' => [ 'contentId' => $content->id, + 'locationId' => $location->id, + ], + 'location' => $location, + 'content' => $content, + 'viewType' => 'full', + 'layout' => true, + 'params' => [ + 'content' => $content, 'location' => $location, - 'viewType' => ViewManagerInterface::VIEW_TYPE_FULL, - 'layout' => true, - 'semanticPathinfo' => '/foo/bar', - 'params' => [ - 'content' => $content, - 'location' => $location, - 'isPreview' => true, - 'siteaccess' => $previewSiteAccess, - ], - ] - ); + 'isPreview' => true, + 'language' => $language, + ], + 'siteaccess' => $previewSiteAccess, + 'semanticPathinfo' => '/foo/bar', + ]; + } + + private function configurePreviewHelper( + Content $content, + Location $location, + SiteAccess $originalSiteAccess, + ?SiteAccess $previewSiteAccess = null + ): void { + $this->previewHelper + ->expects(self::exactly(2)) + ->method('setPreviewActive') + ->withConsecutive([true], [false]) + ; + + $this->previewHelper + ->expects(self::once()) + ->method('setPreviewedContent') + ->with($content) + ; + $this->previewHelper + ->expects(self::once()) + ->method('setPreviewedLocation') + ->with($location) + ; + $this->previewHelper + ->expects(self::once()) + ->method('getOriginalSiteAccess') + ->willReturn($originalSiteAccess) + ; + + if ($previewSiteAccess !== null) { + $this->previewHelper + ->expects(self::once()) + ->method('changeConfigScope') + ->with($previewSiteAccess->name) + ->willReturn($previewSiteAccess) + ; + } - return $duplicatedRequest; + $this->previewHelper + ->expects(self::once()) + ->method('restoreConfigScope') + ; } } - -class_alias(PreviewControllerTest::class, 'eZ\Publish\Core\MVC\Symfony\Controller\Tests\Controller\Content\PreviewControllerTest'); From 22c53eabf6536262f53f7dca6eac9fcabe37e0f6 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Fri, 20 Oct 2023 18:12:59 +0200 Subject: [PATCH 3/5] [Tests] Added coverage for parametrized view type in PreviewController --- .../Content/PreviewControllerTest.php | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php b/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php index 4ca669e383..cf92324b1d 100644 --- a/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php +++ b/tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php @@ -129,7 +129,7 @@ public function testPreviewCanUserFail(): void } /** - * @return iterable + * @return iterable */ public static function getDataForTestPreview(): iterable { @@ -139,6 +139,7 @@ public static function getDataForTestPreview(): iterable 'eng-GB', 3, // versionNo null, // secondary Location Id + null, ]; yield 'with default SiteAccess, main Location' => [ @@ -147,6 +148,7 @@ public static function getDataForTestPreview(): iterable 'ger-DE', 1, // versionNo null, // secondary Location Id + null, ]; yield 'with different SiteAccess, secondary Location' => [ @@ -155,6 +157,7 @@ public static function getDataForTestPreview(): iterable 'eng-GB', 11, // versionNo 220, // secondary Location Id + null, ]; yield 'with default SiteAccess, secondary Location' => [ @@ -163,6 +166,16 @@ public static function getDataForTestPreview(): iterable 'ger-DE', 1, // versionNo 221, // secondary Location Id + null, + ]; + + yield 'with different SiteAccess and different viewType' => [ + new SiteAccess('test', 'preview'), + 789, // contentId + 'eng-GB', + 9, // versionNo + null, + 'foo_view_type', ]; } @@ -176,7 +189,8 @@ public function testPreview( int $contentId, string $language, int $versionNo, - ?int $locationId + ?int $locationId, + ?string $viewType = null ): void { $content = $this->createMock(Content::class); $location = $this->getMockBuilder(Location::class) @@ -200,6 +214,9 @@ public function testPreview( $request = new Request(); $request->attributes->set('semanticPathinfo', '/foo/bar'); + if (null !== $viewType) { + $request->query->set('viewType', $viewType); + } $this->configurePreviewHelper( $content, @@ -212,7 +229,8 @@ public function testPreview( $location, $content, $previewSiteAccess ?? $originalSiteAccess, - $language + $language, + $viewType ); // the actual assertion happens here, checking if the forward request params are correct @@ -240,7 +258,8 @@ private function getExpectedForwardRequestParameters( Location $location, Content $content, SiteAccess $previewSiteAccess, - string $language + string $language, + ?string $viewType ): array { return [ '_controller' => 'ibexa_content::viewAction', @@ -251,7 +270,7 @@ private function getExpectedForwardRequestParameters( ], 'location' => $location, 'content' => $content, - 'viewType' => 'full', + 'viewType' => $viewType ?? 'full', 'layout' => true, 'params' => [ 'content' => $content, From d18a6ce5c72e6481d8b351915456fedf3c2c1318 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Thu, 19 Oct 2023 15:08:59 +0200 Subject: [PATCH 4/5] [PHPStan] Dropped from baseline resolved issues in PreviewController --- phpstan-baseline.neon | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e0bdc8e3f8..8b20995bfb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -11550,31 +11550,6 @@ parameters: count: 1 path: src/lib/MVC/Symfony/ConfigDumperInterface.php - - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Content\\\\PreviewController\\:\\:previewContentAction\\(\\) has no return type specified\\.$#" - count: 1 - path: src/lib/MVC/Symfony/Controller/Content/PreviewController.php - - - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Content\\\\PreviewController\\:\\:previewContentAction\\(\\) has parameter \\$contentId with no type specified\\.$#" - count: 1 - path: src/lib/MVC/Symfony/Controller/Content/PreviewController.php - - - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Content\\\\PreviewController\\:\\:previewContentAction\\(\\) has parameter \\$language with no type specified\\.$#" - count: 1 - path: src/lib/MVC/Symfony/Controller/Content/PreviewController.php - - - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Content\\\\PreviewController\\:\\:previewContentAction\\(\\) has parameter \\$siteAccessName with no type specified\\.$#" - count: 1 - path: src/lib/MVC/Symfony/Controller/Content/PreviewController.php - - - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Content\\\\PreviewController\\:\\:previewContentAction\\(\\) has parameter \\$versionNo with no type specified\\.$#" - count: 1 - path: src/lib/MVC/Symfony/Controller/Content/PreviewController.php - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Content\\\\QueryController\\:\\:runPagingQuery\\(\\) has no return type specified\\.$#" count: 1 From 37f1de089c54f127351c9187b06f787fb9cc9f8f Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Fri, 20 Oct 2023 17:35:50 +0200 Subject: [PATCH 5/5] [PHPStan] Dropped from baseline resolved issues in PreviewControllerTest --- phpstan-baseline.neon | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8b20995bfb..98cbd64acb 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -46505,36 +46505,6 @@ parameters: count: 1 path: tests/lib/MVC/Symfony/Component/Serializer/Stubs/SerializerStub.php - - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Controller\\\\Content\\\\PreviewControllerTest\\:\\:testPreview\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Controller\\\\Content\\\\PreviewControllerTest\\:\\:testPreviewCanUserFail\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Controller\\\\Content\\\\PreviewControllerTest\\:\\:testPreviewDefaultSiteaccess\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Controller\\\\Content\\\\PreviewControllerTest\\:\\:testPreviewUnauthorized\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php - - - - message: "#^Parameter \\#7 \\$controllerChecker of class Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Content\\\\PreviewController constructor expects Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\View\\\\CustomLocationControllerChecker, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Symfony\\\\Component\\\\Security\\\\Core\\\\Authorization\\\\AuthorizationCheckerInterface given\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php - - - - message: "#^Property Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\Controller\\\\Content\\\\PreviewControllerTest\\:\\:\\$controllerChecker \\(PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Symfony\\\\Component\\\\Security\\\\Core\\\\Authorization\\\\AuthorizationCheckerInterface\\) does not accept Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\View\\\\CustomLocationControllerChecker&PHPUnit\\\\Framework\\\\MockObject\\\\MockObject\\.$#" - count: 1 - path: tests/lib/MVC/Symfony/Controller/Controller/Content/PreviewControllerTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Controller\\\\ControllerTest\\:\\:testRender\\(\\) has no return type specified\\.$#" count: 1