Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
ProductAttributeMediaGalleryManagementInterfaceTest Class Reference
Inheritance diagram for ProductAttributeMediaGalleryManagementInterfaceTest:
WebapiAbstract

Public Member Functions

 testCreate ()
 
 testCreateWithoutFileExtension ()
 
 testCreateWithNotDefaultStoreId ()
 
 testUpdate ()
 
 testUpdateWithNotDefaultStoreId ()
 
 testDelete ()
 
 testCreateThrowsExceptionIfProvidedContentIsNotBase64Encoded ()
 
 testCreateThrowsExceptionIfProvidedContentIsNotAnImage ()
 
 testCreateThrowsExceptionIfProvidedImageHasWrongMimeType ()
 
 testCreateThrowsExceptionIfTargetProductDoesNotExist ()
 
 testCreateThrowsExceptionIfProvidedImageNameContainsForbiddenCharacters ()
 
 testUpdateThrowsExceptionIfTargetProductDoesNotExist ()
 
 testUpdateThrowsExceptionIfThereIsNoImageWithGivenId ()
 
 testDeleteThrowsExceptionIfTargetProductDoesNotExist ()
 
 testDeleteThrowsExceptionIfThereIsNoImageWithGivenId ()
 
 testGetList ()
 
 testGetListForAbsentSku ()
 
 testAddProductVideo ()
 
- Public Member Functions inherited from WebapiAbstract
 addModelToDelete ($model, $secure=false)
 
 processRestExceptionResult (\Exception $e)
 

Protected Member Functions

 setUp ()
 
 getTargetSimpleProduct ()
 
 getTargetGalleryEntryId ()
 
- Protected Member Functions inherited from WebapiAbstract
 tearDown ()
 
 _webApiCall ( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
 
 _markTestAsSoapOnly ($message=null)
 
 _markTestAsRestOnly ($message=null)
 
 _getWebApiAdapter ($webApiAdapterCode)
 
 _assertMessagesEqual ($expectedMessages, $receivedMessages)
 
 _cleanAppConfigCache ()
 
 _restoreAppConfig ()
 
 checkSoapFault ( $soapFault, $expectedMessage, $expectedFaultCode, $expectedErrorParams=[], $expectedWrappedErrors=[], $traceString=null)
 
 _checkFaultParams ($expectedErrorParams, $errorDetails)
 
 _checkWrappedErrors ($expectedWrappedErrors, $errorDetails)
 

Protected Attributes

 $createServiceInfo
 
 $updateServiceInfo
 
 $deleteServiceInfo
 
 $testImagePath
 
- Protected Attributes inherited from WebapiAbstract
 $_appCache
 
 $_modelsToDelete = []
 
 $_origConfigValues = []
 
 $_webApiAdapters
 
 $_webApiAdaptersMap
 

Additional Inherited Members

- Static Public Member Functions inherited from WebapiAbstract
static setUpBeforeClass ()
 
static tearDownAfterClass ()
 
static setFixture ($key, $fixture, $tearDown=self::AUTO_TEAR_DOWN_AFTER_METHOD)
 
static getFixture ($key)
 
static callModelDelete ($model, $secure=false)
 
static deleteFixture ($key, $secure=false)
 
- Data Fields inherited from WebapiAbstract
const AUTO_TEAR_DOWN_DISABLED = 0
 
const AUTO_TEAR_DOWN_AFTER_METHOD = 1
 
const AUTO_TEAR_DOWN_AFTER_CLASS = 2
 
const ADAPTER_SOAP = 'soap'
 
const ADAPTER_REST = 'rest'
 
- Static Protected Member Functions inherited from WebapiAbstract
static _setFixtureNamespace ()
 
static _unsetFixtureNamespace ()
 
static _getFixtureNamespace ()
 
static _deleteFixtures ($fixtures)
 
- Static Protected Attributes inherited from WebapiAbstract
static $_fixturesNamespace
 
static $_fixtures = []
 
static $_methodLevelFixtures = []
 
static $_classLevelFixtures = []
 

Detailed Description

Class ProductAttributeMediaGalleryManagementInterfaceTest

Definition at line 16 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

Member Function Documentation

◆ getTargetGalleryEntryId()

getTargetGalleryEntryId ( )
protected

Retrieve target product image ID

Target product must have single image if this function is used

Returns
int

Definition at line 100 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

101  {
102  $mediaGallery = $this->getTargetSimpleProduct()->getData('media_gallery');
103  $image = array_shift($mediaGallery['images']);
104  return (int)$image['value_id'];
105  }

◆ getTargetSimpleProduct()

getTargetSimpleProduct ( )
protected

Retrieve product that was updated by test

Returns
\Magento\Catalog\Model\Product

Definition at line 87 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

88  {
90  return $objectManager->get(\Magento\Catalog\Model\ProductFactory::class)->create()->load(1);
91  }
$objectManager
Definition: bootstrap.php:17

◆ setUp()

setUp ( )
protected

Definition at line 44 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

45  {
46  $this->createServiceInfo = [
47  'rest' => [
48  'resourcePath' => '/V1/products/simple/media',
50  ],
51  'soap' => [
52  'service' => 'catalogProductAttributeMediaGalleryManagementV1',
53  'serviceVersion' => 'V1',
54  'operation' => 'catalogProductAttributeMediaGalleryManagementV1Create',
55  ],
56  ];
57 
58  $this->updateServiceInfo = [
59  'rest' => [
60  'resourcePath' => '/V1/products/simple/media',
62  ],
63  'soap' => [
64  'service' => 'catalogProductAttributeMediaGalleryManagementV1',
65  'serviceVersion' => 'V1',
66  'operation' => 'catalogProductAttributeMediaGalleryManagementV1Update',
67  ],
68  ];
69  $this->deleteServiceInfo = [
70  'rest' => [
72  ],
73  'soap' => [
74  'service' => 'catalogProductAttributeMediaGalleryManagementV1',
75  'serviceVersion' => 'V1',
76  'operation' => 'catalogProductAttributeMediaGalleryManagementV1Remove',
77  ],
78  ];
79  $this->testImagePath = __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test_image.jpg';
80  }
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60

◆ testAddProductVideo()

testAddProductVideo ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php

Definition at line 627 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

628  {
629  $videoContent = [
630  'media_type' => 'external-video',
631  'video_provider' => 'vimeo',
632  'video_url' => 'https://vimeo.com/testUrl',
633  'video_title' => 'Vimeo Test Title',
634  'video_description' => 'test description',
635  'video_metadata' => 'video meta data'
636  ];
637 
638  $requestData = [
639  'id' => null,
640  'media_type' => 'external-video',
641  'label' => 'Image Text',
642  'position' => 1,
643  'types' => null,
644  'disabled' => false,
645  'content' => [
646  ImageContentInterface::BASE64_ENCODED_DATA => base64_encode(file_get_contents($this->testImagePath)),
647  ImageContentInterface::TYPE => 'image/jpeg',
648  ImageContentInterface::NAME => 'test_image.jpg'
649  ],
650  'extension_attributes' => [
651  'video_content' => $videoContent
652  ]
653  ];
654 
655  $actualResult = $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
656  $targetProduct = $this->getTargetSimpleProduct();
657  $mediaGallery = $targetProduct->getData('media_gallery');
658 
659  $this->assertCount(1, $mediaGallery['images']);
660  $updatedImage = array_shift($mediaGallery['images']);
661  $this->assertEquals($actualResult, $updatedImage['value_id']);
662  $this->assertEquals('Image Text', $updatedImage['label']);
663  $this->assertEquals(1, $updatedImage['position']);
664  $this->assertEquals(0, $updatedImage['disabled']);
665  $this->assertStringStartsWith('/t/e/test_image', $updatedImage['file']);
666  $this->assertEquals($videoContent, array_intersect($updatedImage, $videoContent));
667  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreate()

testCreate ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php

Definition at line 110 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

111  {
112  $requestData = [
113  'id' => null,
114  'media_type' => \Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter::MEDIA_TYPE_CODE,
115  'label' => 'Image Text',
116  'position' => 1,
117  'types' => ['image'],
118  'disabled' => false,
119  'content' => [
120  ImageContentInterface::BASE64_ENCODED_DATA => base64_encode(file_get_contents($this->testImagePath)),
121  ImageContentInterface::TYPE => 'image/jpeg',
122  ImageContentInterface::NAME => 'test_image.jpg'
123  ]
124  ];
125 
126  $actualResult = $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
127  $targetProduct = $this->getTargetSimpleProduct();
128  $mediaGallery = $targetProduct->getData('media_gallery');
129 
130  $this->assertCount(1, $mediaGallery['images']);
131  $updatedImage = array_shift($mediaGallery['images']);
132  $this->assertEquals($actualResult, $updatedImage['value_id']);
133  $this->assertEquals('Image Text', $updatedImage['label']);
134  $this->assertEquals(1, $updatedImage['position']);
135  $this->assertEquals(0, $updatedImage['disabled']);
136  $this->assertStringStartsWith('/t/e/test_image', $updatedImage['file']);
137  $this->assertEquals($updatedImage['file'], $targetProduct->getData('image'));
138  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateThrowsExceptionIfProvidedContentIsNotAnImage()

testCreateThrowsExceptionIfProvidedContentIsNotAnImage ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php @expectedException \Exception @expectedExceptionMessage The image content must be valid base64 encoded data.

Definition at line 341 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

342  {
343  $encodedContent = base64_encode('not_an_image');
344  $requestData = [
345  'id' => null,
346  'media_type' => 'image',
347  'label' => 'Image Text',
348  'position' => 1,
349  'types' => ['image'],
350  'disabled' => false,
351  'content' => [
352  'base64_encoded_data' => $encodedContent,
353  'type' => 'image/jpeg',
354  'name' => 'test_image.jpg',
355  ]
356  ];
357 
358  $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
359  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateThrowsExceptionIfProvidedContentIsNotBase64Encoded()

testCreateThrowsExceptionIfProvidedContentIsNotBase64Encoded ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php @expectedException \Exception @expectedExceptionMessage The image content must be valid base64 encoded data.

Definition at line 316 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

317  {
318  $encodedContent = 'not_a_base64_encoded_content';
319  $requestData = [
320  'id' => null,
321  'media_type' => 'image',
322  'label' => 'Image Text',
323  'position' => 1,
324  'types' => ['image'],
325  'disabled' => false,
326  'content' => [
327  'base64_encoded_data' => $encodedContent,
328  'type' => 'image/jpeg',
329  'name' => 'test_image.jpg',
330  ]
331  ];
332 
333  $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
334  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateThrowsExceptionIfProvidedImageHasWrongMimeType()

testCreateThrowsExceptionIfProvidedImageHasWrongMimeType ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php @expectedException \Exception @expectedExceptionMessage The image MIME type is not valid or not supported.

Definition at line 366 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

367  {
368  $encodedContent = base64_encode(file_get_contents($this->testImagePath));
369  $requestData = [
370  'id' => null,
371  'media_type' => 'image',
372  'label' => 'Image Text',
373  'position' => 1,
374  'types' => ['image'],
375  'disabled' => false,
376  'content' => [
377  'base64_encoded_data' => $encodedContent,
378  'type' => 'wrong_mime_type',
379  'name' => 'test_image.jpg',
380  ]
381  ];
382 
383  $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
384  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateThrowsExceptionIfProvidedImageNameContainsForbiddenCharacters()

testCreateThrowsExceptionIfProvidedImageNameContainsForbiddenCharacters ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php @expectedException \Exception @expectedExceptionMessage Provided image name contains forbidden characters.

Definition at line 416 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

417  {
418  $requestData = [
419  'id' => null,
420  'media_type' => 'image',
421  'label' => 'Image Text',
422  'position' => 1,
423  'types' => ['image'],
424  'disabled' => false,
425  'content' => [
426  'base64_encoded_data' => base64_encode(file_get_contents($this->testImagePath)),
427  'type' => 'image/jpeg',
428  'name' => 'test/\\{}|:"<>', // Cannot contain \ / : * ? " < > |
429  ]
430  ];
431 
432  $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
433  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateThrowsExceptionIfTargetProductDoesNotExist()

testCreateThrowsExceptionIfTargetProductDoesNotExist ( )

@expectedException \Exception @expectedExceptionMessage The product that was requested doesn't exist. Verify the product and try again.

Definition at line 390 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

391  {
392  $this->createServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media';
393 
394  $requestData = [
395  'id' => null,
396  'media_type' => 'image',
397  'label' => 'Image Text',
398  'position' => 1,
399  'types' => ['image'],
400  'disabled' => false,
401  'content' => [
402  'base64_encoded_data' => base64_encode(file_get_contents($this->testImagePath)),
403  'type' => 'image/jpeg',
404  'name' => 'test_image.jpg',
405  ]
406  ];
407 
408  $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
409  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateWithNotDefaultStoreId()

testCreateWithNotDefaultStoreId ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php

Definition at line 176 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

177  {
178  $requestData = [
179  'id' => null,
180  'media_type' => \Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter::MEDIA_TYPE_CODE,
181  'label' => 'Image Text',
182  'position' => 1,
183  'types' => ['image'],
184  'disabled' => false,
185  'content' => [
186  'base64_encoded_data' => base64_encode(file_get_contents($this->testImagePath)),
187  'type' => 'image/jpeg',
188  'name' => 'test_image.jpg',
189  ]
190  ];
191 
192  $actualResult = $this->_webApiCall(
193  $this->createServiceInfo,
194  [
195  'sku' => 'simple',
196  'entry' => $requestData,
197  'storeId' => 1,
198  ]
199  );
200  $targetProduct = $this->getTargetSimpleProduct();
201  $mediaGallery = $targetProduct->getData('media_gallery');
202  $this->assertCount(1, $mediaGallery['images']);
203  $updatedImage = array_shift($mediaGallery['images']);
204  // Values for not default store view were provided
205  $this->assertEquals('Image Text', $updatedImage['label']);
206  $this->assertEquals($actualResult, $updatedImage['value_id']);
207  $this->assertEquals(1, $updatedImage['position']);
208  $this->assertEquals(0, $updatedImage['disabled']);
209  $this->assertStringStartsWith('/t/e/test_image', $updatedImage['file']);
210  $this->assertEquals($updatedImage['file'], $targetProduct->getData('image'));
211  // No values for default store view were provided
212  $this->assertNull($updatedImage['label_default']);
213  $this->assertNull($updatedImage['position_default']);
214  $this->assertNull($updatedImage['disabled_default']);
215  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testCreateWithoutFileExtension()

testCreateWithoutFileExtension ( )

@magentoApiDataFixture Magento/Catalog/_files/product_simple.php

Definition at line 143 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

144  {
145  $requestData = [
146  'id' => null,
147  'media_type' => \Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter::MEDIA_TYPE_CODE,
148  'label' => 'Image Text',
149  'position' => 1,
150  'types' => ['image'],
151  'disabled' => false,
152  'content' => [
153  ImageContentInterface::BASE64_ENCODED_DATA => base64_encode(file_get_contents($this->testImagePath)),
154  ImageContentInterface::TYPE => 'image/jpeg',
155  ImageContentInterface::NAME => 'test_image'
156  ]
157  ];
158 
159  $actualResult = $this->_webApiCall($this->createServiceInfo, ['sku' => 'simple', 'entry' => $requestData]);
160  $targetProduct = $this->getTargetSimpleProduct();
161  $mediaGallery = $targetProduct->getData('media_gallery');
162 
163  $this->assertCount(1, $mediaGallery['images']);
164  $updatedImage = array_shift($mediaGallery['images']);
165  $this->assertEquals($actualResult, $updatedImage['value_id']);
166  $this->assertEquals('Image Text', $updatedImage['label']);
167  $this->assertEquals(1, $updatedImage['position']);
168  $this->assertEquals(0, $updatedImage['disabled']);
169  $this->assertStringStartsWith('/t/e/test_image', $updatedImage['file']);
170  $this->assertEquals($updatedImage['file'], $targetProduct->getData('image'));
171  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testDelete()

testDelete ( )

@magentoApiDataFixture Magento/Catalog/_files/product_with_image.php

Definition at line 296 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

297  {
298  $entryId = $this->getTargetGalleryEntryId();
299  $this->deleteServiceInfo['rest']['resourcePath'] = "/V1/products/simple/media/{$entryId}";
300  $requestData = [
301  'sku' => 'simple',
302  'entryId' => $this->getTargetGalleryEntryId(),
303  ];
304 
305  $this->assertTrue($this->_webApiCall($this->deleteServiceInfo, $requestData));
306  $targetProduct = $this->getTargetSimpleProduct();
307  $mediaGallery = $targetProduct->getData('media_gallery');
308  $this->assertCount(0, $mediaGallery['images']);
309  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testDeleteThrowsExceptionIfTargetProductDoesNotExist()

testDeleteThrowsExceptionIfTargetProductDoesNotExist ( )

@expectedException \Exception @expectedExceptionMessage The product that was requested doesn't exist. Verify the product and try again.

Definition at line 487 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

488  {
489  $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media/9999';
490  $requestData = [
491  'sku' => 'wrong_product_sku',
492  'entryId' => 9999,
493  ];
494 
495  $this->_webApiCall($this->deleteServiceInfo, $requestData);
496  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testDeleteThrowsExceptionIfThereIsNoImageWithGivenId()

testDeleteThrowsExceptionIfThereIsNoImageWithGivenId ( )

@magentoApiDataFixture Magento/Catalog/_files/product_with_image.php @expectedException \Exception @expectedExceptionMessage No image with the provided ID was found. Verify the ID and try again.

Definition at line 503 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

504  {
505  $this->deleteServiceInfo['rest']['resourcePath'] = '/V1/products/simple/media/9999';
506  $requestData = [
507  'sku' => 'simple',
508  'entryId' => 9999,
509  ];
510 
511  $this->_webApiCall($this->deleteServiceInfo, $requestData);
512  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testGetList()

testGetList ( )

@magentoApiDataFixture Magento/Catalog/_files/product_with_image.php

Definition at line 565 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

566  {
567  $productSku = 'simple'; //from fixture
568  $serviceInfo = [
569  'rest' => [
570  'resourcePath' => '/V1/products/' . urlencode($productSku) . '/media',
572  ],
573  'soap' => [
574  'service' => 'catalogProductAttributeMediaGalleryManagementV1',
575  'serviceVersion' => 'V1',
576  'operation' => 'catalogProductAttributeMediaGalleryManagementV1GetList',
577  ],
578  ];
579 
580  $requestData = [
581  'sku' => $productSku,
582  ];
583  $imageList = $this->_webApiCall($serviceInfo, $requestData);
584 
585  $image = reset($imageList);
586  $this->assertEquals('/m/a/magento_image.jpg', $image['file']);
587  $this->assertNotEmpty($image['types']);
588  $imageTypes = $image['types'];
589  $this->assertContains('image', $imageTypes);
590  $this->assertContains('small_image', $imageTypes);
591  $this->assertContains('thumbnail', $imageTypes);
592  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testGetListForAbsentSku()

testGetListForAbsentSku ( )

Definition at line 594 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

595  {
596  $productSku = 'absent_sku_' . time();
597  $serviceInfo = [
598  'rest' => [
599  'resourcePath' => '/V1/products/' . urlencode($productSku) . '/media',
601  ],
602  'soap' => [
603  'service' => 'catalogProductAttributeMediaGalleryManagementV1',
604  'serviceVersion' => 'V1',
605  'operation' => 'catalogProductAttributeMediaGalleryManagementV1GetList',
606  ],
607  ];
608 
609  $requestData = [
610  'sku' => $productSku,
611  ];
612  if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
613  $this->expectException('SoapFault');
614  $this->expectExceptionMessage(
615  "The product that was requested doesn't exist. Verify the product and try again."
616  );
617  } else {
618  $this->expectException('Exception');
619  $this->expectExceptionCode(404);
620  }
621  $this->_webApiCall($serviceInfo, $requestData);
622  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testUpdate()

testUpdate ( )

@magentoApiDataFixture Magento/Catalog/_files/product_with_image.php

Definition at line 220 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

221  {
222  $requestData = [
223  'sku' => 'simple',
224  'entry' => [
225  'id' => $this->getTargetGalleryEntryId(),
226  'label' => 'Updated Image Text',
227  'position' => 10,
228  'types' => ['thumbnail'],
229  'disabled' => true,
230  'media_type' => 'image',
231  ],
232  ];
233 
234  $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath']
235  . '/' . $this->getTargetGalleryEntryId();
236 
237  $this->assertTrue($this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all'));
238 
239  $targetProduct = $this->getTargetSimpleProduct();
240  $this->assertEquals('/m/a/magento_image.jpg', $targetProduct->getData('thumbnail'));
241  $this->assertEquals('no_selection', $targetProduct->getData('image'));
242  $this->assertEquals('no_selection', $targetProduct->getData('small_image'));
243  $mediaGallery = $targetProduct->getData('media_gallery');
244  $this->assertCount(1, $mediaGallery['images']);
245  $updatedImage = array_shift($mediaGallery['images']);
246  $this->assertEquals('Updated Image Text', $updatedImage['label']);
247  $this->assertEquals('/m/a/magento_image.jpg', $updatedImage['file']);
248  $this->assertEquals(10, $updatedImage['position']);
249  $this->assertEquals(1, $updatedImage['disabled']);
250  $this->assertEquals('Updated Image Text', $updatedImage['label_default']);
251  $this->assertEquals(10, $updatedImage['position_default']);
252  $this->assertEquals(1, $updatedImage['disabled_default']);
253  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testUpdateThrowsExceptionIfTargetProductDoesNotExist()

testUpdateThrowsExceptionIfTargetProductDoesNotExist ( )

@expectedException \Exception @expectedExceptionMessage The product that was requested doesn't exist. Verify the product and try again.

Definition at line 439 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

440  {
441  $this->updateServiceInfo['rest']['resourcePath'] = '/V1/products/wrong_product_sku/media'
442  . '/' . 'wrong-sku';
443  $requestData = [
444  'sku' => 'wrong_product_sku',
445  'entry' => [
446  'id' => 9999,
447  'media_type' => 'image',
448  'label' => 'Updated Image Text',
449  'position' => 1,
450  'types' => ['thumbnail'],
451  'disabled' => true,
452  ],
453  ];
454 
455  $this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all');
456  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testUpdateThrowsExceptionIfThereIsNoImageWithGivenId()

testUpdateThrowsExceptionIfThereIsNoImageWithGivenId ( )

@magentoApiDataFixture Magento/Catalog/_files/product_with_image.php @expectedException \Exception @expectedExceptionMessage No image with the provided ID was found. Verify the ID and try again.

Definition at line 463 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

464  {
465  $requestData = [
466  'sku' => 'simple',
467  'entry' => [
468  'id' => 9999,
469  'media_type' => 'image',
470  'label' => 'Updated Image Text',
471  'position' => 1,
472  'types' => ['thumbnail'],
473  'disabled' => true,
474  ],
475  ];
476 
477  $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath']
478  . '/' . $this->getTargetGalleryEntryId();
479 
480  $this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all');
481  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

◆ testUpdateWithNotDefaultStoreId()

testUpdateWithNotDefaultStoreId ( )

@magentoApiDataFixture Magento/Catalog/_files/product_with_image.php

Definition at line 258 of file ProductAttributeMediaGalleryManagementInterfaceTest.php.

259  {
260  $requestData = [
261  'sku' => 'simple',
262  'entry' => [
263  'id' => $this->getTargetGalleryEntryId(),
264  'label' => 'Updated Image Text',
265  'position' => 10,
266  'types' => ['thumbnail'],
267  'disabled' => true,
268  'media_type' => 'image',
269  ]
270  ];
271 
272  $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath']
273  . '/' . $this->getTargetGalleryEntryId();
274 
275  $this->assertTrue($this->_webApiCall($this->updateServiceInfo, $requestData, null, 'default'));
276 
277  $targetProduct = $this->getTargetSimpleProduct();
278  $this->assertEquals('/m/a/magento_image.jpg', $targetProduct->getData('thumbnail'));
279  $mediaGallery = $targetProduct->getData('media_gallery');
280  $this->assertCount(1, $mediaGallery['images']);
281  $updatedImage = array_shift($mediaGallery['images']);
282  // Not default store view values were updated
283  $this->assertEquals('Updated Image Text', $updatedImage['label']);
284  $this->assertEquals('/m/a/magento_image.jpg', $updatedImage['file']);
285  $this->assertEquals(10, $updatedImage['position']);
286  $this->assertEquals(1, $updatedImage['disabled']);
287  // Default store view values were not updated
288  $this->assertEquals('Image Alt Text', $updatedImage['label_default']);
289  $this->assertEquals(1, $updatedImage['position_default']);
290  $this->assertEquals(0, $updatedImage['disabled_default']);
291  }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)

Field Documentation

◆ $createServiceInfo

$createServiceInfo
protected

◆ $deleteServiceInfo

$deleteServiceInfo
protected

◆ $testImagePath

$testImagePath
protected

◆ $updateServiceInfo

$updateServiceInfo
protected

The documentation for this class was generated from the following file: