|
5 | 5 | */
|
6 | 6 | namespace Magento\ProductVideo\Test\Unit\Helper;
|
7 | 7 |
|
8 |
| -/** |
9 |
| - * Helper to move images from tmp to catalog directory |
10 |
| - */ |
| 8 | +use Magento\ProductVideo\Helper\Media; |
| 9 | + |
11 | 10 | class MediaTest extends \PHPUnit_Framework_TestCase
|
12 | 11 | {
|
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; |
17 | 14 |
|
18 | 15 | /**
|
19 |
| - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\DesignInterface |
| 16 | + * @var \Magento\ProductVideo\Helper\Media|\PHPUnit_Framework_MockObject_MockObject |
20 | 17 | */
|
21 |
| - protected $currentThemeMock; |
| 18 | + protected $helper; |
22 | 19 |
|
23 | 20 | /**
|
24 |
| - * @var \Magento\ProductVideo\Helper\Media|\Magento\Framework\TestFramework\Unit\Helper\ObjectManager |
| 21 | + * @var \Magento\Framework\App\Helper\Context|\PHPUnit_Framework_MockObject_MockObject |
25 | 22 | */
|
26 |
| - protected $mediaHelperObject; |
| 23 | + protected $contextMock; |
27 | 24 |
|
28 | 25 | /**
|
29 |
| - * @var array |
| 26 | + * Create mock objects |
30 | 27 | */
|
31 |
| - protected $videoConfig; |
32 |
| - |
33 |
| - public function setUp() |
| 28 | + protected function setUp() |
34 | 29 | {
|
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 |
81 | 36 | );
|
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 |
| - ]; |
107 | 37 | }
|
108 | 38 |
|
109 |
| - public function dataForVideoBackground() |
| 39 | + /** |
| 40 | + * Test for method getPlayIfBaseAttribute |
| 41 | + */ |
| 42 | + public function testGetPlayIfBaseAttribute() |
110 | 43 | {
|
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 | + ); |
119 | 53 | }
|
120 | 54 |
|
121 | 55 | /**
|
122 |
| - * @dataProvider dataForVideoPlay |
| 56 | + * Test for method getShowRelatedAttribute |
123 | 57 | */
|
124 |
| - public function testGetPlayIfBaseAttribute($expectedResult) |
| 58 | + public function testGetShowRelatedAttribute() |
125 | 59 | {
|
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 | + ); |
128 | 69 | }
|
129 | 70 |
|
130 | 71 | /**
|
131 |
| - * @dataProvider dataForVideoStop |
| 72 | + * Test for method getVideoAutoRestartAttribute |
132 | 73 | */
|
133 |
| - public function testGetShowRelatedAttribute($expectedResult) |
| 74 | + public function testGetVideoAutoRestartAttribute() |
134 | 75 | {
|
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 | + ); |
137 | 85 | }
|
138 | 86 |
|
139 | 87 | /**
|
140 |
| - * @dataProvider dataForVideoBackground |
| 88 | + * Test for method getYouTubeApiKey |
141 | 89 | */
|
142 |
| - public function testGetVideoAutoRestartAttribute($expectedResult) |
| 90 | + public function testGetYouTubeApiKey() |
143 | 91 | {
|
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 | + ); |
146 | 101 | }
|
| 102 | + |
147 | 103 | }
|
0 commit comments