From f84fd04fde3808c7a802ca00c4fa9902bbe6c697 Mon Sep 17 00:00:00 2001 From: Tomasz Kryszan Date: Mon, 26 Aug 2024 12:01:50 +0200 Subject: [PATCH] [Tests] Added IsBookmarkedTest --- .../Location/IsBookmarkedTest.php | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/lib/Search/Query/Location/CriterionVisitor/Location/IsBookmarkedTest.php diff --git a/tests/lib/Search/Query/Location/CriterionVisitor/Location/IsBookmarkedTest.php b/tests/lib/Search/Query/Location/CriterionVisitor/Location/IsBookmarkedTest.php new file mode 100644 index 00000000..aa242b96 --- /dev/null +++ b/tests/lib/Search/Query/Location/CriterionVisitor/Location/IsBookmarkedTest.php @@ -0,0 +1,108 @@ +permissionResolver = $this->createMock(PermissionResolver::class); + $this->visitor = new IsBookmarked($this->permissionResolver); + } + + /** + * @dataProvider provideDataForTestCanVisit + */ + public function testCanVisit( + bool $expected, + Criterion $criterion + ): void { + self::assertSame( + $expected, + $this->visitor->canVisit($criterion) + ); + } + + /** + * @return iterable + */ + public function provideDataForTestCanVisit(): iterable + { + yield 'Not supported criterion' => [ + false, + new Criterion\ContentId(123), + ]; + + yield 'Supported criterion' => [ + true, + new Criterion\Location\IsBookmarked(), + ]; + } + + /** + * @dataProvider provideDataForTestVisit + */ + public function testVisit( + string $expected, + Criterion $criterion + ): void { + $this->mockPermissionResolverGetCurrentUserReference(); + + self::assertSame( + $expected, + $this->visitor->visit($criterion) + ); + } + + /** + * @return iterable + */ + public function provideDataForTestVisit(): iterable + { + yield 'Query for bookmarked locations' => [ + 'location_bookmarked_user_ids_mid:"123"', + new Criterion\Location\IsBookmarked(), + ]; + + yield 'Query for not bookmarked locations' => [ + 'NOT location_bookmarked_user_ids_mid:"123"', + new Criterion\Location\IsBookmarked(false), + ]; + } + + private function mockPermissionResolverGetCurrentUserReference(): void + { + $this->permissionResolver + ->method('getCurrentUserReference') + ->willReturn(new UserReference(self::USER_ID)); + } +}