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\Bundle\ThemeBundle\Templating\Locator; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Cache\Cache; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Prophecy\Argument; |
17
|
|
|
use Sylius\Bundle\ThemeBundle\Locator\ResourceNotFoundException; |
18
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
19
|
|
|
use Sylius\Bundle\ThemeBundle\Templating\Locator\CachedTemplateLocator; |
20
|
|
|
use Sylius\Bundle\ThemeBundle\Templating\Locator\TemplateLocatorInterface; |
21
|
|
|
use Symfony\Component\Templating\TemplateReferenceInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @mixin CachedTemplateLocator |
25
|
|
|
* |
26
|
|
|
* @author Kamil Kokot <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class CachedTemplateLocatorSpec extends ObjectBehavior |
29
|
|
|
{ |
30
|
|
|
function let(TemplateLocatorInterface $decoratedTemplateLocator, Cache $cache) |
31
|
|
|
{ |
32
|
|
|
$this->beConstructedWith($decoratedTemplateLocator, $cache); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_is_initializable() |
36
|
|
|
{ |
37
|
|
|
$this->shouldHaveType('Sylius\Bundle\ThemeBundle\Templating\Locator\CachedTemplateLocator'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_implements_template_locator_interface() |
41
|
|
|
{ |
42
|
|
|
$this->shouldImplement(TemplateLocatorInterface::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_returns_the_location_found_in_cache( |
46
|
|
|
TemplateLocatorInterface $decoratedTemplateLocator, |
47
|
|
|
Cache $cache, |
48
|
|
|
TemplateReferenceInterface $template, |
49
|
|
|
ThemeInterface $theme |
50
|
|
|
) { |
51
|
|
|
$template->getLogicalName()->willReturn('Logical:Name'); |
52
|
|
|
$theme->getSlug()->willReturn('theme/slug'); |
53
|
|
|
|
54
|
|
|
$cache->contains('Logical:Name|theme/slug')->willReturn(true); |
55
|
|
|
$cache->fetch('Logical:Name|theme/slug')->willReturn('/template.html.twig'); |
56
|
|
|
|
57
|
|
|
$decoratedTemplateLocator->locateTemplate(Argument::cetera())->shouldNotBeCalled(); |
58
|
|
|
|
59
|
|
|
$this->locateTemplate($template, $theme)->shouldReturn('/template.html.twig'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function it_uses_decorated_template_locator_if_location_can_not_be_found_in_cache( |
63
|
|
|
TemplateLocatorInterface $decoratedTemplateLocator, |
64
|
|
|
Cache $cache, |
65
|
|
|
TemplateReferenceInterface $template, |
66
|
|
|
ThemeInterface $theme |
67
|
|
|
) { |
68
|
|
|
$template->getLogicalName()->willReturn('Logical:Name'); |
69
|
|
|
$theme->getSlug()->willReturn('theme/slug'); |
70
|
|
|
|
71
|
|
|
$cache->contains('Logical:Name|theme/slug')->willReturn(false); |
72
|
|
|
$cache->fetch(Argument::cetera())->shouldNotBeCalled(); |
73
|
|
|
|
74
|
|
|
$decoratedTemplateLocator->locateTemplate($template, $theme)->willReturn('/template.html.twig'); |
75
|
|
|
|
76
|
|
|
$this->locateTemplate($template, $theme)->shouldReturn('/template.html.twig'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function it_throws_resource_not_found_exception_if_the_location_found_in_cache_is_null( |
80
|
|
|
TemplateLocatorInterface $decoratedTemplateLocator, |
81
|
|
|
Cache $cache, |
82
|
|
|
TemplateReferenceInterface $template, |
83
|
|
|
ThemeInterface $theme |
84
|
|
|
) { |
85
|
|
|
$template->getLogicalName()->willReturn('Logical:Name'); |
86
|
|
|
$template->getPath()->willReturn('@Acme/template.html.twig'); |
87
|
|
|
$theme->getSlug()->willReturn('theme/slug'); |
88
|
|
|
|
89
|
|
|
$cache->contains('Logical:Name|theme/slug')->willReturn(true); |
90
|
|
|
$cache->fetch('Logical:Name|theme/slug')->willReturn(null); |
91
|
|
|
|
92
|
|
|
$decoratedTemplateLocator->locateTemplate(Argument::cetera())->shouldNotBeCalled(); |
93
|
|
|
|
94
|
|
|
$this->shouldThrow(ResourceNotFoundException::class)->during('locateTemplate', [$template, $theme]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|