Skip to content

Commit 1786cad

Browse files
author
Sergey Shvets
committed
MAGETWO-94029: Issues with Multi website YouTube Videos
fix tests
1 parent a80c6bb commit 1786cad

File tree

2 files changed

+159
-73
lines changed

2 files changed

+159
-73
lines changed

app/code/Magento/ProductVideo/Model/Plugin/Catalog/Product/Gallery/CreateHandler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public function afterExecute(
6060
if (!empty($mediaCollection)) {
6161
$newVideoCollection = $this->collectNewVideos($mediaCollection);
6262
$this->saveVideoData($newVideoCollection, 0);
63-
$this->saveAdditionalStoreData($newVideoCollection);
6463

6564
$videoDataCollection = $this->collectVideoData($mediaCollection);
6665
$this->saveVideoData($videoDataCollection, $product->getStoreId());
@@ -263,21 +262,21 @@ private function collectNewVideos(array $mediaCollection): array
263262
}
264263

265264
/**
266-
* @param $item
265+
* @param array $item
267266
* @return bool
268267
*/
269-
private function isVideoItem($item): bool
268+
private function isVideoItem(array $item): bool
270269
{
271270
return !empty($item['media_type'])
272271
&& empty($item['removed'])
273272
&& $item['media_type'] == ExternalVideoEntryConverter::MEDIA_TYPE_CODE;
274273
}
275274

276275
/**
277-
* @param $item
276+
* @param array $item
278277
* @return bool
279278
*/
280-
private function isNewVideo($item): bool
279+
private function isNewVideo(array $item): bool
281280
{
282281
return !isset($item['video_url_default'], $item['video_title_default'])
283282
|| empty($item['video_url_default'])

app/code/Magento/ProductVideo/Test/Unit/Model/Plugin/Catalog/Product/Gallery/CreateHandlerTest.php

Lines changed: 155 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\ProductVideo\Test\Unit\Model\Plugin\Catalog\Product\Gallery;
78

89
/**
@@ -37,6 +38,9 @@ class CreateHandlerTest extends \PHPUnit\Framework\TestCase
3738
*/
3839
protected $mediaGalleryCreateHandler;
3940

41+
/**
42+
* {@inheritDoc}
43+
*/
4044
protected function setUp()
4145
{
4246
$this->product = $this->createMock(\Magento\Catalog\Model\Product::class);
@@ -62,72 +66,18 @@ protected function setUp()
6266
);
6367
}
6468

65-
public function testAfterExecute()
69+
/**
70+
* @dataProvider provideImageForAfterExecute
71+
* @param array $image
72+
* @param array $expectedSave
73+
* @param int $rowSaved
74+
*/
75+
public function testAfterExecute($image, $expectedSave, $rowSaved): void
6676
{
67-
$mediaData = [
68-
'images' => [
69-
'72mljfhmasfilp9cuq' => [
70-
'position' => '3',
71-
'media_type' => 'external-video',
72-
'file' => '/i/n/index111111.jpg',
73-
'value_id' => '4',
74-
'label' => '',
75-
'disabled' => '0',
76-
'removed' => '',
77-
'video_provider' => 'youtube',
78-
'video_url' => 'https://www.youtube.com/watch?v=ab123456',
79-
'video_title' => 'Some second title',
80-
'video_description' => 'Description second',
81-
'video_metadata' => 'meta two',
82-
'role' => '',
83-
],
84-
'w596fi79hv1p6wj21u' => [
85-
'position' => '4',
86-
'media_type' => 'image',
87-
'video_provider' => '',
88-
'file' => '/h/d/hd_image.jpg',
89-
'value_id' => '7',
90-
'label' => '',
91-
'disabled' => '0',
92-
'removed' => '',
93-
'video_url' => '',
94-
'video_title' => '',
95-
'video_description' => '',
96-
'video_metadata' => '',
97-
'role' => '',
98-
],
99-
'tcodwd7e0dirifr64j' => [
100-
'position' => '4',
101-
'media_type' => 'external-video',
102-
'file' => '/s/a/sample_3.jpg',
103-
'value_id' => '5',
104-
'label' => '',
105-
'disabled' => '0',
106-
'removed' => '',
107-
'video_provider' => 'youtube',
108-
'video_url' => 'https://www.youtube.com/watch?v=ab123456',
109-
'video_title' => 'Some second title',
110-
'video_description' => 'Description second',
111-
'video_metadata' => 'meta two',
112-
'role' => '',
113-
'additional_store_data' => [
114-
0 => [
115-
'store_id' => '0',
116-
'video_provider' => null,
117-
'video_url' => 'https://www.youtube.com/watch?v=ab123456',
118-
'video_title' => 'New Title',
119-
'video_description' => 'New Description',
120-
'video_metadata' => 'New metadata',
121-
],
122-
]
123-
],
124-
],
125-
];
126-
12777
$this->product->expects($this->once())
12878
->method('getData')
12979
->with('media_gallery')
130-
->willReturn($mediaData);
80+
->willReturn(['images' => $image]);
13181
$this->product->expects($this->once())
13282
->method('getStoreId')
13383
->willReturn(0);
@@ -136,13 +86,150 @@ public function testAfterExecute()
13686
->method('getAttribute')
13787
->willReturn($this->attribute);
13888

139-
$this->subject->afterExecute(
140-
$this->mediaGalleryCreateHandler,
141-
$this->product
142-
);
89+
$this->resourceModel->expects($this->exactly($rowSaved))
90+
->method('saveDataRow')
91+
->with('catalog_product_entity_media_gallery_value_video', $expectedSave)
92+
->willReturn(1);
93+
94+
$this->subject->afterExecute($this->mediaGalleryCreateHandler, $this->product);
95+
}
96+
97+
/**
98+
* DataProvider for testAfterExecute
99+
*
100+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
101+
* @return array
102+
*/
103+
public function provideImageForAfterExecute(): array
104+
{
105+
return [
106+
'new_video' => [
107+
[
108+
'72mljfhmasfilp9cuq' => [
109+
'position' => '3',
110+
'media_type' => 'external-video',
111+
'file' => '/i/n/index111111.jpg',
112+
'value_id' => '4',
113+
'label' => '',
114+
'disabled' => '0',
115+
'removed' => '',
116+
'video_provider' => 'youtube',
117+
'video_url' => 'https://www.youtube.com/watch?v=ab123456',
118+
'video_title' => 'Some second title',
119+
'video_description' => 'Description second',
120+
'video_metadata' => 'meta two',
121+
'role' => '',
122+
],
123+
],
124+
[
125+
'value_id' => '4',
126+
'store_id' => 0,
127+
'provider' => 'youtube',
128+
'url' => 'https://www.youtube.com/watch?v=ab123456',
129+
'title' => 'Some second title',
130+
'description' => 'Description second',
131+
'metadata' => 'meta two',
132+
],
133+
2
134+
],
135+
'image' => [
136+
[
137+
'w596fi79hv1p6wj21u' => [
138+
'position' => '4',
139+
'media_type' => 'image',
140+
'video_provider' => '',
141+
'file' => '/h/d/hd_image.jpg',
142+
'value_id' => '7',
143+
'label' => '',
144+
'disabled' => '0',
145+
'removed' => '',
146+
'video_url' => '',
147+
'video_title' => '',
148+
'video_description' => '',
149+
'video_metadata' => '',
150+
'role' => '',
151+
],
152+
],
153+
[],
154+
0
155+
],
156+
'new_video_with_additional_data' => [
157+
[
158+
'tcodwd7e0dirifr64j' => [
159+
'position' => '4',
160+
'media_type' => 'external-video',
161+
'file' => '/s/a/sample_3.jpg',
162+
'value_id' => '5',
163+
'label' => '',
164+
'disabled' => '0',
165+
'removed' => '',
166+
'video_provider' => 'youtube',
167+
'video_url' => 'https://www.youtube.com/watch?v=ab123456',
168+
'video_title' => 'Some second title',
169+
'video_description' => 'Description second',
170+
'video_metadata' => 'meta two',
171+
'role' => '',
172+
'additional_store_data' => [
173+
0 => [
174+
'store_id' => 0,
175+
'video_provider' => 'youtube',
176+
'video_url' => 'https://www.youtube.com/watch?v=ab123456',
177+
'video_title' => 'Some second title',
178+
'video_description' => 'Description second',
179+
'video_metadata' => 'meta two',
180+
],
181+
]
182+
],
183+
],
184+
[
185+
'value_id' => '5',
186+
'store_id' => 0,
187+
'provider' => 'youtube',
188+
'url' => 'https://www.youtube.com/watch?v=ab123456',
189+
'title' => 'Some second title',
190+
'description' => 'Description second',
191+
'metadata' => 'meta two',
192+
],
193+
3
194+
],
195+
'not_new_video' => [
196+
[
197+
'72mljfhmasfilp9cuq' => [
198+
'position' => '3',
199+
'media_type' => 'external-video',
200+
'file' => '/i/n/index111111.jpg',
201+
'value_id' => '4',
202+
'label' => '',
203+
'disabled' => '0',
204+
'removed' => '',
205+
'video_provider' => 'youtube',
206+
'video_url' => 'https://www.youtube.com/watch?v=ab123456',
207+
'video_url_default' => 'https://www.youtube.com/watch?v=ab123456',
208+
'video_title' => 'Some second title',
209+
'video_title_default' => 'Some second title',
210+
'video_description' => 'Description second',
211+
'video_metadata' => 'meta two',
212+
'role' => '',
213+
],
214+
],
215+
[
216+
'value_id' => '4',
217+
'store_id' => 0,
218+
'provider' => 'youtube',
219+
'url' => 'https://www.youtube.com/watch?v=ab123456',
220+
'title' => 'Some second title',
221+
'description' => 'Description second',
222+
'metadata' => 'meta two',
223+
],
224+
1
225+
],
226+
];
143227
}
144228

145-
public function testAfterExecuteEmpty()
229+
/**
230+
* Tests empty media gallery
231+
*/
232+
public function testAfterExecuteEmpty(): void
146233
{
147234
$this->product->expects($this->once())
148235
->method('getData')
@@ -162,7 +249,7 @@ public function testAfterExecuteEmpty()
162249
/**
163250
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
164251
*/
165-
public function testBeforeExecute()
252+
public function testBeforeExecute(): void
166253
{
167254
$mediaData = [
168255
'images' => [

0 commit comments

Comments
 (0)