|
9 | 9 | */
|
10 | 10 | namespace Magento\Theme\Model\Config;
|
11 | 11 |
|
| 12 | +use Magento\Framework\App\Area; |
| 13 | + |
12 | 14 | class CustomizationTest extends \PHPUnit_Framework_TestCase
|
13 | 15 | {
|
14 | 16 | /**
|
15 |
| - * @var \Magento\Store\Model\StoreManagerInterface |
| 17 | + * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
16 | 18 | */
|
17 |
| - protected $_storeManager; |
| 19 | + protected $storeManager; |
18 | 20 |
|
19 | 21 | /**
|
20 |
| - * @var \Magento\Framework\View\DesignInterface |
| 22 | + * @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject |
21 | 23 | */
|
22 |
| - protected $_designPackage; |
| 24 | + protected $designPackage; |
23 | 25 |
|
24 | 26 | /**
|
25 |
| - * @var \Magento\Core\Model\Resource\Theme\Collection |
| 27 | + * @var \Magento\Core\Model\Resource\Theme\Collection|\PHPUnit_Framework_MockObject_MockObject |
26 | 28 | */
|
27 |
| - protected $_themeCollection; |
| 29 | + protected $themeCollection; |
28 | 30 |
|
29 | 31 | /**
|
30 | 32 | * @var \Magento\Theme\Model\Config\Customization
|
31 | 33 | */
|
32 |
| - protected $_model; |
| 34 | + protected $model; |
33 | 35 |
|
34 | 36 | /**
|
35 |
| - * @var \Magento\Core\Model\Theme\ThemeProvider|\PHPUnit_Framework_MockObject_MockBuilder |
| 37 | + * @var \Magento\Core\Model\Theme\ThemeProvider|\PHPUnit_Framework_MockObject_MockObject |
36 | 38 | */
|
37 | 39 | protected $themeProviderMock;
|
38 | 40 |
|
39 | 41 | protected function setUp()
|
40 | 42 | {
|
41 |
| - $this->_storeManager = $this->getMockForAbstractClass( |
42 |
| - 'Magento\Store\Model\StoreManagerInterface', |
43 |
| - [], |
44 |
| - '', |
45 |
| - true, |
46 |
| - true, |
47 |
| - true, |
48 |
| - ['getStores'] |
49 |
| - ); |
50 |
| - $this->_designPackage = $this->getMockForAbstractClass( |
51 |
| - 'Magento\Framework\View\DesignInterface', |
52 |
| - [], |
53 |
| - '', |
54 |
| - true, |
55 |
| - true, |
56 |
| - true, |
57 |
| - ['getConfigurationDesignTheme'] |
58 |
| - ); |
59 |
| - $this->_themeCollection = $this->getMock( |
60 |
| - 'Magento\Core\Model\Resource\Theme\Collection', |
61 |
| - ['filterThemeCustomizations', 'load'], |
62 |
| - [], |
63 |
| - '', |
64 |
| - false |
65 |
| - ); |
66 |
| - |
67 |
| - $collectionFactory = $this->getMock( |
68 |
| - 'Magento\Core\Model\Resource\Theme\CollectionFactory', |
69 |
| - ['create'], |
70 |
| - [], |
71 |
| - '', |
72 |
| - false |
73 |
| - ); |
74 |
| - |
75 |
| - $collectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->_themeCollection)); |
76 |
| - |
77 |
| - $this->themeProviderMock = $this->getMock( |
78 |
| - '\Magento\Core\Model\Theme\ThemeProvider', |
79 |
| - ['getThemeCustomizations', 'getThemeByFullPath'], |
80 |
| - [$collectionFactory, $this->getMock('\Magento\Core\Model\ThemeFactory', [], [], '', false)], |
81 |
| - '', |
82 |
| - false |
83 |
| - ); |
84 |
| - |
85 |
| - $this->_model = new \Magento\Theme\Model\Config\Customization( |
86 |
| - $this->_storeManager, |
87 |
| - $this->_designPackage, |
| 43 | + $this->storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface')->getMock(); |
| 44 | + $this->designPackage = $this->getMockBuilder('Magento\Framework\View\DesignInterface')->getMock(); |
| 45 | + $this->themeCollection = $this->getMockBuilder('Magento\Core\Model\Resource\Theme\Collection') |
| 46 | + ->disableOriginalConstructor() |
| 47 | + ->getMock(); |
| 48 | + |
| 49 | + $collectionFactory = $this->getMockBuilder('Magento\Core\Model\Resource\Theme\CollectionFactory') |
| 50 | + ->disableOriginalConstructor() |
| 51 | + ->setMethods(['create']) |
| 52 | + ->getMock(); |
| 53 | + |
| 54 | + $collectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->themeCollection)); |
| 55 | + |
| 56 | + $this->themeProviderMock = $this->getMockBuilder('\Magento\Core\Model\Theme\ThemeProvider') |
| 57 | + ->disableOriginalConstructor() |
| 58 | + ->setMethods(['getThemeCustomizations', 'getThemeByFullPath']) |
| 59 | + ->getMock(); |
| 60 | + |
| 61 | + $this->model = new \Magento\Theme\Model\Config\Customization( |
| 62 | + $this->storeManager, |
| 63 | + $this->designPackage, |
88 | 64 | $this->themeProviderMock
|
89 | 65 | );
|
90 | 66 | }
|
91 | 67 |
|
92 |
| - protected function tearDown() |
93 |
| - { |
94 |
| - $this->_storeManager = null; |
95 |
| - $this->_designPackage = null; |
96 |
| - $this->_themeCollection = null; |
97 |
| - $this->_model = null; |
98 |
| - } |
99 |
| - |
100 | 68 | /**
|
101 |
| - * @covers \Magento\Theme\Model\Config\Customization::getAssignedThemeCustomizations |
| 69 | + * covers \Magento\Theme\Model\Config\Customization::getAssignedThemeCustomizations |
| 70 | + * covers \Magento\Theme\Model\Config\Customization::hasThemeAssigned |
102 | 71 | */
|
103 | 72 | public function testGetAssignedThemeCustomizations()
|
104 | 73 | {
|
105 |
| - $this->_designPackage->expects( |
106 |
| - $this->once() |
107 |
| - )->method( |
108 |
| - 'getConfigurationDesignTheme' |
109 |
| - )->will( |
110 |
| - $this->returnValue($this->_getAssignedTheme()->getId()) |
111 |
| - ); |
112 |
| - |
113 |
| - $this->_storeManager->expects( |
114 |
| - $this->once() |
115 |
| - )->method( |
116 |
| - 'getStores' |
117 |
| - )->will( |
118 |
| - $this->returnValue([$this->_getStore()]) |
119 |
| - ); |
120 |
| - |
121 |
| - $this->themeProviderMock->expects( |
122 |
| - $this->once() |
123 |
| - )->method( |
124 |
| - 'getThemeCustomizations' |
125 |
| - )->with( |
126 |
| - \Magento\Framework\App\Area::AREA_FRONTEND |
127 |
| - )->will( |
128 |
| - $this->returnValue([$this->_getAssignedTheme(), $this->_getUnassignedTheme()]) |
129 |
| - ); |
130 |
| - |
131 |
| - $assignedThemes = $this->_model->getAssignedThemeCustomizations(); |
132 |
| - $this->assertArrayHasKey($this->_getAssignedTheme()->getId(), $assignedThemes); |
| 74 | + $this->designPackage->expects($this->once()) |
| 75 | + ->method('getConfigurationDesignTheme') |
| 76 | + ->willReturn($this->getAssignedTheme()->getId()); |
| 77 | + |
| 78 | + $this->storeManager->expects($this->once()) |
| 79 | + ->method('getStores') |
| 80 | + ->willReturn([$this->getStore()]); |
| 81 | + |
| 82 | + $this->themeProviderMock->expects($this->once()) |
| 83 | + ->method('getThemeCustomizations') |
| 84 | + ->with(Area::AREA_FRONTEND) |
| 85 | + ->willReturn([$this->getAssignedTheme(), $this->getUnassignedTheme()]); |
| 86 | + |
| 87 | + $assignedThemes = $this->model->getAssignedThemeCustomizations(); |
| 88 | + $this->assertArrayHasKey($this->getAssignedTheme()->getId(), $assignedThemes); |
| 89 | + $this->assertTrue($this->model->hasThemeAssigned()); |
133 | 90 | }
|
134 | 91 |
|
135 | 92 | /**
|
136 |
| - * @covers \Magento\Theme\Model\Config\Customization::getUnassignedThemeCustomizations |
| 93 | + * covers \Magento\Theme\Model\Config\Customization::getUnassignedThemeCustomizations |
137 | 94 | */
|
138 | 95 | public function testGetUnassignedThemeCustomizations()
|
139 | 96 | {
|
140 |
| - $this->_storeManager->expects( |
141 |
| - $this->once() |
142 |
| - )->method( |
143 |
| - 'getStores' |
144 |
| - )->will( |
145 |
| - $this->returnValue([$this->_getStore()]) |
146 |
| - ); |
| 97 | + $this->storeManager->expects($this->once()) |
| 98 | + ->method('getStores') |
| 99 | + ->willReturn([$this->getStore()]); |
147 | 100 |
|
148 |
| - $this->_designPackage->expects( |
149 |
| - $this->once() |
150 |
| - )->method( |
151 |
| - 'getConfigurationDesignTheme' |
152 |
| - )->will( |
153 |
| - $this->returnValue($this->_getAssignedTheme()->getId()) |
154 |
| - ); |
| 101 | + $this->designPackage->expects($this->once()) |
| 102 | + ->method('getConfigurationDesignTheme') |
| 103 | + ->willReturn($this->getAssignedTheme()->getId()); |
155 | 104 |
|
156 |
| - $this->themeProviderMock->expects( |
157 |
| - $this->once() |
158 |
| - )->method( |
159 |
| - 'getThemeCustomizations' |
160 |
| - )->with( |
161 |
| - \Magento\Framework\App\Area::AREA_FRONTEND |
162 |
| - )->will( |
163 |
| - $this->returnValue([$this->_getAssignedTheme(), $this->_getUnassignedTheme()]) |
164 |
| - ); |
| 105 | + $this->themeProviderMock->expects($this->once()) |
| 106 | + ->method('getThemeCustomizations') |
| 107 | + ->with(Area::AREA_FRONTEND) |
| 108 | + ->willReturn([$this->getAssignedTheme(), $this->getUnassignedTheme()]); |
165 | 109 |
|
166 |
| - $unassignedThemes = $this->_model->getUnassignedThemeCustomizations(); |
167 |
| - $this->assertArrayHasKey($this->_getUnassignedTheme()->getId(), $unassignedThemes); |
| 110 | + $unassignedThemes = $this->model->getUnassignedThemeCustomizations(); |
| 111 | + $this->assertArrayHasKey($this->getUnassignedTheme()->getId(), $unassignedThemes); |
168 | 112 | }
|
169 | 113 |
|
170 | 114 | /**
|
171 |
| - * @covers \Magento\Theme\Model\Config\Customization::getStoresByThemes |
| 115 | + * covers \Magento\Theme\Model\Config\Customization::getStoresByThemes |
172 | 116 | */
|
173 | 117 | public function testGetStoresByThemes()
|
174 | 118 | {
|
175 |
| - $this->_storeManager->expects( |
176 |
| - $this->once() |
177 |
| - )->method( |
178 |
| - 'getStores' |
179 |
| - )->will( |
180 |
| - $this->returnValue([$this->_getStore()]) |
181 |
| - ); |
| 119 | + $this->storeManager->expects($this->once()) |
| 120 | + ->method('getStores') |
| 121 | + ->willReturn([$this->getStore()]); |
182 | 122 |
|
183 |
| - $this->_designPackage->expects( |
184 |
| - $this->once() |
185 |
| - )->method( |
186 |
| - 'getConfigurationDesignTheme' |
187 |
| - )->will( |
188 |
| - $this->returnValue($this->_getAssignedTheme()->getId()) |
189 |
| - ); |
| 123 | + $this->designPackage->expects($this->once()) |
| 124 | + ->method('getConfigurationDesignTheme') |
| 125 | + ->willReturn($this->getAssignedTheme()->getId()); |
190 | 126 |
|
191 |
| - $stores = $this->_model->getStoresByThemes(); |
192 |
| - $this->assertArrayHasKey($this->_getAssignedTheme()->getId(), $stores); |
| 127 | + $stores = $this->model->getStoresByThemes(); |
| 128 | + $this->assertArrayHasKey($this->getAssignedTheme()->getId(), $stores); |
193 | 129 | }
|
194 | 130 |
|
195 | 131 | /**
|
196 |
| - * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore |
| 132 | + * covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore |
197 | 133 | */
|
198 | 134 | public function testIsThemeAssignedToDefaultStore()
|
199 | 135 | {
|
200 |
| - $this->_storeManager->expects( |
201 |
| - $this->once() |
202 |
| - )->method( |
203 |
| - 'getStores' |
204 |
| - )->will( |
205 |
| - $this->returnValue([$this->_getStore()]) |
206 |
| - ); |
| 136 | + $this->storeManager->expects($this->once()) |
| 137 | + ->method('getStores') |
| 138 | + ->willReturn([$this->getStore()]); |
207 | 139 |
|
208 |
| - $this->_designPackage->expects( |
209 |
| - $this->once() |
210 |
| - )->method( |
211 |
| - 'getConfigurationDesignTheme' |
212 |
| - )->will( |
213 |
| - $this->returnValue($this->_getAssignedTheme()->getId()) |
214 |
| - ); |
| 140 | + $this->designPackage->expects($this->once()) |
| 141 | + ->method('getConfigurationDesignTheme') |
| 142 | + ->willReturn($this->getAssignedTheme()->getId()); |
215 | 143 |
|
216 |
| - $this->themeProviderMock->expects( |
217 |
| - $this->once() |
218 |
| - )->method( |
219 |
| - 'getThemeCustomizations' |
220 |
| - )->with( |
221 |
| - \Magento\Framework\App\Area::AREA_FRONTEND |
222 |
| - )->will( |
223 |
| - $this->returnValue([$this->_getAssignedTheme(), $this->_getUnassignedTheme()]) |
224 |
| - ); |
| 144 | + $this->themeProviderMock->expects($this->once()) |
| 145 | + ->method('getThemeCustomizations') |
| 146 | + ->with(Area::AREA_FRONTEND) |
| 147 | + ->willReturn([$this->getAssignedTheme(), $this->getUnassignedTheme()]); |
225 | 148 |
|
226 |
| - $themeAssigned = $this->_model->isThemeAssignedToStore($this->_getAssignedTheme()); |
| 149 | + $themeAssigned = $this->model->isThemeAssignedToStore($this->getAssignedTheme()); |
227 | 150 | $this->assertEquals(true, $themeAssigned);
|
228 | 151 | }
|
229 | 152 |
|
230 | 153 | /**
|
231 |
| - * @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore |
| 154 | + * covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore |
232 | 155 | */
|
233 | 156 | public function testIsThemeAssignedToConcreteStore()
|
234 | 157 | {
|
235 |
| - $this->_designPackage->expects( |
236 |
| - $this->once() |
237 |
| - )->method( |
238 |
| - 'getConfigurationDesignTheme' |
239 |
| - )->will( |
240 |
| - $this->returnValue($this->_getAssignedTheme()->getId()) |
241 |
| - ); |
| 158 | + $this->designPackage->expects($this->once()) |
| 159 | + ->method('getConfigurationDesignTheme') |
| 160 | + ->willReturn($this->getAssignedTheme()->getId()); |
242 | 161 |
|
243 |
| - $themeUnassigned = $this->_model->isThemeAssignedToStore($this->_getUnassignedTheme(), $this->_getStore()); |
| 162 | + $themeUnassigned = $this->model->isThemeAssignedToStore($this->getUnassignedTheme(), $this->getStore()); |
244 | 163 | $this->assertEquals(false, $themeUnassigned);
|
245 | 164 | }
|
246 | 165 |
|
247 | 166 | /**
|
248 | 167 | * @return \Magento\Framework\Object
|
249 | 168 | */
|
250 |
| - protected function _getAssignedTheme() |
| 169 | + protected function getAssignedTheme() |
251 | 170 | {
|
252 | 171 | return new \Magento\Framework\Object(['id' => 1, 'theme_path' => 'Magento/luma']);
|
253 | 172 | }
|
254 | 173 |
|
255 | 174 | /**
|
256 | 175 | * @return \Magento\Framework\Object
|
257 | 176 | */
|
258 |
| - protected function _getUnassignedTheme() |
| 177 | + protected function getUnassignedTheme() |
259 | 178 | {
|
260 | 179 | return new \Magento\Framework\Object(['id' => 2, 'theme_path' => 'Magento/blank']);
|
261 | 180 | }
|
262 | 181 |
|
263 | 182 | /**
|
264 | 183 | * @return \Magento\Framework\Object
|
265 | 184 | */
|
266 |
| - protected function _getStore() |
| 185 | + protected function getStore() |
267 | 186 | {
|
268 | 187 | return new \Magento\Framework\Object(['id' => 55]);
|
269 | 188 | }
|
|
0 commit comments