Skip to content

Commit 7ce8a32

Browse files
MAGETWO-31369: [South] Unit and Integration tests coverage
1 parent 4c3d6ee commit 7ce8a32

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Theme\Model\Theme;
7+
8+
class SingleFileTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var SingleFile
12+
*/
13+
protected $object;
14+
15+
/**
16+
* @var \Magento\Framework\View\Design\Theme\Customization\FileInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $file;
19+
20+
/**
21+
* Initialize testable object
22+
*/
23+
public function setUp()
24+
{
25+
$this->file = $this->getMockBuilder('Magento\Framework\View\Design\Theme\Customization\FileInterface')
26+
->getMock();
27+
28+
$this->object = new SingleFile($this->file);
29+
}
30+
31+
/**
32+
* cover update method
33+
*/
34+
public function testUpdate()
35+
{
36+
$fileContent = 'file content';
37+
$customFiles = [];
38+
$fileType = 'png';
39+
$customCss = $this->getMockBuilder('Magento\Framework\View\Design\Theme\FileInterface')
40+
->disableOriginalConstructor()
41+
->setMethods(
42+
[
43+
'delete',
44+
'save',
45+
'getContent',
46+
'getFileInfo',
47+
'getFullPath',
48+
'getFileName',
49+
'setFileName',
50+
'getTheme',
51+
'setTheme',
52+
'getCustomizationService',
53+
'setCustomizationService',
54+
'setData',
55+
'getType',
56+
'prepareFile',
57+
]
58+
)
59+
->getMock();
60+
$theme = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface')
61+
->setMethods(
62+
[
63+
'getArea',
64+
'getThemePath',
65+
'getFullPath',
66+
'getParentTheme',
67+
'getCode',
68+
'isPhysical',
69+
'getInheritedThemes',
70+
'getId',
71+
'getCustomization',
72+
]
73+
)
74+
->getMock();
75+
$customization = $this->getMockBuilder('Magento\Framework\View\Design\Theme\CustomizationInterface')
76+
->getMock();
77+
78+
$customCss->expects($this->once())
79+
->method('setData')
80+
->with('content', $fileContent);
81+
$customCss->expects($this->once())
82+
->method('setTheme')
83+
->with($theme);
84+
$customCss->expects($this->once())
85+
->method('save');
86+
$this->file->expects($this->once())
87+
->method('create')
88+
->willReturn($customCss);
89+
$this->file->expects($this->once())
90+
->method('getType')
91+
->willReturn($fileType);
92+
$customization->expects($this->once())
93+
->method('getFilesByType')
94+
->with($fileType)
95+
->willReturn($customFiles);
96+
$theme->expects($this->once())
97+
->method('getCustomization')
98+
->willReturn($customization);
99+
100+
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
101+
$this->assertInstanceOf(
102+
'Magento\Framework\View\Design\Theme\FileInterface',
103+
$this->object->update($theme, $fileContent)
104+
);
105+
}
106+
107+
/**
108+
* cover update method when fileContent is empty
109+
*/
110+
public function testUpdateWhenFileDelete()
111+
{
112+
$customCss = $this->getMockBuilder('Magento\Framework\View\Design\Theme\FileInterface')
113+
->disableOriginalConstructor()
114+
->setMethods(
115+
[
116+
'delete',
117+
'save',
118+
'getContent',
119+
'getFileInfo',
120+
'getFullPath',
121+
'getFileName',
122+
'setFileName',
123+
'getTheme',
124+
'setTheme',
125+
'getCustomizationService',
126+
'setCustomizationService',
127+
'setData',
128+
'getType',
129+
'prepareFile',
130+
]
131+
)
132+
->getMock();
133+
$fileContent = '';
134+
$customFiles = [$customCss];
135+
$fileType = 'png';
136+
137+
$theme = $this->getMockBuilder('Magento\Framework\View\Design\ThemeInterface')
138+
->setMethods(
139+
[
140+
'getArea',
141+
'getThemePath',
142+
'getFullPath',
143+
'getParentTheme',
144+
'getCode',
145+
'isPhysical',
146+
'getInheritedThemes',
147+
'getId',
148+
'getCustomization',
149+
]
150+
)
151+
->getMock();
152+
$customization = $this->getMockBuilder('Magento\Framework\View\Design\Theme\CustomizationInterface')
153+
->getMock();
154+
155+
156+
$customCss->expects($this->once())
157+
->method('delete');
158+
$this->file->expects($this->once())
159+
->method('getType')
160+
->willReturn($fileType);
161+
$customization->expects($this->once())
162+
->method('getFilesByType')
163+
->with($fileType)
164+
->willReturn($customFiles);
165+
$theme->expects($this->once())
166+
->method('getCustomization')
167+
->willReturn($customization);
168+
169+
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
170+
$this->assertInstanceOf(
171+
'Magento\Framework\View\Design\Theme\FileInterface',
172+
$this->object->update($theme, $fileContent)
173+
);
174+
}
175+
}

0 commit comments

Comments
 (0)