|
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\Repository\TaxonRepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Mateusz Zalewski <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class TaxonSlugGeneratorSpec extends ObjectBehavior |
|
24
|
|
|
{ |
|
25
|
|
|
function let(TaxonRepositoryInterface $taxonRepository) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->beConstructedWith($taxonRepository); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_is_initializable() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->shouldHaveType(TaxonSlugGenerator::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function it_implements_taxon_slug_generator_interface() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->shouldImplement(TaxonSlugGeneratorInterface::class); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
function it_generates_slug_based_on_new_taxon_name_and_parent_taxon_slug( |
|
41
|
|
|
TaxonInterface $parent, |
|
42
|
|
|
TaxonRepositoryInterface $taxonRepository |
|
43
|
|
|
) { |
|
44
|
|
|
$taxonRepository->find(1)->willReturn($parent); |
|
45
|
|
|
$parent->getSlug()->willReturn('board-games'); |
|
46
|
|
|
|
|
47
|
|
|
$this->generate('Battle games', 1)->shouldReturn('board-games/battle-games');; |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function it_generates_slug_based_on_new_taxon_name_if_this_taxon_has_no_parent() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->generate('Board games')->shouldReturn('board-games');; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
function it_throws_exception_if_parent_taxon_with_given_id_does_not_exist( |
|
56
|
|
|
TaxonRepositoryInterface $taxonRepository |
|
57
|
|
|
) { |
|
58
|
|
|
$taxonRepository->find(1)->willReturn(null); |
|
59
|
|
|
|
|
60
|
|
|
$this |
|
61
|
|
|
->shouldThrow(new \InvalidArgumentException('There is no parent taxon with id 1.')) |
|
62
|
|
|
->during('generate', ['Battle games', 1]) |
|
63
|
|
|
; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Let’s take a look at an example: