-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
tests/lib/Search/Query/Location/CriterionVisitor/Location/IsBookmarkedTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
/** | ||
* @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\Solr\Search\Query\Location\CriterionVisitor\Location; | ||
|
||
use Ibexa\Contracts\Core\Repository\PermissionResolver; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
use Ibexa\Core\Repository\Values\User\UserReference; | ||
use Ibexa\Solr\Query\Location\CriterionVisitor\Location\IsBookmarked; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers \Ibexa\Solr\Query\Location\CriterionVisitor\Location\IsBookmarked | ||
*/ | ||
final class IsBookmarkedTest extends TestCase | ||
{ | ||
private const USER_ID = 123; | ||
|
||
private CriterionVisitor $visitor; | ||
|
||
/** @var \Ibexa\Contracts\Core\Repository\PermissionResolver&\PHPUnit\Framework\MockObject\MockObject */ | ||
private PermissionResolver $permissionResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->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<array{ | ||
* bool, | ||
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion | ||
* }> | ||
*/ | ||
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<array{ | ||
* string, | ||
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion | ||
* }> | ||
*/ | ||
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)); | ||
} | ||
} |