Skip to content

Commit da045c3

Browse files
committed
Merge remote-tracking branch 'origin/4.6'
2 parents 30e5e1a + b68ebb9 commit da045c3

File tree

7 files changed

+212
-36
lines changed

7 files changed

+212
-36
lines changed

src/lib/FieldMapper/ContentFieldMapper/UserDocumentFields.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public function mapFields(SPIContent $content): array
4848
);
4949
}
5050

51+
if (isset($userField->value->externalData['enabled'])) {
52+
$fields[] = new Field(
53+
'user_is_enabled',
54+
$userField->value->externalData['enabled'],
55+
new FieldType\BooleanField()
56+
);
57+
}
58+
5159
return $fields;
5260
}
5361

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Solr\Query\Common\CriterionVisitor;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
12+
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
13+
14+
final class IsUserEnabled extends CriterionVisitor
15+
{
16+
private const SEARCH_FIELD = 'user_is_enabled_b';
17+
18+
public function canVisit(Criterion $criterion): bool
19+
{
20+
return $criterion instanceof Criterion\IsUserEnabled;
21+
}
22+
23+
public function visit(Criterion $criterion, CriterionVisitor $subVisitor = null): string
24+
{
25+
$value = $criterion->value;
26+
if (!is_array($value) || !is_bool($value[0])) {
27+
throw new \LogicException(
28+
sprintf(
29+
'%s value should be of type array<bool>, received %s.',
30+
Criterion\IsUserEnabled::class,
31+
get_debug_type($value),
32+
)
33+
);
34+
}
35+
36+
return self::SEARCH_FIELD . ':' . $this->toString($value[0]);
37+
}
38+
}

src/lib/Resources/config/container/solr/criterion_visitors.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,7 @@ services:
348348
tags:
349349
- { name: ibexa.search.solr.query.content.criterion.visitor }
350350
- { name: ibexa.search.solr.query.location.criterion.visitor }
351+
352+
Ibexa\Solr\Query\Common\CriterionVisitor\IsUserEnabled:
353+
tags:
354+
- { name: ibexa.search.solr.query.content.criterion.visitor }
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Solr\Search\Query;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
12+
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
13+
use Ibexa\Tests\Solr\Search\Query\Utils\Stub\TestCriterion;
14+
use PHPUnit\Framework\TestCase;
15+
16+
abstract class BaseCriterionVisitorTestCase extends TestCase
17+
{
18+
abstract protected function getVisitor(): CriterionVisitor;
19+
20+
abstract protected function getSupportedCriterion(): Criterion;
21+
22+
/**
23+
* @return iterable<array{
24+
* string,
25+
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion
26+
* }>
27+
*/
28+
abstract protected function provideDataForTestVisit(): iterable;
29+
30+
/**
31+
* @dataProvider provideDataForTestCanVisit
32+
*/
33+
public function testCanVisit(
34+
bool $expected,
35+
Criterion $criterion
36+
): void {
37+
self::assertSame(
38+
$expected,
39+
$this->getVisitor()->canVisit($criterion)
40+
);
41+
}
42+
43+
/**
44+
* @return iterable<array{
45+
* bool,
46+
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion
47+
* }>
48+
*/
49+
public function provideDataForTestCanVisit(): iterable
50+
{
51+
yield 'Not supported criterion' => [
52+
false,
53+
new TestCriterion(),
54+
];
55+
56+
yield 'Supported criterion' => [
57+
true,
58+
$this->getSupportedCriterion(),
59+
];
60+
}
61+
62+
/**
63+
* @dataProvider provideDataForTestVisit
64+
*/
65+
public function testVisit(
66+
string $expectedQuery,
67+
Criterion $criterion
68+
): void {
69+
self::assertSame(
70+
$expectedQuery,
71+
$this->getVisitor()->visit($criterion)
72+
);
73+
}
74+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Solr\Search\Query\Common\CriterionVisitor;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
12+
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
13+
use Ibexa\Solr\Query\Common\CriterionVisitor\IsUserEnabled;
14+
use Ibexa\Tests\Solr\Search\Query\BaseCriterionVisitorTestCase;
15+
16+
/**
17+
* @covers \Ibexa\Solr\Query\Common\CriterionVisitor\IsUserEnabled
18+
*/
19+
final class IsUserEnabledTest extends BaseCriterionVisitorTestCase
20+
{
21+
private CriterionVisitor $criterionVisitor;
22+
23+
protected function setUp(): void
24+
{
25+
$this->criterionVisitor = new IsUserEnabled();
26+
}
27+
28+
protected function getVisitor(): CriterionVisitor
29+
{
30+
return $this->criterionVisitor;
31+
}
32+
33+
protected function getSupportedCriterion(): Criterion
34+
{
35+
return new Criterion\IsUserEnabled();
36+
}
37+
38+
protected function provideDataForTestVisit(): iterable
39+
{
40+
yield 'Query for enabled user' => [
41+
'user_is_enabled_b:true',
42+
new Criterion\IsUserEnabled(),
43+
];
44+
45+
yield 'Query for disabled user' => [
46+
'user_is_enabled_b:false',
47+
new Criterion\IsUserEnabled(false),
48+
];
49+
}
50+
}

tests/lib/Search/Query/Location/CriterionVisitor/Location/IsBookmarkedTest.php

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
1414
use Ibexa\Core\Repository\Values\User\UserReference;
1515
use Ibexa\Solr\Query\Location\CriterionVisitor\Location\IsBookmarked;
16-
use PHPUnit\Framework\TestCase;
16+
use Ibexa\Tests\Solr\Search\Query\BaseCriterionVisitorTestCase;
1717

1818
/**
1919
* @covers \Ibexa\Solr\Query\Location\CriterionVisitor\Location\IsBookmarked
2020
*/
21-
final class IsBookmarkedTest extends TestCase
21+
final class IsBookmarkedTest extends BaseCriterionVisitorTestCase
2222
{
2323
private const USER_ID = 123;
2424

@@ -33,49 +33,17 @@ protected function setUp(): void
3333
$this->visitor = new IsBookmarked($this->permissionResolver);
3434
}
3535

36-
/**
37-
* @dataProvider provideDataForTestCanVisit
38-
*/
39-
public function testCanVisit(
40-
bool $expected,
41-
Criterion $criterion
42-
): void {
43-
self::assertSame(
44-
$expected,
45-
$this->visitor->canVisit($criterion)
46-
);
47-
}
48-
49-
/**
50-
* @return iterable<array{
51-
* bool,
52-
* \Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion
53-
* }>
54-
*/
55-
public function provideDataForTestCanVisit(): iterable
56-
{
57-
yield 'Not supported criterion' => [
58-
false,
59-
new Criterion\ContentId(123),
60-
];
61-
62-
yield 'Supported criterion' => [
63-
true,
64-
new Criterion\Location\IsBookmarked(),
65-
];
66-
}
67-
6836
/**
6937
* @dataProvider provideDataForTestVisit
7038
*/
7139
public function testVisit(
72-
string $expected,
40+
string $expectedQuery,
7341
Criterion $criterion
7442
): void {
7543
$this->mockPermissionResolverGetCurrentUserReference();
7644

7745
self::assertSame(
78-
$expected,
46+
$expectedQuery,
7947
$this->visitor->visit($criterion)
8048
);
8149
}
@@ -105,4 +73,14 @@ private function mockPermissionResolverGetCurrentUserReference(): void
10573
->method('getCurrentUserReference')
10674
->willReturn(new UserReference(self::USER_ID));
10775
}
76+
77+
protected function getVisitor(): CriterionVisitor
78+
{
79+
return $this->visitor;
80+
}
81+
82+
protected function getSupportedCriterion(): Criterion
83+
{
84+
return new Criterion\Location\IsBookmarked();
85+
}
10886
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Solr\Search\Query\Utils\Stub;
10+
11+
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
12+
13+
final class TestCriterion extends Criterion
14+
{
15+
public function __construct()
16+
{
17+
// No implementation needed. Used for test purposes only.
18+
}
19+
20+
public function getSpecifications(): array
21+
{
22+
return [];
23+
}
24+
}

0 commit comments

Comments
 (0)