1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet; |
6
|
|
|
|
7
|
|
|
use BitBag\SyliusElasticsearchPlugin\Facet\AttributeFacet; |
8
|
|
|
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface; |
9
|
|
|
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface; |
10
|
|
|
use Elastica\Aggregation\Terms; |
11
|
|
|
use PhpSpec\ObjectBehavior; |
12
|
|
|
use Prophecy\Argument; |
13
|
|
|
use Sylius\Component\Attribute\Model\Attribute; |
14
|
|
|
use Sylius\Component\Locale\Context\LocaleContextInterface; |
15
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
16
|
|
|
|
17
|
|
|
final class AttributeFacetSpec extends ObjectBehavior |
18
|
|
|
{ |
19
|
|
|
function let( |
|
|
|
|
20
|
|
|
ConcatedNameResolverInterface $attributeNameResolver, |
21
|
|
|
RepositoryInterface $attributeRepository, |
22
|
|
|
LocaleContextInterface $localeContext |
23
|
|
|
): void { |
24
|
|
|
$attributeNameResolver->resolvePropertyName('attribute_code')->willReturn('attribute_attribute_code'); |
25
|
|
|
$localeContext->getLocaleCode()->willReturn('en_US'); |
26
|
|
|
$this->beConstructedWith($attributeNameResolver, $attributeRepository, $localeContext, 'attribute_code'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function it_is_initializable(): void |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
$this->shouldHaveType(AttributeFacet::class); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_implements_facet_interface(): void |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType(FacetInterface::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_returns_terms_aggregation(): void |
40
|
|
|
{ |
41
|
|
|
$expectedAggregation = new Terms(''); |
42
|
|
|
$expectedAggregation->setField('attribute_attribute_code.keyword'); |
43
|
|
|
|
44
|
|
|
$this->getAggregation()->shouldBeLike($expectedAggregation); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function it_returns_terms_query(): void |
48
|
|
|
{ |
49
|
|
|
$selectedBuckets = ['selected_value']; |
50
|
|
|
$expectedQuery = new \Elastica\Query\Terms('attribute_attribute_code.keyword', $selectedBuckets); |
51
|
|
|
|
52
|
|
|
$this->getQuery($selectedBuckets)->shouldBeLike($expectedQuery); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
function it_returns_bucket_label_from_config_for_select_attribute(RepositoryInterface $attributeRepository): void |
56
|
|
|
{ |
57
|
|
|
$attribute = new Attribute(); |
58
|
|
|
$attribute->setType('select'); |
59
|
|
|
$attribute->setConfiguration(['choices' => ['value_id' => ['en_US' => 'Value Label']]]); |
60
|
|
|
$attributeRepository->findOneBy(['code' => 'attribute_code'])->willReturn($attribute); |
61
|
|
|
|
62
|
|
|
$this->getBucketLabel(['key' => 'value_id', 'doc_count' => 3])->shouldReturn('Value Label (3)'); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function it_returns_human_readable_bucket_label_for_text_attribute(RepositoryInterface $attributeRepository): void |
66
|
|
|
{ |
67
|
|
|
$attribute = new Attribute(); |
68
|
|
|
$attribute->setType('text'); |
69
|
|
|
$attributeRepository->findOneBy(['code' => 'attribute_code'])->willReturn($attribute); |
70
|
|
|
|
71
|
|
|
$this->getBucketLabel(['key' => 'green_&_white', 'doc_count' => 3])->shouldReturn('Green & White (3)'); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.