|
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\Model\Integration; |
26 | 27 | use Magento\TestFramework\Fixture\DataFixture;
|
27 | 28 | use Magento\TestFramework\Helper\Bootstrap;
|
28 | 29 | use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
|
@@ -414,6 +415,80 @@ public function testCacheIsInvalidatedOnProductDeletion()
|
414 | 415 | $this->assertMediaGalleryResolverCacheRecordDoesNotExist($product);
|
415 | 416 | }
|
416 | 417 |
|
| 418 | + #[ |
| 419 | + DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'), |
| 420 | + ] |
| 421 | + public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeViaImport() |
| 422 | + { |
| 423 | + // first, create an integration so that cache is not cleared in |
| 424 | + // Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call |
| 425 | + /** @var $integrationService \Magento\Integration\Api\IntegrationServiceInterface */ |
| 426 | + $integrationService = $this->objectManager->get(\Magento\Integration\Api\IntegrationServiceInterface::class); |
| 427 | + |
| 428 | + $params = [ |
| 429 | + 'all_resources' => true, |
| 430 | + 'integration_id' => 1, |
| 431 | + 'status' => Integration::STATUS_ACTIVE, |
| 432 | + 'name' => 'Integration' . microtime() |
| 433 | + ]; |
| 434 | + |
| 435 | + $integration = $integrationService->create($params); |
| 436 | + $integration->setStatus(\Magento\Integration\Model\Integration::STATUS_ACTIVE)->save(); |
| 437 | + |
| 438 | + $product = $this->productRepository->get('product1'); |
| 439 | + |
| 440 | + $this->assertCount( |
| 441 | + 1, |
| 442 | + $product->getMediaGalleryEntries() |
| 443 | + ); |
| 444 | + |
| 445 | + $query = $this->getProductWithMediaGalleryQuery($product); |
| 446 | + $response = $this->graphQlQuery($query); |
| 447 | + |
| 448 | + $this->assertCount( |
| 449 | + 1, |
| 450 | + $response['products']['items'][0]['media_gallery'] |
| 451 | + ); |
| 452 | + |
| 453 | + $this->assertMediaGalleryResolverCacheRecordExists($product); |
| 454 | + |
| 455 | + $serviceInfo = [ |
| 456 | + 'rest' => [ |
| 457 | + 'resourcePath' => '/V1/import/csv', |
| 458 | + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, |
| 459 | + ], |
| 460 | + ]; |
| 461 | + |
| 462 | + $requestData = [ |
| 463 | + 'source' => [ |
| 464 | + 'entity' => 'catalog_product', |
| 465 | + 'behavior' => 'append', |
| 466 | + 'validationStrategy' => 'validation-stop-on-errors', |
| 467 | + 'allowedErrorCount' => '10', |
| 468 | + 'csvData' => base64_encode("sku,name\nproduct1,NEW_NAME\n"), |
| 469 | + ], |
| 470 | + ]; |
| 471 | + |
| 472 | + $response = $this->_webApiCall($serviceInfo, $requestData, 'rest', null, $integration); |
| 473 | + |
| 474 | + $this->assertEquals( |
| 475 | + 'Entities Processed: 1', |
| 476 | + $response[0] |
| 477 | + ); |
| 478 | + |
| 479 | + // assert product has updated media gallery entry count |
| 480 | + $this->productRepository->cleanCache(); |
| 481 | + $updatedProduct = $this->productRepository->get('product1'); |
| 482 | + |
| 483 | + $this->assertEquals( |
| 484 | + 'NEW_NAME', |
| 485 | + $updatedProduct->getName() |
| 486 | + ); |
| 487 | + |
| 488 | + // assert media gallery resolver cache is NOT invalidated |
| 489 | + $this->assertMediaGalleryResolverCacheRecordExists($product); |
| 490 | + } |
| 491 | + |
417 | 492 | /**
|
418 | 493 | * Assert that media gallery cache record exists for the $product.
|
419 | 494 | *
|
|
0 commit comments