Skip to content

Commit 17d9535

Browse files
committed
Merge branch 'PV-fix-unit-media-hlper' into 'master3'
Create unit tests See merge request !164
2 parents adc344a + e4da9a6 commit 17d9535

File tree

1 file changed

+63
-107
lines changed

1 file changed

+63
-107
lines changed

app/code/Magento/ProductVideo/Test/Unit/Helper/MediaTest.php

Lines changed: 63 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -5,143 +5,99 @@
55
*/
66
namespace Magento\ProductVideo\Test\Unit\Helper;
77

8-
/**
9-
* Helper to move images from tmp to catalog directory
10-
*/
8+
use Magento\ProductVideo\Helper\Media;
9+
1110
class MediaTest extends \PHPUnit_Framework_TestCase
1211
{
13-
/**
14-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Config
15-
*/
16-
protected $viewConfigMock;
12+
/** @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject */
13+
protected $scopeConfigMock;
1714

1815
/**
19-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\DesignInterface
16+
* @var \Magento\ProductVideo\Helper\Media|\PHPUnit_Framework_MockObject_MockObject
2017
*/
21-
protected $currentThemeMock;
18+
protected $helper;
2219

2320
/**
24-
* @var \Magento\ProductVideo\Helper\Media|\Magento\Framework\TestFramework\Unit\Helper\ObjectManager
21+
* @var \Magento\Framework\App\Helper\Context|\PHPUnit_Framework_MockObject_MockObject
2522
*/
26-
protected $mediaHelperObject;
23+
protected $contextMock;
2724

2825
/**
29-
* @var array
26+
* Create mock objects
3027
*/
31-
protected $videoConfig;
32-
33-
public function setUp()
28+
protected function setUp()
3429
{
35-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36-
37-
$this->viewConfigMock = $this->getMock(
38-
'\Magento\Framework\View\Config',
39-
['getMediaAttributes', 'getViewConfig'],
40-
[],
41-
'',
42-
false
43-
);
44-
45-
$this->viewConfigMock
46-
->expects($this->atLeastOnce())
47-
->method('getViewConfig')
48-
->willReturn($this->viewConfigMock);
49-
50-
$this->themeCustomization = $this->getMock(
51-
'Magento\Framework\View\Design\Theme\Customization',
52-
[],
53-
[],
54-
'',
55-
false
56-
);
57-
$themeMock = $this->getMock(
58-
'Magento\Theme\Model\Theme',
59-
['__wakeup', 'getCustomization'],
60-
[],
61-
'',
62-
false
63-
);
64-
$themeMock->expects(
65-
$this->any()
66-
)->method(
67-
'getCustomization'
68-
)->will(
69-
$this->returnValue($this->themeCustomization)
70-
);
71-
72-
$this->currentThemeMock = $this->getMock('Magento\Framework\View\DesignInterface');
73-
$this->currentThemeMock->expects($this->any())->method('getDesignTheme')->will($this->returnValue($themeMock));
74-
75-
$this->mediaHelperObject = $objectManager->getObject(
76-
'\Magento\ProductVideo\Helper\Media',
77-
[
78-
'configInterface' => $this->viewConfigMock,
79-
'designInterface' => $this->currentThemeMock,
80-
]
30+
$this->scopeConfigMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
31+
->getMock();
32+
$this->contextMock = $this->getMock('Magento\Framework\App\Helper\Context', [], [], '', false);
33+
$this->contextMock->expects($this->any())->method('getScopeConfig')->willReturn($this->scopeConfigMock);
34+
$this->helper = new \Magento\ProductVideo\Helper\Media(
35+
$this->contextMock
8136
);
82-
83-
}
84-
85-
public function dataForVideoPlay()
86-
{
87-
return [
88-
[
89-
1,
90-
],
91-
[
92-
0,
93-
],
94-
];
95-
}
96-
97-
public function dataForVideoStop()
98-
{
99-
return [
100-
[
101-
1,
102-
],
103-
[
104-
0,
105-
],
106-
];
10737
}
10838

109-
public function dataForVideoBackground()
39+
/**
40+
* Test for method getPlayIfBaseAttribute
41+
*/
42+
public function testGetPlayIfBaseAttribute()
11043
{
111-
return [
112-
[
113-
'[255, 255, 255]',
114-
],
115-
[
116-
'[0, 0, 0]',
117-
],
118-
];
44+
$return = 'some_value';
45+
$this->scopeConfigMock->expects($this->once())->method('getValue')
46+
->with(Media::XML_PATH_PLAY_IF_BASE)
47+
->will($this->returnValue($return));
48+
49+
$this->assertEquals(
50+
$return,
51+
$this->helper->getPlayIfBaseAttribute()
52+
);
11953
}
12054

12155
/**
122-
* @dataProvider dataForVideoPlay
56+
* Test for method getShowRelatedAttribute
12357
*/
124-
public function testGetPlayIfBaseAttribute($expectedResult)
58+
public function testGetShowRelatedAttribute()
12559
{
126-
$this->viewConfigMock->expects($this->once())->method('getMediaAttributes')->willReturn($expectedResult);
127-
$this->mediaHelperObject->getPlayIfBaseAttribute();
60+
$return = 'some_value';
61+
$this->scopeConfigMock->expects($this->once())->method('getValue')
62+
->with(Media::XML_PATH_SHOW_RELATED)
63+
->will($this->returnValue($return));
64+
65+
$this->assertEquals(
66+
$return,
67+
$this->helper->getShowRelatedAttribute()
68+
);
12869
}
12970

13071
/**
131-
* @dataProvider dataForVideoStop
72+
* Test for method getVideoAutoRestartAttribute
13273
*/
133-
public function testGetShowRelatedAttribute($expectedResult)
74+
public function testGetVideoAutoRestartAttribute()
13475
{
135-
$this->viewConfigMock->expects($this->once())->method('getMediaAttributes')->willReturn($expectedResult);
136-
$this->mediaHelperObject->getShowRelatedAttribute();
76+
$return = 'some_value';
77+
$this->scopeConfigMock->expects($this->once())->method('getValue')
78+
->with(Media::XML_PATH_VIDEO_AUTO_RESTART)
79+
->will($this->returnValue($return));
80+
81+
$this->assertEquals(
82+
$return,
83+
$this->helper->getVideoAutoRestartAttribute()
84+
);
13785
}
13886

13987
/**
140-
* @dataProvider dataForVideoBackground
88+
* Test for method getYouTubeApiKey
14189
*/
142-
public function testGetVideoAutoRestartAttribute($expectedResult)
90+
public function testGetYouTubeApiKey()
14391
{
144-
$this->viewConfigMock->expects($this->once())->method('getMediaAttributes')->willReturn($expectedResult);
145-
$this->mediaHelperObject->getVideoAutoRestartAttribute();
92+
$return = 'some_value';
93+
$this->scopeConfigMock->expects($this->once())->method('getValue')
94+
->with(Media::XML_PATH_YOUTUBE_API_KEY)
95+
->will($this->returnValue($return));
96+
97+
$this->assertEquals(
98+
$return,
99+
$this->helper->getYouTubeApiKey()
100+
);
146101
}
102+
147103
}

0 commit comments

Comments
 (0)