From 10132c37ddf448d37b62abb25919e83c8bd70e86 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Mon, 23 Oct 2023 22:13:35 +0200 Subject: [PATCH] [Tests] Added unit test coverage for IsPreview View Matcher --- .../Matcher/ContentBased/IsPreviewTest.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 tests/lib/MVC/Symfony/Matcher/ContentBased/IsPreviewTest.php diff --git a/tests/lib/MVC/Symfony/Matcher/ContentBased/IsPreviewTest.php b/tests/lib/MVC/Symfony/Matcher/ContentBased/IsPreviewTest.php new file mode 100644 index 0000000000..114ce35369 --- /dev/null +++ b/tests/lib/MVC/Symfony/Matcher/ContentBased/IsPreviewTest.php @@ -0,0 +1,96 @@ +isPreviewMatcher = new IsPreview(); + } + + /** + * @return iterable + */ + public static function getDataForTestMatch(): iterable + { + $previewContentView = new ContentView(); + $previewContentView->setParameters(['isPreview' => true]); + + $notPreviewContentView = new ContentView(); + $notPreviewContentView->setParameters(['isPreview' => false]); + + $viewContentView = new ContentView(); + yield 'match for preview content view' => [ + $previewContentView, + true, // IsPreview: true + true, // matches the view + ]; + + yield 'do not match for preview content view' => [ + $previewContentView, + false, // IsPreview: false + false, // doesn't match the view + ]; + + yield 'match for view content view' => [ + $notPreviewContentView, + false, // IsPreview: false + true, // matches since it's not a preview content view + ]; + + yield 'do not match for view content view' => [ + $notPreviewContentView, + true, // IsPreview: true + false, // doesn't match since it's not a preview content view + ]; + + yield 'not match for not set isPreview parameter' => [ + $viewContentView, + true, // IsPreview: true + false, // by default, it's not a preview view if parameter is not set + ]; + + yield 'do not match for not set isPreview parameter' => [ + $viewContentView, + false, + true, // matches not a preview view, when parameter is not set + ]; + } + + /** + * @dataProvider getDataForTestMatch + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ + public function testMatch(View $view, bool $matchConfig, bool $expectedIsPreview): void + { + $this->isPreviewMatcher->setMatchingConfig($matchConfig); + + self::assertSame($expectedIsPreview, $this->isPreviewMatcher->match($view)); + } + + public function testSetMatchConfigThrowsInvalidArgumentException(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('IsPreview matcher expects true or false value, got a value of integer type'); + $this->isPreviewMatcher->setMatchingConfig(123); + } +}