-
Notifications
You must be signed in to change notification settings - Fork 6
IBX-9121: Added support for IsUserEnabled criterion #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Steveb-p
merged 10 commits into
4.6
from
ibx-9121-support-for-is-user-enabled-criterion
Oct 30, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
118afaa
Added IsUserEnabled
ciastektk db662af
[DI] Added service definition
ciastektk f8cf237
Added index field user_is_enabled
ciastektk d8da5ed
[Tests] Added BaseCriterionVisitorTestCase
ciastektk f5e1e2f
[Tests] Added IsUserEnabledTest
ciastektk 193fce6
[Tests] Adjusted IsBookmarkedTest
ciastektk 05ed457
[Tests] Added TestCriterion
ciastektk dbaf252
[Tests] Adjusted BaseCriterionVisitorTestCase
ciastektk de0b636
Fixed cs
ciastektk 2e80804
[SonarCloud] Fixed reported issue
ciastektk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,38 @@ | ||
| <?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\Solr\Query\Common\CriterionVisitor; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
|
|
||
| final class IsUserEnabled extends CriterionVisitor | ||
| { | ||
| private const SEARCH_FIELD = 'user_is_enabled_b'; | ||
|
|
||
| public function canVisit(Criterion $criterion): bool | ||
| { | ||
| return $criterion instanceof Criterion\IsUserEnabled; | ||
| } | ||
|
|
||
| public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null): string | ||
| { | ||
| $value = $criterion->value; | ||
| if (!is_array($value) || !is_bool($value[0])) { | ||
| throw new \LogicException( | ||
| sprintf( | ||
| '%s value should be of type array<bool>, received %s.', | ||
| Criterion\IsUserEnabled::class, | ||
| get_debug_type($value), | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| return self::SEARCH_FIELD . ':' . $this->toString($value[0]); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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,74 @@ | ||
| <?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; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
| use Ibexa\Tests\Solr\Search\Query\Utils\Stub\TestCriterion; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| abstract class BaseCriterionVisitorTestCase extends TestCase | ||
| { | ||
| abstract protected function getVisitor(): CriterionVisitor; | ||
|
|
||
| abstract protected function getSupportedCriterion(): Criterion; | ||
|
|
||
| /** | ||
| * @return iterable<array{ | ||
| * string, | ||
| * \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion | ||
| * }> | ||
| */ | ||
| abstract protected function provideDataForTestVisit(): iterable; | ||
|
|
||
| /** | ||
| * @dataProvider provideDataForTestCanVisit | ||
| */ | ||
| public function testCanVisit( | ||
| bool $expected, | ||
| Criterion $criterion | ||
| ): void { | ||
| self::assertSame( | ||
| $expected, | ||
| $this->getVisitor()->canVisit($criterion) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @return iterable<array{ | ||
| * bool, | ||
| * \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion | ||
| * }> | ||
| */ | ||
| public function provideDataForTestCanVisit(): iterable | ||
| { | ||
| yield 'Not supported criterion' => [ | ||
| false, | ||
| new TestCriterion(), | ||
| ]; | ||
|
|
||
| yield 'Supported criterion' => [ | ||
| true, | ||
| $this->getSupportedCriterion(), | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider provideDataForTestVisit | ||
| */ | ||
| public function testVisit( | ||
| string $expectedQuery, | ||
| Criterion $criterion | ||
| ): void { | ||
| self::assertSame( | ||
| $expectedQuery, | ||
| $this->getVisitor()->visit($criterion) | ||
| ); | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
tests/lib/Search/Query/Common/CriterionVisitor/IsUserEnabledTest.php
This file contains hidden or 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,50 @@ | ||
| <?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\Common\CriterionVisitor; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
| use Ibexa\Contracts\Solr\Query\CriterionVisitor; | ||
| use Ibexa\Solr\Query\Common\CriterionVisitor\IsUserEnabled; | ||
| use Ibexa\Tests\Solr\Search\Query\BaseCriterionVisitorTestCase; | ||
|
|
||
| /** | ||
| * @covers \Ibexa\Solr\Query\Common\CriterionVisitor\IsUserEnabled | ||
| */ | ||
| final class IsUserEnabledTest extends BaseCriterionVisitorTestCase | ||
| { | ||
| private CriterionVisitor $criterionVisitor; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| $this->criterionVisitor = new IsUserEnabled(); | ||
| } | ||
|
|
||
| protected function getVisitor(): CriterionVisitor | ||
| { | ||
| return $this->criterionVisitor; | ||
| } | ||
|
|
||
| protected function getSupportedCriterion(): Criterion | ||
| { | ||
| return new Criterion\IsUserEnabled(); | ||
| } | ||
|
|
||
| protected function provideDataForTestVisit(): iterable | ||
| { | ||
| yield 'Query for enabled user' => [ | ||
| 'user_is_enabled_b:true', | ||
| new Criterion\IsUserEnabled(), | ||
| ]; | ||
|
|
||
| yield 'Query for disabled user' => [ | ||
| 'user_is_enabled_b:false', | ||
| new Criterion\IsUserEnabled(false), | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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,24 @@ | ||
| <?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\Utils\Stub; | ||
|
|
||
| use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; | ||
|
|
||
| final class TestCriterion extends Criterion | ||
| { | ||
| public function __construct() | ||
| { | ||
| // No implementation needed. Used for test purposes only. | ||
| } | ||
|
|
||
| public function getSpecifications(): array | ||
| { | ||
| return []; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.