1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\Sylius\Component\Taxonomy\Generator; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Component\Taxonomy\Generator\TaxonSlugGenerator; |
16
|
|
|
use Sylius\Component\Taxonomy\Generator\TaxonSlugGeneratorInterface; |
17
|
|
|
use Sylius\Component\Taxonomy\Model\TaxonInterface; |
18
|
|
|
use Sylius\Component\Taxonomy\Model\TaxonTranslationInterface; |
19
|
|
|
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; |
20
|
|
|
|
21
|
|
|
final class TaxonSlugGeneratorSpec extends ObjectBehavior |
22
|
|
|
{ |
23
|
|
|
function it_implements_taxon_slug_generator_interface() |
24
|
|
|
{ |
25
|
|
|
$this->shouldImplement(TaxonSlugGeneratorInterface::class); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_generates_slug_for_root_taxon( |
29
|
|
|
TaxonInterface $taxon, |
30
|
|
|
TaxonTranslationInterface $taxonTranslation |
31
|
|
|
) { |
32
|
|
|
$taxon->getTranslation('pl_PL')->willReturn($taxonTranslation); |
33
|
|
|
$taxonTranslation->getName()->willReturn('Board games'); |
34
|
|
|
|
35
|
|
|
$taxon->getParent()->willReturn(null); |
36
|
|
|
|
37
|
|
|
$this->generate($taxon, 'pl_PL')->shouldReturn('board-games'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_generates_slug_for_root_taxon_replacing_apostrophes_with_hyphens( |
41
|
|
|
TaxonInterface $taxon, |
42
|
|
|
TaxonTranslationInterface $taxonTranslation |
43
|
|
|
) { |
44
|
|
|
$taxon->getTranslation('pl_PL')->willReturn($taxonTranslation); |
45
|
|
|
$taxonTranslation->getName()->willReturn('Rock\'n\'roll'); |
46
|
|
|
|
47
|
|
|
$taxon->getParent()->willReturn(null); |
48
|
|
|
|
49
|
|
|
$this->generate($taxon, 'pl_PL')->shouldReturn('rock-n-roll'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function it_generates_slug_for_child_taxon_when_parent_taxon_already_has_slug( |
53
|
|
|
TaxonInterface $taxon, |
54
|
|
|
TaxonTranslationInterface $taxonTranslation, |
55
|
|
|
TaxonInterface $parentTaxon, |
56
|
|
|
TaxonTranslationInterface $parentTaxonTranslation |
|
|
|
|
57
|
|
|
) { |
58
|
|
|
$taxon->getTranslation('pl_PL')->willReturn($taxonTranslation); |
59
|
|
|
$taxonTranslation->getName()->willReturn('Battle games'); |
60
|
|
|
|
61
|
|
|
$taxon->getParent()->willReturn($parentTaxon); |
62
|
|
|
|
63
|
|
|
$parentTaxon->getTranslation('pl_PL')->willReturn($parentTaxonTranslation); |
64
|
|
|
$parentTaxonTranslation->getSlug()->willReturn('board-games'); |
65
|
|
|
|
66
|
|
|
$this->generate($taxon, 'pl_PL')->shouldReturn('board-games/battle-games'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
function it_generates_slug_for_child_taxon_even_when_parent_taxon_does_not_have_slug( |
70
|
|
|
TaxonInterface $taxon, |
71
|
|
|
TaxonTranslationInterface $taxonTranslation, |
72
|
|
|
TaxonInterface $parentTaxon, |
73
|
|
|
TaxonTranslationInterface $parentTaxonTranslation |
|
|
|
|
74
|
|
|
) { |
75
|
|
|
$taxon->getTranslation('pl_PL')->willReturn($taxonTranslation); |
76
|
|
|
$taxonTranslation->getName()->willReturn('Battle games'); |
77
|
|
|
|
78
|
|
|
$taxon->getParent()->willReturn($parentTaxon); |
79
|
|
|
|
80
|
|
|
$parentTaxon->getTranslation('pl_PL')->willReturn($parentTaxonTranslation); |
81
|
|
|
$parentTaxonTranslation->getSlug()->willReturn(null); |
82
|
|
|
$parentTaxonTranslation->getName()->willReturn('Board games'); |
83
|
|
|
|
84
|
|
|
$parentTaxon->getParent()->willReturn(null); |
85
|
|
|
|
86
|
|
|
$this->generate($taxon, 'pl_PL')->shouldReturn('board-games/battle-games'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function it_throws_an_exception_if_passed_taxon_has_no_name( |
90
|
|
|
TaxonInterface $taxon, |
91
|
|
|
TaxonTranslationInterface $taxonTranslation |
92
|
|
|
) { |
93
|
|
|
$taxon->getTranslation('pl_PL')->willReturn($taxonTranslation); |
94
|
|
|
$taxonTranslation->getName()->willReturn(''); |
95
|
|
|
|
96
|
|
|
$taxon->getParent()->willReturn(null); |
97
|
|
|
|
98
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('generate', [$taxon, 'pl_PL']); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.