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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\UiBundle\Registry; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Bundle\UiBundle\Registry\TemplateBlock; |
18
|
|
|
|
19
|
|
|
final class TemplateBlockSpec extends ObjectBehavior |
20
|
|
|
{ |
21
|
|
|
function it_represents_a_template_block(): void |
22
|
|
|
{ |
23
|
|
|
$this->beConstructedWith('block_name', 'event_name', 'block.html.twig', ['foo' => 'bar'], 10, false); |
24
|
|
|
|
25
|
|
|
$this->getName()->shouldReturn('block_name'); |
26
|
|
|
$this->getEventName()->shouldReturn('event_name'); |
27
|
|
|
$this->getTemplate()->shouldReturn('block.html.twig'); |
28
|
|
|
$this->getContext()->shouldReturn(['foo' => 'bar']); |
29
|
|
|
$this->getPriority()->shouldReturn(10); |
30
|
|
|
$this->isEnabled()->shouldReturn(false); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_overwrites_a_template_block_with_an_another_template_block(): void |
34
|
|
|
{ |
35
|
|
|
$this->beConstructedWith('block_name', 'event_name', 'block.html.twig', ['foo' => 'bar'], 10, false); |
36
|
|
|
|
37
|
|
|
$this |
38
|
|
|
->overwriteWith(new TemplateBlock('block_name', 'specific_event_name', 'another.html.twig', null, null, null)) |
39
|
|
|
->shouldBeLike(new TemplateBlock('block_name', 'specific_event_name', 'another.html.twig', ['foo' => 'bar'], 10, false)) |
40
|
|
|
; |
41
|
|
|
|
42
|
|
|
$this |
43
|
|
|
->overwriteWith(new TemplateBlock('block_name', 'specific_event_name', null, [], null, null)) |
44
|
|
|
->shouldBeLike(new TemplateBlock('block_name', 'specific_event_name', 'block.html.twig', [], 10, false)) |
45
|
|
|
; |
46
|
|
|
|
47
|
|
|
$this |
48
|
|
|
->overwriteWith(new TemplateBlock('block_name', 'specific_event_name', null, null, -5, null)) |
49
|
|
|
->shouldBeLike(new TemplateBlock('block_name', 'specific_event_name', 'block.html.twig', ['foo' => 'bar'], -5, false)) |
50
|
|
|
; |
51
|
|
|
|
52
|
|
|
$this |
53
|
|
|
->overwriteWith(new TemplateBlock('block_name', 'specific_event_name', null, null, null, true)) |
54
|
|
|
->shouldBeLike(new TemplateBlock('block_name', 'specific_event_name', 'block.html.twig', ['foo' => 'bar'], 10, true)) |
55
|
|
|
; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function it_throws_an_exception_if_trying_to_overwrite_with_a_differently_named_block(): void |
59
|
|
|
{ |
60
|
|
|
$this->beConstructedWith('block_name', 'event_name', 'block.html.twig', ['foo' => 'bar'], 10, false); |
61
|
|
|
|
62
|
|
|
$this->shouldThrow(\DomainException::class)->during('overwriteWith', [new TemplateBlock('different_name', 'specific_event_name', null, null, null, null)]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
function it_has_sensible_defaults(): void |
66
|
|
|
{ |
67
|
|
|
$this->beConstructedWith('block_name', 'event_name', null, null, null, null); |
68
|
|
|
|
69
|
|
|
$this->shouldThrow(\DomainException::class)->during('getTemplate'); |
70
|
|
|
$this->getContext()->shouldReturn([]); |
71
|
|
|
$this->getPriority()->shouldReturn(0); |
72
|
|
|
$this->isEnabled()->shouldReturn(true); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|