|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * |
4 |
| - * Copyright © Magento, Inc. All rights reserved. |
5 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2015 Adobe |
| 4 | + * All Rights Reserved. |
6 | 5 | */
|
7 | 6 | declare(strict_types=1);
|
8 | 7 |
|
@@ -895,4 +894,41 @@ public function testContentAttributeInGet(): void
|
895 | 894 | $response = $this->_webApiCall($serviceInfo, $requestData);
|
896 | 895 | $this->assertArrayHasKey('content', $response);
|
897 | 896 | }
|
| 897 | + |
| 898 | + /** |
| 899 | + * Test update() method when existing image gets overwritten and name is not changed |
| 900 | + * |
| 901 | + * @magentoApiDataFixture Magento/Catalog/_files/product_with_image.php |
| 902 | + */ |
| 903 | + public function testUpdateExistingImage() |
| 904 | + { |
| 905 | + $productRepository = $this->objectManager->create(ProductRepositoryInterface::class); |
| 906 | + /** @var \Magento\Catalog\Api\Data\ProductInterface $product */ |
| 907 | + $product = $productRepository->get('simple'); |
| 908 | + $imageId = (int)$product->getMediaGalleryImages()->getFirstItem()->getValueId(); |
| 909 | + $requestData = [ |
| 910 | + 'sku' => 'simple', |
| 911 | + 'entry' => [ |
| 912 | + 'id' => $this->getTargetGalleryEntryId(), |
| 913 | + 'label' => 'Updated Image Text', |
| 914 | + 'position' => 10, |
| 915 | + 'types' => ['thumbnail'], |
| 916 | + 'disabled' => true, |
| 917 | + 'media_type' => 'image', |
| 918 | + 'content' => [ |
| 919 | + 'base64_encoded_data' => base64_encode(file_get_contents($this->testImagePath)), |
| 920 | + 'type' => 'image/jpeg', |
| 921 | + 'name' => 'magento_image.jpg', |
| 922 | + ] |
| 923 | + ] |
| 924 | + ]; |
| 925 | + |
| 926 | + $this->updateServiceInfo['rest']['resourcePath'] = $this->updateServiceInfo['rest']['resourcePath'] |
| 927 | + . '/' . $this->getTargetGalleryEntryId(); |
| 928 | + |
| 929 | + $this->assertTrue($this->_webApiCall($this->updateServiceInfo, $requestData, null, 'all')); |
| 930 | + $updatedImage = $this->assertMediaGalleryData($imageId, '/m/a/magento_image.jpg', 'Updated Image Text'); |
| 931 | + $this->assertEquals(10, $updatedImage['position_default']); |
| 932 | + $this->assertEquals(1, $updatedImage['disabled_default']); |
| 933 | + } |
898 | 934 | }
|
0 commit comments