8
8
9
9
namespace Magento \Catalog \Api ;
10
10
11
- use Magento \Catalog \Test \Fixture \Product ;
11
+ use Magento \Catalog \Test \Fixture \Product as ProductFixture ;
12
12
use Magento \Framework \Api \Data \ImageContentInterface ;
13
13
use Magento \Store \Test \Fixture \Store as StoreFixture ;
14
14
use Magento \TestFramework \Fixture \DataFixture ;
27
27
*/
28
28
class ProductAttributeMediaGalleryManagementInterfaceTest extends WebapiAbstract
29
29
{
30
+ public const RESOURCE_PATH = '/V1/products/ ' ;
31
+
32
+ public const SERVICE_NAME = 'catalogProductAttributeMediaGalleryManagementV1 ' ;
33
+
34
+ public const SERVICE_VERSION = 'V1 ' ;
35
+
30
36
/**
31
37
* Default create service request information (product with SKU 'simple' is used)
32
38
*
@@ -72,25 +78,25 @@ protected function setUp(): void
72
78
73
79
$ this ->createServiceInfo = [
74
80
'rest ' => [
75
- 'resourcePath ' => ' /V1/products/ simple/media ' ,
81
+ 'resourcePath ' => self :: RESOURCE_PATH . ' simple/media ' ,
76
82
'httpMethod ' => Request::HTTP_METHOD_POST ,
77
83
],
78
84
'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 ' ,
82
88
],
83
89
];
84
90
85
91
$ this ->updateServiceInfo = [
86
92
'rest ' => [
87
- 'resourcePath ' => ' /V1/products/ simple/media ' ,
93
+ 'resourcePath ' => self :: RESOURCE_PATH . ' simple/media ' ,
88
94
'httpMethod ' => Request::HTTP_METHOD_PUT ,
89
95
],
90
96
'soap ' => [
91
97
'service ' => 'catalogProductAttributeMediaGalleryManagementV1 ' ,
92
- 'serviceVersion ' => ' V1 ' ,
93
- 'operation ' => ' catalogProductAttributeMediaGalleryManagementV1Update ' ,
98
+ 'serviceVersion ' => self :: SERVICE_VERSION ,
99
+ 'operation ' => self :: SERVICE_NAME . ' Update ' ,
94
100
],
95
101
];
96
102
@@ -99,9 +105,9 @@ protected function setUp(): void
99
105
'httpMethod ' => Request::HTTP_METHOD_DELETE ,
100
106
],
101
107
'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 ' ,
105
111
],
106
112
];
107
113
@@ -641,7 +647,7 @@ public function testDeleteThrowsExceptionIfThereIsNoImageWithGivenId()
641
647
642
648
#[
643
649
DataFixture(StoreFixture::class, as: 'store2 ' ),
644
- DataFixture(Product ::class, ['media_gallery_entries ' => [[], []]], as: 'product ' )
650
+ DataFixture(ProductFixture ::class, ['media_gallery_entries ' => [[], []]], as: 'product ' )
645
651
]
646
652
public function testDeleteThrowsExceptionIfTheImageCannotBeRemoved (): void
647
653
{
@@ -692,13 +698,13 @@ public function testGet()
692
698
693
699
$ serviceInfo = [
694
700
'rest ' => [
695
- 'resourcePath ' => ' /V1/products/ ' . $ productSku . '/media/ ' . $ imageId ,
701
+ 'resourcePath ' => self :: RESOURCE_PATH . $ productSku . '/media/ ' . $ imageId ,
696
702
'httpMethod ' => Request::HTTP_METHOD_GET ,
697
703
],
698
704
'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 ' ,
702
708
],
703
709
];
704
710
$ requestData = [
@@ -725,13 +731,13 @@ public function testGetList()
725
731
$ productSku = 'simple ' ; //from fixture
726
732
$ serviceInfo = [
727
733
'rest ' => [
728
- 'resourcePath ' => ' /V1/products/ ' . urlencode ($ productSku ) . '/media ' ,
734
+ 'resourcePath ' => self :: RESOURCE_PATH . urlencode ($ productSku ) . '/media ' ,
729
735
'httpMethod ' => Request::HTTP_METHOD_GET ,
730
736
],
731
737
'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 ' ,
735
741
],
736
742
];
737
743
@@ -757,13 +763,13 @@ public function testGetListForAbsentSku()
757
763
$ productSku = 'absent_sku_ ' . time ();
758
764
$ serviceInfo = [
759
765
'rest ' => [
760
- 'resourcePath ' => ' /V1/products/ ' . urlencode ($ productSku ) . '/media ' ,
766
+ 'resourcePath ' => self :: RESOURCE_PATH . urlencode ($ productSku ) . '/media ' ,
761
767
'httpMethod ' => Request::HTTP_METHOD_GET ,
762
768
],
763
769
'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 ' ,
767
773
],
768
774
];
769
775
@@ -828,4 +834,58 @@ public function testAddProductVideo()
828
834
$ this ->assertStringStartsWith ('/t/e/test_image ' , $ updatedImage ['file ' ]);
829
835
$ this ->assertEquals ($ videoContent , array_intersect_key ($ updatedImage , $ videoContent ));
830
836
}
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
+ }
831
891
}
0 commit comments