|
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\ImportExport\Model\Import; |
26 | 27 | use Magento\Integration\Model\Integration;
|
27 | 28 | use Magento\TestFramework\Fixture\DataFixture;
|
28 | 29 | use Magento\TestFramework\Helper\Bootstrap;
|
@@ -418,22 +419,75 @@ public function testCacheIsInvalidatedOnProductDeletion()
|
418 | 419 | #[
|
419 | 420 | DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'),
|
420 | 421 | ]
|
421 |
| - public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeViaImport() |
| 422 | + public function testCacheIsInvalidatedWhenUpdatingMediaGalleryEntriesOnAProductViaImport() |
422 | 423 | {
|
423 | 424 | // first, create an integration so that cache is not cleared in
|
424 | 425 | // 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); |
| 426 | + $integration = $this->createNewOauthIntegration(); |
427 | 427 |
|
428 |
| - $params = [ |
429 |
| - 'all_resources' => true, |
430 |
| - 'integration_id' => 1, |
431 |
| - 'status' => Integration::STATUS_ACTIVE, |
432 |
| - 'name' => 'Integration' . microtime() |
| 428 | + $product = $this->productRepository->get('product1'); |
| 429 | + |
| 430 | + $this->assertCount( |
| 431 | + 1, |
| 432 | + $product->getMediaGalleryEntries() |
| 433 | + ); |
| 434 | + |
| 435 | + $query = $this->getProductWithMediaGalleryQuery($product); |
| 436 | + $response = $this->graphQlQuery($query); |
| 437 | + |
| 438 | + $this->assertCount( |
| 439 | + 1, |
| 440 | + $response['products']['items'][0]['media_gallery'] |
| 441 | + ); |
| 442 | + |
| 443 | + $this->assertMediaGalleryResolverCacheRecordExists($product); |
| 444 | + |
| 445 | + $serviceInfo = [ |
| 446 | + 'rest' => [ |
| 447 | + 'resourcePath' => '/V1/import/csv', |
| 448 | + 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, |
| 449 | + ], |
433 | 450 | ];
|
434 | 451 |
|
435 |
| - $integration = $integrationService->create($params); |
436 |
| - $integration->setStatus(\Magento\Integration\Model\Integration::STATUS_ACTIVE)->save(); |
| 452 | + $requestData = [ |
| 453 | + 'source' => [ |
| 454 | + 'entity' => 'catalog_product', |
| 455 | + 'behavior' => 'append', |
| 456 | + 'validationStrategy' => 'validation-stop-on-errors', |
| 457 | + 'allowedErrorCount' => '10', |
| 458 | + Import::FIELD_NAME_IMG_FILE_DIR => |
| 459 | + '/Users/dmooney/Code/vagrant-magento/magento2ce/var/import/images/product_images', |
| 460 | + 'csvData' => base64_encode("sku,base_image\nproduct1,design_patterns.jpeg\n"), |
| 461 | + ], |
| 462 | + ]; |
| 463 | + |
| 464 | + $response = $this->_webApiCall($serviceInfo, $requestData, 'rest', null, $integration); |
| 465 | + |
| 466 | + $this->assertEquals( |
| 467 | + 'Entities Processed: 1', |
| 468 | + $response[0] |
| 469 | + ); |
| 470 | + |
| 471 | + // assert product has updated media gallery entry count |
| 472 | + $this->productRepository->cleanCache(); |
| 473 | + $updatedProduct = $this->productRepository->get('product1'); |
| 474 | + $this->assertCount( |
| 475 | + 2, |
| 476 | + $updatedProduct->getMediaGalleryEntries() |
| 477 | + ); |
| 478 | + |
| 479 | + // assert media gallery resolver cache is invalidated |
| 480 | + $this->assertMediaGalleryResolverCacheRecordDoesNotExist($product); |
| 481 | + } |
| 482 | + |
| 483 | + #[ |
| 484 | + DataFixture(ProductFixture::class, ['sku' => 'product1', 'media_gallery_entries' => [[]]], as: 'product'), |
| 485 | + ] |
| 486 | + public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeViaImport() |
| 487 | + { |
| 488 | + // first, create an integration so that cache is not cleared in |
| 489 | + // Magento\TestFramework\Authentication\OauthHelper::_createIntegration before making the API call |
| 490 | + $integration = $this->createNewOauthIntegration(); |
437 | 491 |
|
438 | 492 | $product = $this->productRepository->get('product1');
|
439 | 493 |
|
@@ -489,6 +543,29 @@ public function testCacheIsNotInvalidatedWhenUpdatingProductSpecificAttributeVia
|
489 | 543 | $this->assertMediaGalleryResolverCacheRecordExists($product);
|
490 | 544 | }
|
491 | 545 |
|
| 546 | + /** |
| 547 | + * |
| 548 | + * @return Integration |
| 549 | + * @throws \Magento\Framework\Exception\IntegrationException |
| 550 | + */ |
| 551 | + private function createNewOauthIntegration(): Integration |
| 552 | + { |
| 553 | + /** @var $integrationService \Magento\Integration\Api\IntegrationServiceInterface */ |
| 554 | + $integrationService = $this->objectManager->get(\Magento\Integration\Api\IntegrationServiceInterface::class); |
| 555 | + |
| 556 | + $params = [ |
| 557 | + 'all_resources' => true, |
| 558 | + 'integration_id' => 1, |
| 559 | + 'status' => Integration::STATUS_ACTIVE, |
| 560 | + 'name' => 'Integration' . microtime() |
| 561 | + ]; |
| 562 | + |
| 563 | + $integration = $integrationService->create($params); |
| 564 | + $integration->setStatus(\Magento\Integration\Model\Integration::STATUS_ACTIVE)->save(); |
| 565 | + |
| 566 | + return $integration; |
| 567 | + } |
| 568 | + |
492 | 569 | /**
|
493 | 570 | * Assert that media gallery cache record exists for the $product.
|
494 | 571 | *
|
|
0 commit comments