88
99namespace Magento \Catalog \Api ;
1010
11- use Magento \Catalog \Test \Fixture \Product ;
11+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
1212use Magento \Framework \Api \Data \ImageContentInterface ;
1313use Magento \Store \Test \Fixture \Store as StoreFixture ;
1414use Magento \TestFramework \Fixture \DataFixture ;
2727 */
2828class ProductAttributeMediaGalleryManagementInterfaceTest extends WebapiAbstract
2929{
30+ public const RESOURCE_PATH = '/V1/products/ ' ;
31+
32+ public const SERVICE_NAME = 'catalogProductAttributeMediaGalleryManagementV1 ' ;
33+
34+ public const SERVICE_VERSION = 'V1 ' ;
35+
3036 /**
3137 * Default create service request information (product with SKU 'simple' is used)
3238 *
@@ -72,25 +78,25 @@ protected function setUp(): void
7278
7379 $ this ->createServiceInfo = [
7480 'rest ' => [
75- 'resourcePath ' => ' /V1/products/ simple/media ' ,
81+ 'resourcePath ' => self :: RESOURCE_PATH . ' simple/media ' ,
7682 'httpMethod ' => Request::HTTP_METHOD_POST ,
7783 ],
7884 'soap ' => [
79- 'service ' => ' catalogProductAttributeMediaGalleryManagementV1 ' ,
80- 'serviceVersion ' => ' V1 ' ,
81- 'operation ' => ' catalogProductAttributeMediaGalleryManagementV1Create ' ,
85+ 'service ' => self :: SERVICE_NAME ,
86+ 'serviceVersion ' => self :: SERVICE_VERSION ,
87+ 'operation ' => self :: SERVICE_NAME . ' Create ' ,
8288 ],
8389 ];
8490
8591 $ this ->updateServiceInfo = [
8692 'rest ' => [
87- 'resourcePath ' => ' /V1/products/ simple/media ' ,
93+ 'resourcePath ' => self :: RESOURCE_PATH . ' simple/media ' ,
8894 'httpMethod ' => Request::HTTP_METHOD_PUT ,
8995 ],
9096 'soap ' => [
9197 'service ' => 'catalogProductAttributeMediaGalleryManagementV1 ' ,
92- 'serviceVersion ' => ' V1 ' ,
93- 'operation ' => ' catalogProductAttributeMediaGalleryManagementV1Update ' ,
98+ 'serviceVersion ' => self :: SERVICE_VERSION ,
99+ 'operation ' => self :: SERVICE_NAME . ' Update ' ,
94100 ],
95101 ];
96102
@@ -99,9 +105,9 @@ protected function setUp(): void
99105 'httpMethod ' => Request::HTTP_METHOD_DELETE ,
100106 ],
101107 'soap ' => [
102- 'service ' => ' catalogProductAttributeMediaGalleryManagementV1 ' ,
103- 'serviceVersion ' => ' V1 ' ,
104- 'operation ' => ' catalogProductAttributeMediaGalleryManagementV1Remove ' ,
108+ 'service ' => self :: SERVICE_NAME ,
109+ 'serviceVersion ' => self :: SERVICE_VERSION ,
110+ 'operation ' => self :: SERVICE_NAME . ' Remove ' ,
105111 ],
106112 ];
107113
@@ -641,7 +647,7 @@ public function testDeleteThrowsExceptionIfThereIsNoImageWithGivenId()
641647
642648 #[
643649 DataFixture(StoreFixture::class, as: 'store2 ' ),
644- DataFixture(Product ::class, ['media_gallery_entries ' => [[], []]], as: 'product ' )
650+ DataFixture(ProductFixture ::class, ['media_gallery_entries ' => [[], []]], as: 'product ' )
645651 ]
646652 public function testDeleteThrowsExceptionIfTheImageCannotBeRemoved (): void
647653 {
@@ -692,13 +698,13 @@ public function testGet()
692698
693699 $ serviceInfo = [
694700 'rest ' => [
695- 'resourcePath ' => ' /V1/products/ ' . $ productSku . '/media/ ' . $ imageId ,
701+ 'resourcePath ' => self :: RESOURCE_PATH . $ productSku . '/media/ ' . $ imageId ,
696702 'httpMethod ' => Request::HTTP_METHOD_GET ,
697703 ],
698704 'soap ' => [
699- 'service ' => ' catalogProductAttributeMediaGalleryManagementV1 ' ,
700- 'serviceVersion ' => ' V1 ' ,
701- 'operation ' => ' catalogProductAttributeMediaGalleryManagementV1Get ' ,
705+ 'service ' => self :: SERVICE_NAME ,
706+ 'serviceVersion ' => self :: SERVICE_VERSION ,
707+ 'operation ' => self :: SERVICE_NAME . ' Get ' ,
702708 ],
703709 ];
704710 $ requestData = [
@@ -725,13 +731,13 @@ public function testGetList()
725731 $ productSku = 'simple ' ; //from fixture
726732 $ serviceInfo = [
727733 'rest ' => [
728- 'resourcePath ' => ' /V1/products/ ' . urlencode ($ productSku ) . '/media ' ,
734+ 'resourcePath ' => self :: RESOURCE_PATH . urlencode ($ productSku ) . '/media ' ,
729735 'httpMethod ' => Request::HTTP_METHOD_GET ,
730736 ],
731737 'soap ' => [
732- 'service ' => ' catalogProductAttributeMediaGalleryManagementV1 ' ,
733- 'serviceVersion ' => ' V1 ' ,
734- 'operation ' => ' catalogProductAttributeMediaGalleryManagementV1GetList ' ,
738+ 'service ' => self :: SERVICE_NAME ,
739+ 'serviceVersion ' => self :: SERVICE_VERSION ,
740+ 'operation ' => self :: SERVICE_NAME . ' GetList ' ,
735741 ],
736742 ];
737743
@@ -757,13 +763,13 @@ public function testGetListForAbsentSku()
757763 $ productSku = 'absent_sku_ ' . time ();
758764 $ serviceInfo = [
759765 'rest ' => [
760- 'resourcePath ' => ' /V1/products/ ' . urlencode ($ productSku ) . '/media ' ,
766+ 'resourcePath ' => self :: RESOURCE_PATH . urlencode ($ productSku ) . '/media ' ,
761767 'httpMethod ' => Request::HTTP_METHOD_GET ,
762768 ],
763769 'soap ' => [
764- 'service ' => ' catalogProductAttributeMediaGalleryManagementV1 ' ,
765- 'serviceVersion ' => ' V1 ' ,
766- 'operation ' => ' catalogProductAttributeMediaGalleryManagementV1GetList ' ,
770+ 'service ' => self :: SERVICE_NAME ,
771+ 'serviceVersion ' => self :: SERVICE_VERSION ,
772+ 'operation ' => self :: SERVICE_NAME . ' GetList ' ,
767773 ],
768774 ];
769775
@@ -828,4 +834,58 @@ public function testAddProductVideo()
828834 $ this ->assertStringStartsWith ('/t/e/test_image ' , $ updatedImage ['file ' ]);
829835 $ this ->assertEquals ($ videoContent , array_intersect_key ($ updatedImage , $ videoContent ));
830836 }
837+
838+ /**
839+ * Check content attribute in getList method
840+ *
841+ * @return void
842+ */
843+ #[
844+ DataFixture(ProductFixture::class, ['media_gallery_entries ' => [[]]], as: 'product ' ),
845+ ]
846+ public function testContentAttributeInGetList (): void
847+ {
848+ $ productSku = $ this ->fixtures ->get ('product ' )->getSku ();
849+ $ serviceInfo = [
850+ 'rest ' => [
851+ 'resourcePath ' => self ::RESOURCE_PATH .$ productSku ."/media " ,
852+ 'httpMethod ' => Request::HTTP_METHOD_GET ,
853+ ],
854+ 'soap ' => [
855+ 'service ' => self ::SERVICE_NAME ,
856+ 'serviceVersion ' => self ::SERVICE_VERSION ,
857+ 'operation ' => self ::SERVICE_NAME . 'getList ' ,
858+ ],
859+ ];
860+ $ response = $ this ->_webApiCall ($ serviceInfo , []);
861+ $ this ->assertArrayHasKey ('content ' , $ response [0 ]);
862+ }
863+
864+ /**
865+ * Check content attribute in getList method
866+ *
867+ * @return void
868+ */
869+ #[
870+ DataFixture(ProductFixture::class, ['media_gallery_entries ' => [[]]], as: 'product ' ),
871+ ]
872+ public function testContentAttributeInGet (): void
873+ {
874+ $ product = $ this ->fixtures ->get ('product ' );
875+ $ productSku = $ product ->getSku ();
876+ $ entryId = $ product ->getMediaGalleryEntries ()[0 ]->getId ();
877+ $ serviceInfo = [
878+ 'rest ' => [
879+ 'resourcePath ' => self ::RESOURCE_PATH .$ productSku ."/media/ " .$ entryId ,
880+ 'httpMethod ' => Request::HTTP_METHOD_GET ,
881+ ],
882+ 'soap ' => [
883+ 'service ' => self ::SERVICE_NAME ,
884+ 'serviceVersion ' => self ::SERVICE_VERSION ,
885+ 'operation ' => self ::SERVICE_NAME . 'get ' ,
886+ ],
887+ ];
888+ $ response = $ this ->_webApiCall ($ serviceInfo , []);
889+ $ this ->assertArrayHasKey ('content ' , $ response );
890+ }
831891}
0 commit comments