23
23
use Magento \Framework \ObjectManagerInterface ;
24
24
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \Calculator \ProviderInterface ;
25
25
use Magento \GraphQlResolverCache \Model \Resolver \Result \Type as GraphQlResolverCache ;
26
+ use Magento \Integration \Api \IntegrationServiceInterface ;
27
+ use Magento \Integration \Model \Integration ;
26
28
use Magento \TestFramework \Fixture \DataFixture ;
27
29
use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
28
30
use Magento \TestFramework \Helper \Bootstrap ;
@@ -49,6 +51,11 @@ class MediaGalleryTest extends ResolverCacheAbstract
49
51
*/
50
52
private $ graphQlResolverCache ;
51
53
54
+ /**
55
+ * @var Integration
56
+ */
57
+ private $ integration ;
58
+
52
59
/**
53
60
* @var DataFixtureStorageManager
54
61
*/
@@ -233,6 +240,64 @@ public function actionMechanismProvider(): array
233
240
$ productRepository = $ objectManager ->get (ProductRepositoryInterface::class);
234
241
235
242
return [
243
+ 'update non-gallery-related attribute via rest ' => [
244
+ function (ProductInterface $ product ) use ($ productRepository ) {
245
+ // create an integration so that cache is not cleared in
246
+ // Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
247
+ $ integration = $ this ->getOauthIntegration ();
248
+
249
+ $ serviceInfo = [
250
+ 'rest ' => [
251
+ 'resourcePath ' => '/V1/products/ ' . $ product ->getSku (),
252
+ 'httpMethod ' => 'PUT ' ,
253
+ ],
254
+ ];
255
+
256
+ $ this ->_webApiCall (
257
+ $ serviceInfo ,
258
+ ['product ' => ['name ' => 'new name ' ]],
259
+ 'rest ' ,
260
+ null ,
261
+ $ integration
262
+ );
263
+ },
264
+ false
265
+ ],
266
+ 'update gallery-related attribute via rest ' => [
267
+ function (ProductInterface $ product ) use ($ productRepository , $ galleryManagement ) {
268
+ // create an integration so that cache is not cleared in
269
+ // Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
270
+ $ integration = $ this ->getOauthIntegration ();
271
+
272
+ $ galleryEntry = $ product ->getMediaGalleryEntries ()[0 ];
273
+ $ galleryEntryId = $ galleryEntry ->getId ();
274
+
275
+ $ serviceInfo = [
276
+ 'rest ' => [
277
+ 'resourcePath ' => '/V1/products/ ' . $ product ->getSku () . '/media/ ' . $ galleryEntryId ,
278
+ 'httpMethod ' => 'PUT ' ,
279
+ ],
280
+ ];
281
+
282
+ $ videoContent = $ galleryEntry ->getExtensionAttributes ()->getVideoContent ();
283
+
284
+ $ galleryEntryArray = $ galleryEntry ->toArray ();
285
+ $ galleryEntryArray ['extension_attributes ' ] = [
286
+ 'video_content ' => $ videoContent ->toArray (),
287
+ ];
288
+
289
+ $ galleryEntryArray ['label ' ] = 'new label ' ;
290
+
291
+ $ this ->_webApiCall (
292
+ $ serviceInfo ,
293
+ ['entry ' => $ galleryEntryArray ],
294
+ 'rest ' ,
295
+ null ,
296
+ $ integration
297
+ );
298
+ },
299
+ true
300
+ ],
236
301
'add new media gallery entry ' => [
237
302
function (ProductInterface $ product ) use ($ galleryManagement , $ objectManager ) {
238
303
/** @var ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory */
@@ -567,4 +632,25 @@ private function getProductWithMediaGalleryQuery(ProductInterface $product): str
567
632
}
568
633
QUERY ;
569
634
}
635
+
636
+ /**
637
+ *
638
+ * @return Integration
639
+ * @throws \Magento\Framework\Exception\IntegrationException
640
+ */
641
+ private function getOauthIntegration (): Integration
642
+ {
643
+ if (!isset ($ this ->integration )) {
644
+ $ params = [
645
+ 'all_resources ' => true ,
646
+ 'status ' => Integration::STATUS_ACTIVE ,
647
+ 'name ' => 'Integration ' . microtime ()
648
+ ];
649
+
650
+ $ this ->integration = Bootstrap::getObjectManager ()->get (IntegrationServiceInterface::class)
651
+ ->create ($ params );
652
+ }
653
+
654
+ return $ this ->integration ;
655
+ }
570
656
}
0 commit comments