/
ThemeTemplateLocatorTest.php
184 lines (148 loc) · 6.89 KB
/
ThemeTemplateLocatorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* Copyright 2006 - 2015 TubePress LLC (http://tubepress.com)
*
* This file is part of TubePress (http://tubepress.com)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* @covers tubepress_app_template_impl_ThemeTemplateLocator<extended>
*/
class tubepress_test_app_impl_template_ThemeTemplateLocatorTest extends tubepress_test_TubePressUnitTest
{
/**
* @var tubepress_app_template_impl_ThemeTemplateLocator
*/
private $_sut;
/**
* @var ehough_mockery_mockery_MockInterface
*/
private $_mockLogger;
/**
* @var ehough_mockery_mockery_MockInterface
*/
private $_mockContext;
/**
* @var ehough_mockery_mockery_MockInterface
*/
private $_mockThemeRegistry;
/**
* @var ehough_mockery_mockery_MockInterface
*/
private $_mockCurrentThemeService;
/**
* @var ehough_mockery_mockery_MockInterface
*/
private $_mockChildTheme;
/**
* @var ehough_mockery_mockery_MockInterface
*/
private $_mockParentTheme;
public function onSetup()
{
$this->_mockLogger = $this->mock(tubepress_platform_api_log_LoggerInterface::_);
$this->_mockContext = $this->mock(tubepress_app_api_options_ContextInterface::_);
$this->_mockThemeRegistry = $this->mock(tubepress_platform_api_contrib_RegistryInterface::_);
$this->_mockCurrentThemeService = $this->mock('tubepress_app_impl_theme_CurrentThemeService');
$this->_mockChildTheme = $this->mock(tubepress_app_api_theme_ThemeInterface::_);
$this->_mockParentTheme = $this->mock(tubepress_app_api_theme_ThemeInterface::_);
$this->_mockLogger->shouldReceive('isEnabled')->once()->andReturn(true);
$this->_mockLogger->shouldReceive('debug')->atLeast(1);
$this->_sut = new tubepress_app_template_impl_ThemeTemplateLocator(
$this->_mockLogger,
$this->_mockContext,
$this->_mockThemeRegistry,
$this->_mockCurrentThemeService
);
}
/**
* @dataProvider trueAndFalse
*/
public function testCacheKey($fresh)
{
$this->_mockCurrentThemeService->shouldReceive('getCurrentTheme')->once()->andReturn($this->_mockChildTheme);
$this->_mockChildTheme->shouldReceive('hasTemplateSource')->once()->with('template-name')->andReturn($fresh);
$this->_mockChildTheme->shouldReceive('getName')->atLeast(1)->andReturn('abc');
$this->_mockChildTheme->shouldReceive('getVersion')->atLeast(1)->andReturn(tubepress_platform_api_version_Version::parse('1.2.3'));
if ($fresh) {
$this->_mockChildTheme->shouldReceive('getTemplateCacheKey')->once()->andReturn($fresh);
$expected = $fresh;
} else {
$this->_mockChildTheme->shouldReceive('getParentThemeName')->once()->andReturnNull();
$this->setExpectedException('InvalidArgumentException');
}
$actual = $this->_sut->getCacheKey('template-name');
$this->assertEquals($expected, $actual);
}
/**
* @dataProvider trueAndFalse
*/
public function testIsFresh($fresh)
{
$this->_mockCurrentThemeService->shouldReceive('getCurrentTheme')->once()->andReturn($this->_mockChildTheme);
$this->_mockChildTheme->shouldReceive('hasTemplateSource')->once()->with('template-name')->andReturn($fresh);
$this->_mockChildTheme->shouldReceive('getName')->atLeast(1)->andReturn('abc');
$this->_mockChildTheme->shouldReceive('getVersion')->atLeast(1)->andReturn(tubepress_platform_api_version_Version::parse('1.2.3'));
if ($fresh) {
$this->_mockChildTheme->shouldReceive('isTemplateSourceFresh')->once()->andReturn($fresh);
$expected = $fresh;
} else {
$this->_mockChildTheme->shouldReceive('getParentThemeName')->once()->andReturnNull();
$this->setExpectedException('InvalidArgumentException');
}
$actual = $this->_sut->isFresh('template-name', PHP_INT_MAX);
$this->assertEquals($expected, $actual);
}
/**
* @dataProvider trueAndFalse
*/
public function testGetTemplateSource($exists)
{
$this->_mockCurrentThemeService->shouldReceive('getCurrentTheme')->once()->andReturn($this->_mockChildTheme);
$this->_mockChildTheme->shouldReceive('hasTemplateSource')->once()->with('template-name')->andReturn($exists);
$this->_mockChildTheme->shouldReceive('getName')->atLeast(1)->andReturn('abc');
$this->_mockChildTheme->shouldReceive('getVersion')->atLeast(1)->andReturn(tubepress_platform_api_version_Version::parse('1.2.3'));
if ($exists) {
$this->_mockChildTheme->shouldReceive('getTemplateSource')->once()->andReturn('foobar');
$expected = 'foobar';
} else {
$this->_mockChildTheme->shouldReceive('getParentThemeName')->once()->andReturnNull();
$expected = null;
}
$actual = $this->_sut->getSource('template-name');
$this->assertEquals($expected, $actual);
}
/**
* @dataProvider trueAndFalse
*/
public function testExistInParent($exists)
{
$this->_mockCurrentThemeService->shouldReceive('getCurrentTheme')->twice()->andReturn($this->_mockChildTheme);
$this->_mockChildTheme->shouldReceive('hasTemplateSource')->twice()->with('template-name')->andReturn(false);
$this->_mockChildTheme->shouldReceive('getParentThemeName')->twice()->andReturn('xyz');
$this->_mockChildTheme->shouldReceive('getName')->atLeast(1)->andReturn('abc');
$this->_mockChildTheme->shouldReceive('getVersion')->twice()->andReturn('1.2.3');
$this->_mockThemeRegistry->shouldReceive('getInstanceByName')->with('xyz')->andReturn($this->_mockParentTheme);
$this->_mockParentTheme->shouldReceive('hasTemplateSource')->twice()->with('template-name')->andReturn($exists);
$this->_mockChildTheme->shouldReceive('getVersion')->atLeast(1)->andReturn(tubepress_platform_api_version_Version::parse('1.2.3'));
if (!$exists) {
$this->_mockParentTheme->shouldReceive('getParentThemeName')->twice()->andReturnNull();
$this->_mockParentTheme->shouldReceive('getName')->twice()->andReturn('parent-theme-name');
} else {
$this->_mockParentTheme->shouldReceive('getName')->atLeast(1)->andReturn('xyz');
$this->_mockParentTheme->shouldReceive('getVersion')->atLeast(1)->andReturn('3.2.1');
}
$this->assertTrue($this->_sut->exists('template-name') === $exists);
$this->assertTrue($this->_sut->exists('template-name') === $exists);
}
public function trueAndFalse()
{
return array(
array(true),
array(false)
);
}
}