18
18
use Magento \CatalogGraphQl \Model \Resolver \Product \MediaGallery ;
19
19
use Magento \Framework \Api \Data \ImageContentInterfaceFactory ;
20
20
use Magento \Framework \App \Area as AppArea ;
21
- use Magento \Framework \App \Filesystem \DirectoryList ;
22
21
use Magento \Framework \App \ObjectManager \ConfigLoader ;
23
22
use Magento \Framework \App \State as AppState ;
24
- use Magento \Framework \Filesystem \Directory \WriteInterface as DirectoryWriteInterface ;
25
23
use Magento \Framework \ObjectManagerInterface ;
26
24
use Magento \GraphQlResolverCache \Model \Resolver \Result \CacheKey \Calculator \ProviderInterface ;
27
25
use Magento \GraphQlResolverCache \Model \Resolver \Result \Type as GraphQlResolverCache ;
28
- use Magento \ImportExport \Model \Import ;
29
- use Magento \Integration \Api \IntegrationServiceInterface ;
30
- use Magento \Integration \Model \Integration ;
31
- use Magento \Framework \Filesystem ;
32
26
use Magento \TestFramework \Fixture \DataFixture ;
33
27
use Magento \TestFramework \Helper \Bootstrap ;
34
28
use Magento \TestFramework \TestCase \GraphQl \ResolverCacheAbstract ;
@@ -54,49 +48,15 @@ class MediaGalleryTest extends ResolverCacheAbstract
54
48
*/
55
49
private $ graphQlResolverCache ;
56
50
57
- /**
58
- * @var IntegrationServiceInterface
59
- */
60
- private $ integrationService ;
61
-
62
- /**
63
- * @var Integration
64
- */
65
- private $ integration ;
66
-
67
- /**
68
- * @var DirectoryWriteInterface
69
- */
70
- private $ mediaDirectory ;
71
-
72
- /**
73
- * @var string[]
74
- */
75
- private $ filesToRemove = [];
76
-
77
51
protected function setUp (): void
78
52
{
79
53
$ this ->objectManager = Bootstrap::getObjectManager ();
80
54
$ this ->graphQlResolverCache = $ this ->objectManager ->get (GraphQlResolverCache::class);
81
55
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
82
- $ this ->integrationService = $ this ->objectManager ->get (IntegrationServiceInterface::class);
83
- $ filesystem = $ this ->objectManager ->get (Filesystem::class);
84
- $ this ->mediaDirectory = $ filesystem ->getDirectoryWrite (DirectoryList::MEDIA );
85
56
86
57
parent ::setUp ();
87
58
}
88
59
89
- protected function tearDown (): void
90
- {
91
- foreach ($ this ->filesToRemove as $ fileToRemove ) {
92
- $ this ->mediaDirectory ->delete ($ fileToRemove );
93
- }
94
-
95
- $ this ->mediaDirectory ->delete ('import/images ' );
96
-
97
- parent ::tearDown ();
98
- }
99
-
100
60
#[
101
61
DataFixture(ProductFixture::class, ['sku ' => 'product1 ' , 'media_gallery_entries ' => [[]]], as: 'product ' ),
102
62
]
@@ -454,168 +414,6 @@ public function testCacheIsInvalidatedOnProductDeletion()
454
414
$ this ->assertMediaGalleryResolverCacheRecordDoesNotExist ($ product );
455
415
}
456
416
457
- #[
458
- DataFixture(ProductFixture::class, ['sku ' => 'product1 ' , 'media_gallery_entries ' => [[]]], as: 'product ' ),
459
- ]
460
- public function testCacheIsInvalidatedWhenUpdatingMediaGalleryEntriesOnAProductViaImport ()
461
- {
462
- // first, create an integration so that cache is not cleared in
463
- // Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
464
- $ integration = $ this ->getOauthIntegration ();
465
-
466
- $ product = $ this ->productRepository ->get ('product1 ' );
467
-
468
- $ this ->assertCount (
469
- 1 ,
470
- $ product ->getMediaGalleryEntries ()
471
- );
472
-
473
- $ query = $ this ->getProductWithMediaGalleryQuery ($ product );
474
- $ response = $ this ->graphQlQuery ($ query );
475
-
476
- $ this ->assertCount (
477
- 1 ,
478
- $ response ['products ' ]['items ' ][0 ]['media_gallery ' ]
479
- );
480
-
481
- $ this ->assertMediaGalleryResolverCacheRecordExists ($ product );
482
-
483
- $ serviceInfo = [
484
- 'rest ' => [
485
- 'resourcePath ' => '/V1/import/csv ' ,
486
- 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
487
- ],
488
- ];
489
-
490
- // move test image into media directory
491
- $ destinationDir = $ this ->mediaDirectory ->getAbsolutePath () . 'import/images ' ;
492
-
493
- $ this ->mediaDirectory ->create ($ destinationDir );
494
-
495
- $ sourcePathname = dirname (__FILE__ ) . '/../../_files/magento_image.jpg ' ;
496
- $ destinationFilePathname = $ this ->mediaDirectory ->getAbsolutePath ("$ destinationDir/magento_image.jpg " );
497
-
498
- $ this ->mediaDirectory ->getDriver ()->filePutContents (
499
- $ destinationFilePathname ,
500
- file_get_contents ($ sourcePathname )
501
- );
502
-
503
- // add file to list of files to remove after test finishes
504
- $ this ->filesToRemove [] = $ destinationFilePathname ;
505
-
506
- $ requestData = [
507
- 'source ' => [
508
- 'entity ' => 'catalog_product ' ,
509
- 'behavior ' => 'append ' ,
510
- 'validationStrategy ' => 'validation-stop-on-errors ' ,
511
- 'allowedErrorCount ' => '10 ' ,
512
- Import::FIELD_NAME_IMG_FILE_DIR => $ destinationDir ,
513
- 'csvData ' => base64_encode ("sku,base_image \nproduct1,magento_image.jpg \n" ),
514
- ],
515
- ];
516
-
517
- $ response = $ this ->_webApiCall ($ serviceInfo , $ requestData , 'rest ' , null , $ integration );
518
-
519
- $ this ->assertEquals (
520
- 'Entities Processed: 1 ' ,
521
- $ response [0 ]
522
- );
523
-
524
- // assert product has updated media gallery entry count
525
- $ this ->productRepository ->cleanCache ();
526
- $ updatedProduct = $ this ->productRepository ->get ('product1 ' );
527
- $ this ->assertCount (
528
- 2 ,
529
- $ updatedProduct ->getMediaGalleryEntries ()
530
- );
531
-
532
- // assert media gallery resolver cache is invalidated
533
- $ this ->assertMediaGalleryResolverCacheRecordDoesNotExist ($ product );
534
- }
535
-
536
- #[
537
- DataFixture(ProductFixture::class, ['sku ' => 'product1 ' , 'media_gallery_entries ' => [[]]], as: 'product ' ),
538
- ]
539
- public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeViaImport ()
540
- {
541
- // first, create an integration so that cache is not cleared in
542
- // Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call
543
- $ integration = $ this ->getOauthIntegration ();
544
-
545
- $ product = $ this ->productRepository ->get ('product1 ' );
546
-
547
- $ this ->assertCount (
548
- 1 ,
549
- $ product ->getMediaGalleryEntries ()
550
- );
551
-
552
- $ query = $ this ->getProductWithMediaGalleryQuery ($ product );
553
- $ response = $ this ->graphQlQuery ($ query );
554
-
555
- $ this ->assertCount (
556
- 1 ,
557
- $ response ['products ' ]['items ' ][0 ]['media_gallery ' ]
558
- );
559
-
560
- $ this ->assertMediaGalleryResolverCacheRecordExists ($ product );
561
-
562
- $ serviceInfo = [
563
- 'rest ' => [
564
- 'resourcePath ' => '/V1/import/csv ' ,
565
- 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
566
- ],
567
- ];
568
-
569
- $ requestData = [
570
- 'source ' => [
571
- 'entity ' => 'catalog_product ' ,
572
- 'behavior ' => 'append ' ,
573
- 'validationStrategy ' => 'validation-stop-on-errors ' ,
574
- 'allowedErrorCount ' => '10 ' ,
575
- 'csvData ' => base64_encode ("sku,name \nproduct1,NEW_NAME \n" ),
576
- ],
577
- ];
578
-
579
- $ response = $ this ->_webApiCall ($ serviceInfo , $ requestData , 'rest ' , null , $ integration );
580
-
581
- $ this ->assertEquals (
582
- 'Entities Processed: 1 ' ,
583
- $ response [0 ]
584
- );
585
-
586
- // assert product has updated media gallery entry count
587
- $ this ->productRepository ->cleanCache ();
588
- $ updatedProduct = $ this ->productRepository ->get ('product1 ' );
589
-
590
- $ this ->assertEquals (
591
- 'NEW_NAME ' ,
592
- $ updatedProduct ->getName ()
593
- );
594
-
595
- // assert media gallery resolver cache is NOT invalidated
596
- $ this ->assertMediaGalleryResolverCacheRecordExists ($ product );
597
- }
598
-
599
- /**
600
- *
601
- * @return Integration
602
- * @throws \Magento\Framework\Exception\IntegrationException
603
- */
604
- private function getOauthIntegration (): Integration
605
- {
606
- if (!isset ($ this ->integration )) {
607
- $ params = [
608
- 'all_resources ' => true ,
609
- 'status ' => Integration::STATUS_ACTIVE ,
610
- 'name ' => 'Integration ' . microtime ()
611
- ];
612
-
613
- $ this ->integration = $ this ->integrationService ->create ($ params );
614
- }
615
-
616
- return $ this ->integration ;
617
- }
618
-
619
417
/**
620
418
* Assert that media gallery cache record exists for the $product.
621
419
*
0 commit comments