From 6ed7e4e1b795fe4896e83412fddb67a111eb4d10 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Fri, 20 Oct 2023 18:12:59 +0200 Subject: [PATCH] [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 e21b92a7ba..a75537583a 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,