Skip to content

Commit 80cb06e

Browse files
committed
Extract the problematic test to separate file (╯°□°)╯︵ ┻━┻
1 parent 986a4ef commit 80cb06e

File tree

2 files changed

+174
-91
lines changed

2 files changed

+174
-91
lines changed

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -381,97 +381,6 @@ public function testCreate($product)
381381
$this->deleteProduct($product[ProductInterface::SKU]);
382382
}
383383

384-
/**
385-
* Media gallery entries with external videos
386-
*
387-
* @return array
388-
*/
389-
public function externalVideoDataProvider(): array
390-
{
391-
return [
392-
'youtube-external-video' => [
393-
[
394-
'media_type' => 'external-video',
395-
'disabled' => false,
396-
'label' => 'Test Video Created',
397-
'types' => [],
398-
'position' => 1,
399-
'content' => $this->getVideoThumbnailStub(),
400-
'extension_attributes' => [
401-
'video_content' => [
402-
'media_type' => 'external-video',
403-
'video_provider' => 'youtube',
404-
'video_url' => 'https://www.youtube.com/',
405-
'video_title' => 'Video title',
406-
'video_description' => 'Video description',
407-
'video_metadata' => 'Video meta',
408-
],
409-
],
410-
]
411-
],
412-
'vimeo-external-video' => [
413-
[
414-
'media_type' => 'external-video',
415-
'disabled' => false,
416-
'label' => 'Test Video Updated',
417-
'types' => [],
418-
'position' => 1,
419-
'content' => $this->getVideoThumbnailStub(),
420-
'extension_attributes' => [
421-
'video_content' => [
422-
'media_type' => 'external-video',
423-
'video_provider' => 'vimeo',
424-
'video_url' => 'https://www.vimeo.com/',
425-
'video_title' => 'Video title',
426-
'video_description' => 'Video description',
427-
'video_metadata' => 'Video meta',
428-
],
429-
],
430-
]
431-
]
432-
];
433-
}
434-
435-
/**
436-
* Returns the array of data for Video thumbnail
437-
*
438-
* @return array|string[]
439-
*/
440-
private function getVideoThumbnailStub(): array
441-
{
442-
return [
443-
'type' => 'image/png',
444-
'name' => 'thumbnail.png',
445-
'base64_encoded_data' => 'iVBORw0KGgoAAAANSUhEUgAAAP8AAADGCAMAAAAqo6adAAAAA1BMVEUAAP79f'
446-
. '+LBAAAASElEQVR4nO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
447-
. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA+BsYAAAF7hZJ0AAAAAElFTkSuQmCC',
448-
];
449-
}
450-
451-
/**
452-
* Test create/ update product with external video media gallery entry
453-
*
454-
* @dataProvider externalVideoDataProvider
455-
* @param array $mediaGalleryData
456-
*/
457-
public function testCreateWithExternalVideo(array $mediaGalleryData)
458-
{
459-
$simpleProductBaseData = $this->getSimpleProductData(
460-
[
461-
ProductInterface::NAME => 'Product With Ext. Video',
462-
ProductInterface::SKU => 'prod-with-ext-video'
463-
]
464-
);
465-
466-
$simpleProductBaseData['media_gallery_entries'] = [$mediaGalleryData];
467-
468-
$response = $this->saveProduct($simpleProductBaseData);
469-
$this->assertEquals(
470-
$simpleProductBaseData['media_gallery_entries'][0]['extension_attributes'],
471-
$response["media_gallery_entries"][0]["extension_attributes"]
472-
);
473-
}
474-
475384
/**
476385
* @param array $fixtureProduct
477386
*
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Magento\ProductVideo;
5+
6+
use Magento\Catalog\Api\Data\ProductInterface;
7+
use Magento\TestFramework\TestCase\WebapiAbstract;
8+
9+
/**
10+
* Test for \Magento\ProductVideo feature
11+
*
12+
* @magentoAppIsolation enabled
13+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14+
*/
15+
class ProductVideoExternalSourceTest extends WebapiAbstract
16+
{
17+
const SERVICE_NAME = 'catalogProductRepositoryV1';
18+
const SERVICE_VERSION = 'V1';
19+
const RESOURCE_PATH = '/V1/products';
20+
21+
/**
22+
* Media gallery entries with external videos
23+
*
24+
* @return array
25+
*/
26+
public function externalVideoDataProvider(): array
27+
{
28+
return [
29+
'youtube-external-video' => [
30+
[
31+
'media_type' => 'external-video',
32+
'disabled' => false,
33+
'label' => 'Test Video Created',
34+
'types' => [],
35+
'position' => 1,
36+
'content' => $this->getVideoThumbnailStub(),
37+
'extension_attributes' => [
38+
'video_content' => [
39+
'media_type' => 'external-video',
40+
'video_provider' => 'youtube',
41+
'video_url' => 'https://www.youtube.com/',
42+
'video_title' => 'Video title',
43+
'video_description' => 'Video description',
44+
'video_metadata' => 'Video meta',
45+
],
46+
],
47+
]
48+
],
49+
'vimeo-external-video' => [
50+
[
51+
'media_type' => 'external-video',
52+
'disabled' => false,
53+
'label' => 'Test Video Updated',
54+
'types' => [],
55+
'position' => 1,
56+
'content' => $this->getVideoThumbnailStub(),
57+
'extension_attributes' => [
58+
'video_content' => [
59+
'media_type' => 'external-video',
60+
'video_provider' => 'vimeo',
61+
'video_url' => 'https://www.vimeo.com/',
62+
'video_title' => 'Video title',
63+
'video_description' => 'Video description',
64+
'video_metadata' => 'Video meta',
65+
],
66+
],
67+
]
68+
]
69+
];
70+
}
71+
72+
/**
73+
* Returns the array of data for Video thumbnail
74+
*
75+
* @return array|string[]
76+
*/
77+
private function getVideoThumbnailStub(): array
78+
{
79+
return [
80+
'type' => 'image/png',
81+
'name' => 'thumbnail.png',
82+
'base64_encoded_data' => 'iVBORw0KGgoAAAANSUhEUgAAAP8AAADGCAMAAAAqo6adAAAAA1BMVEUAAP79f'
83+
. '+LBAAAASElEQVR4nO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
84+
. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA+BsYAAAF7hZJ0AAAAAElFTkSuQmCC',
85+
];
86+
}
87+
88+
/**
89+
* Test create/ update product with external video media gallery entry
90+
*
91+
* @dataProvider externalVideoDataProvider
92+
* @param array $mediaGalleryData
93+
*/
94+
public function testCreateWithExternalVideo(array $mediaGalleryData)
95+
{
96+
$simpleProductBaseData = $this->getSimpleProductData(
97+
[
98+
ProductInterface::NAME => 'Product With Ext. Video',
99+
ProductInterface::SKU => 'prod-with-ext-video'
100+
]
101+
);
102+
103+
$simpleProductBaseData['media_gallery_entries'] = [$mediaGalleryData];
104+
105+
$response = $this->saveProduct($simpleProductBaseData);
106+
$this->assertEquals(
107+
$simpleProductBaseData['media_gallery_entries'][0]['extension_attributes'],
108+
$response["media_gallery_entries"][0]["extension_attributes"]
109+
);
110+
}
111+
112+
/**
113+
* Get Simple Product Data
114+
*
115+
* @param array $productData
116+
* @return array
117+
*/
118+
protected function getSimpleProductData($productData = [])
119+
{
120+
return [
121+
ProductInterface::SKU => isset($productData[ProductInterface::SKU])
122+
? $productData[ProductInterface::SKU] : uniqid('sku-', true),
123+
ProductInterface::NAME => isset($productData[ProductInterface::NAME])
124+
? $productData[ProductInterface::NAME] : uniqid('sku-', true),
125+
ProductInterface::VISIBILITY => 4,
126+
ProductInterface::TYPE_ID => 'simple',
127+
ProductInterface::PRICE => 3.62,
128+
ProductInterface::STATUS => 1,
129+
ProductInterface::ATTRIBUTE_SET_ID => 4,
130+
'custom_attributes' => [
131+
['attribute_code' => 'cost', 'value' => ''],
132+
['attribute_code' => 'description', 'value' => 'Description'],
133+
]
134+
];
135+
}
136+
137+
/**
138+
* Save Product
139+
*
140+
* @param $product
141+
* @param string|null $storeCode
142+
* @param string|null $token
143+
* @return mixed
144+
*/
145+
protected function saveProduct($product, $storeCode = null, ?string $token = null)
146+
{
147+
if (isset($product['custom_attributes'])) {
148+
foreach ($product['custom_attributes'] as &$attribute) {
149+
if ($attribute['attribute_code'] == 'category_ids'
150+
&& !is_array($attribute['value'])
151+
) {
152+
$attribute['value'] = [""];
153+
}
154+
}
155+
}
156+
$serviceInfo = [
157+
'rest' => [
158+
'resourcePath' => self::RESOURCE_PATH,
159+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
160+
],
161+
'soap' => [
162+
'service' => self::SERVICE_NAME,
163+
'serviceVersion' => self::SERVICE_VERSION,
164+
'operation' => self::SERVICE_NAME . 'Save',
165+
],
166+
];
167+
if ($token) {
168+
$serviceInfo['rest']['token'] = $serviceInfo['soap']['token'] = $token;
169+
}
170+
$requestData = ['product' => $product];
171+
172+
return $this->_webApiCall($serviceInfo, $requestData, null, $storeCode);
173+
}
174+
}

0 commit comments

Comments
 (0)