|
8 | 8 |
|
9 | 9 | namespace Magento\Catalog\Model; |
10 | 10 |
|
| 11 | +use Magento\Catalog\Api\Data\ProductInterface; |
11 | 12 | use Magento\Catalog\Api\ProductRepositoryInterface; |
12 | 13 | use Magento\Catalog\Model\Product\Attribute\Source\Status; |
13 | 14 | use Magento\Catalog\Model\Product\Copier; |
14 | 15 | use Magento\Catalog\Model\Product\Visibility; |
| 16 | +use Magento\Catalog\Test\Fixture\Product as ProductFixture; |
| 17 | +use Magento\Framework\App\Cache\Type\Block; |
15 | 18 | use Magento\Framework\App\Filesystem\DirectoryList; |
16 | 19 | use Magento\Framework\Exception\CouldNotSaveException; |
17 | 20 | use Magento\Framework\Exception\InputException; |
|
21 | 24 | use Magento\Framework\Math\Random; |
22 | 25 | use Magento\Framework\ObjectManagerInterface; |
23 | 26 | use Magento\Store\Model\Store; |
| 27 | +use Magento\TestFramework\Fixture\DataFixture; |
| 28 | +use Magento\TestFramework\Fixture\DataFixtureStorageManager; |
24 | 29 | use Magento\TestFramework\Helper\Bootstrap; |
25 | 30 | use Magento\TestFramework\ObjectManager; |
| 31 | +use Magento\Widget\Model\Widget\Instance; |
26 | 32 |
|
27 | 33 | /** |
28 | 34 | * Tests product model: |
@@ -54,13 +60,19 @@ class ProductTest extends \PHPUnit\Framework\TestCase |
54 | 60 | */ |
55 | 61 | private $objectManager; |
56 | 62 |
|
| 63 | + /** |
| 64 | + * @var DataFixtureStorageManager |
| 65 | + */ |
| 66 | + private $fixtures; |
| 67 | + |
57 | 68 | /** |
58 | 69 | * @inheritdoc |
59 | 70 | */ |
60 | 71 | protected function setUp(): void |
61 | 72 | { |
62 | 73 | $this->objectManager = Bootstrap::getObjectManager(); |
63 | 74 | $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class); |
| 75 | + $this->fixtures = DataFixtureStorageManager::getStorage(); |
64 | 76 | $this->_model = $this->objectManager->create(Product::class); |
65 | 77 | } |
66 | 78 |
|
@@ -869,4 +881,33 @@ public function testSetPriceWithoutTypeId() |
869 | 881 | $product = $this->productRepository->get('some_sku', false, null, true); |
870 | 882 | $this->assertEquals(9.95, $product->getPrice()); |
871 | 883 | } |
| 884 | + |
| 885 | + /** |
| 886 | + * Tests case for product saving invalidate cache successfully |
| 887 | + */ |
| 888 | + #[ |
| 889 | + DataFixture(ProductFixture::class, |
| 890 | + ['sku' => 'simple1', 'price' => 10, 'page_layout' => '1column'], as: 'product' |
| 891 | + ), |
| 892 | + ] |
| 893 | + public function testSavingProductInAdminWithLayoutChangeWillInvalidateCache() |
| 894 | + { |
| 895 | + /** @var ProductInterface $product */ |
| 896 | + $product = $this->fixtures->get('product'); |
| 897 | + $product->setStatus(Status::STATUS_ENABLED); |
| 898 | + $this->productRepository->save($product); |
| 899 | + $blockHtmlCache = $this->objectManager->get( |
| 900 | + Block::class |
| 901 | + ); |
| 902 | + $cacheKey = sprintf( |
| 903 | + '%s', |
| 904 | + str_replace('{{ID}}', (string) $product->getId(), Instance::SINGLE_PRODUCT_LAYOUT_HANDLE) |
| 905 | + ); |
| 906 | + |
| 907 | + $product->setPageLayout('cms-full-width'); |
| 908 | + $this->productRepository->save($product); |
| 909 | + $this->assertFalse( |
| 910 | + $blockHtmlCache->test($cacheKey) |
| 911 | + ); |
| 912 | + } |
872 | 913 | } |
0 commit comments