Skip to content

Commit 65b5122

Browse files
MAGETWO-31369: [South] Unit and Integration tests coverage
1 parent 3dd6f78 commit 65b5122

File tree

1 file changed

+91
-172
lines changed

1 file changed

+91
-172
lines changed

dev/tests/unit/testsuite/Magento/Theme/Model/Config/CustomizationTest.php

Lines changed: 91 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -9,261 +9,180 @@
99
*/
1010
namespace Magento\Theme\Model\Config;
1111

12+
use Magento\Framework\App\Area;
13+
1214
class CustomizationTest extends \PHPUnit_Framework_TestCase
1315
{
1416
/**
15-
* @var \Magento\Store\Model\StoreManagerInterface
17+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
1618
*/
17-
protected $_storeManager;
19+
protected $storeManager;
1820

1921
/**
20-
* @var \Magento\Framework\View\DesignInterface
22+
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
2123
*/
22-
protected $_designPackage;
24+
protected $designPackage;
2325

2426
/**
25-
* @var \Magento\Core\Model\Resource\Theme\Collection
27+
* @var \Magento\Core\Model\Resource\Theme\Collection|\PHPUnit_Framework_MockObject_MockObject
2628
*/
27-
protected $_themeCollection;
29+
protected $themeCollection;
2830

2931
/**
3032
* @var \Magento\Theme\Model\Config\Customization
3133
*/
32-
protected $_model;
34+
protected $model;
3335

3436
/**
35-
* @var \Magento\Core\Model\Theme\ThemeProvider|\PHPUnit_Framework_MockObject_MockBuilder
37+
* @var \Magento\Core\Model\Theme\ThemeProvider|\PHPUnit_Framework_MockObject_MockObject
3638
*/
3739
protected $themeProviderMock;
3840

3941
protected function setUp()
4042
{
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,
8864
$this->themeProviderMock
8965
);
9066
}
9167

92-
protected function tearDown()
93-
{
94-
$this->_storeManager = null;
95-
$this->_designPackage = null;
96-
$this->_themeCollection = null;
97-
$this->_model = null;
98-
}
99-
10068
/**
101-
* @covers \Magento\Theme\Model\Config\Customization::getAssignedThemeCustomizations
69+
* covers \Magento\Theme\Model\Config\Customization::getAssignedThemeCustomizations
70+
* covers \Magento\Theme\Model\Config\Customization::hasThemeAssigned
10271
*/
10372
public function testGetAssignedThemeCustomizations()
10473
{
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());
13390
}
13491

13592
/**
136-
* @covers \Magento\Theme\Model\Config\Customization::getUnassignedThemeCustomizations
93+
* covers \Magento\Theme\Model\Config\Customization::getUnassignedThemeCustomizations
13794
*/
13895
public function testGetUnassignedThemeCustomizations()
13996
{
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()]);
147100

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());
155104

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()]);
165109

166-
$unassignedThemes = $this->_model->getUnassignedThemeCustomizations();
167-
$this->assertArrayHasKey($this->_getUnassignedTheme()->getId(), $unassignedThemes);
110+
$unassignedThemes = $this->model->getUnassignedThemeCustomizations();
111+
$this->assertArrayHasKey($this->getUnassignedTheme()->getId(), $unassignedThemes);
168112
}
169113

170114
/**
171-
* @covers \Magento\Theme\Model\Config\Customization::getStoresByThemes
115+
* covers \Magento\Theme\Model\Config\Customization::getStoresByThemes
172116
*/
173117
public function testGetStoresByThemes()
174118
{
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()]);
182122

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());
190126

191-
$stores = $this->_model->getStoresByThemes();
192-
$this->assertArrayHasKey($this->_getAssignedTheme()->getId(), $stores);
127+
$stores = $this->model->getStoresByThemes();
128+
$this->assertArrayHasKey($this->getAssignedTheme()->getId(), $stores);
193129
}
194130

195131
/**
196-
* @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
132+
* covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
197133
*/
198134
public function testIsThemeAssignedToDefaultStore()
199135
{
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()]);
207139

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());
215143

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()]);
225148

226-
$themeAssigned = $this->_model->isThemeAssignedToStore($this->_getAssignedTheme());
149+
$themeAssigned = $this->model->isThemeAssignedToStore($this->getAssignedTheme());
227150
$this->assertEquals(true, $themeAssigned);
228151
}
229152

230153
/**
231-
* @covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
154+
* covers \Magento\Theme\Model\Config\Customization::isThemeAssignedToStore
232155
*/
233156
public function testIsThemeAssignedToConcreteStore()
234157
{
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());
242161

243-
$themeUnassigned = $this->_model->isThemeAssignedToStore($this->_getUnassignedTheme(), $this->_getStore());
162+
$themeUnassigned = $this->model->isThemeAssignedToStore($this->getUnassignedTheme(), $this->getStore());
244163
$this->assertEquals(false, $themeUnassigned);
245164
}
246165

247166
/**
248167
* @return \Magento\Framework\Object
249168
*/
250-
protected function _getAssignedTheme()
169+
protected function getAssignedTheme()
251170
{
252171
return new \Magento\Framework\Object(['id' => 1, 'theme_path' => 'Magento/luma']);
253172
}
254173

255174
/**
256175
* @return \Magento\Framework\Object
257176
*/
258-
protected function _getUnassignedTheme()
177+
protected function getUnassignedTheme()
259178
{
260179
return new \Magento\Framework\Object(['id' => 2, 'theme_path' => 'Magento/blank']);
261180
}
262181

263182
/**
264183
* @return \Magento\Framework\Object
265184
*/
266-
protected function _getStore()
185+
protected function getStore()
267186
{
268187
return new \Magento\Framework\Object(['id' => 55]);
269188
}

0 commit comments

Comments
 (0)