2323use Magento \Framework \ObjectManagerInterface ;
2424use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \Calculator \ProviderInterface ;
2525use Magento \GraphQlResolverCache \Model \Resolver \Result \Type as GraphQlResolverCache ;
26+ use Magento \Integration \Api \IntegrationServiceInterface ;
27+ use Magento \Integration \Model \Integration ;
2628use Magento \TestFramework \Fixture \DataFixture ;
2729use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
2830use Magento \TestFramework \Helper \Bootstrap ;
@@ -49,6 +51,11 @@ class MediaGalleryTest extends ResolverCacheAbstract
4951 */
5052 private $ graphQlResolverCache ;
5153
54+ /**
55+ * @var Integration
56+ */
57+ private $ integration ;
58+
5259 /**
5360 * @var DataFixtureStorageManager
5461 */
@@ -233,6 +240,64 @@ public function actionMechanismProvider(): array
233240 $ productRepository = $ objectManager ->get (ProductRepositoryInterface::class);
234241
235242 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+ ],
236301 'add new media gallery entry ' => [
237302 function (ProductInterface $ product ) use ($ galleryManagement , $ objectManager ) {
238303 /** @var ProductAttributeMediaGalleryEntryInterfaceFactory $mediaGalleryEntryFactory */
@@ -567,4 +632,25 @@ private function getProductWithMediaGalleryQuery(ProductInterface $product): str
567632}
568633QUERY ;
569634 }
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+ }
570656}
0 commit comments