|
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 PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Prophecy\Argument; |
|
16
|
|
|
use Sylius\Bundle\ThemeBundle\Context\ThemeContextInterface; |
|
17
|
|
|
use Sylius\Bundle\ThemeBundle\Locator\ResourceNotFoundException; |
|
18
|
|
|
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface; |
|
19
|
|
|
use Sylius\Bundle\ThemeBundle\Templating\Locator\TemplateFileLocator; |
|
20
|
|
|
use Sylius\Bundle\ThemeBundle\Templating\Locator\TemplateLocatorInterface; |
|
21
|
|
|
use Symfony\Component\Config\FileLocatorInterface; |
|
22
|
|
|
use Symfony\Component\Templating\TemplateReferenceInterface; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @mixin TemplateFileLocator |
|
26
|
|
|
* |
|
27
|
|
|
* @author Kamil Kokot <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class TemplateFileLocatorSpec extends ObjectBehavior |
|
30
|
|
|
{ |
|
31
|
|
|
function let( |
|
32
|
|
|
FileLocatorInterface $decoratedFileLocator, |
|
33
|
|
|
ThemeContextInterface $themeContext, |
|
34
|
|
|
TemplateLocatorInterface $templateLocator |
|
35
|
|
|
) { |
|
36
|
|
|
$this->beConstructedWith($decoratedFileLocator, $themeContext, $templateLocator); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_is_initializable() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldHaveType('Sylius\Bundle\ThemeBundle\Templating\Locator\TemplateFileLocator'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_implements_file_locator_interface() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->shouldImplement(FileLocatorInterface::class); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_throws_an_exception_if_located_thing_is_not_an_instance_of_template_reference_interface() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->shouldThrow(\InvalidArgumentException::class)->during('locate', ['not an instance']); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_returns_first_possible_theme_resource( |
|
55
|
|
|
ThemeContextInterface $themeContext, |
|
56
|
|
|
TemplateLocatorInterface $templateLocator, |
|
57
|
|
|
TemplateReferenceInterface $template, |
|
58
|
|
|
ThemeInterface $firstTheme, |
|
59
|
|
|
ThemeInterface $secondTheme |
|
60
|
|
|
) { |
|
61
|
|
|
$themeContext->getThemeHierarchy()->willReturn([$firstTheme, $secondTheme]); |
|
62
|
|
|
|
|
63
|
|
|
$templateLocator->locateTemplate($template, $firstTheme)->willThrow(ResourceNotFoundException::class); |
|
64
|
|
|
$templateLocator->locateTemplate($template, $secondTheme)->willReturn('/second/theme/template/path'); |
|
65
|
|
|
|
|
66
|
|
|
$this->locate($template)->shouldReturn('/second/theme/template/path'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function it_falls_back_to_decorated_template_locator_if_themed_tempaltes_can_not_be_found( |
|
70
|
|
|
FileLocatorInterface $decoratedFileLocator, |
|
71
|
|
|
ThemeContextInterface $themeContext, |
|
72
|
|
|
TemplateLocatorInterface $templateLocator, |
|
73
|
|
|
TemplateReferenceInterface $template, |
|
74
|
|
|
ThemeInterface $theme |
|
75
|
|
|
) { |
|
76
|
|
|
$themeContext->getThemeHierarchy()->willReturn([$theme]); |
|
77
|
|
|
|
|
78
|
|
|
$templateLocator->locateTemplate($template, $theme)->willThrow(ResourceNotFoundException::class); |
|
79
|
|
|
|
|
80
|
|
|
$decoratedFileLocator->locate($template, Argument::cetera())->willReturn('/app/template/path'); |
|
81
|
|
|
|
|
82
|
|
|
$this->locate($template)->shouldReturn('/app/template/path'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
function it_falls_back_to_decorated_template_locator_if_there_are_no_themes_active( |
|
86
|
|
|
FileLocatorInterface $decoratedFileLocator, |
|
87
|
|
|
ThemeContextInterface $themeContext, |
|
88
|
|
|
TemplateReferenceInterface $template |
|
89
|
|
|
) { |
|
90
|
|
|
$themeContext->getThemeHierarchy()->willReturn([]); |
|
91
|
|
|
|
|
92
|
|
|
$decoratedFileLocator->locate($template, Argument::cetera())->willReturn('/app/template/path'); |
|
93
|
|
|
|
|
94
|
|
|
$this->locate($template)->shouldReturn('/app/template/path'); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|