Skip to content

Commit afc849a

Browse files
committed
ACP2E-3063: [Cloud] Cache is not getting invalidated.
- with test
1 parent 7a1a14f commit afc849a

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Model/ProductTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
namespace Magento\Catalog\Model;
1010

11+
use Magento\Catalog\Api\Data\ProductInterface;
1112
use Magento\Catalog\Api\ProductRepositoryInterface;
1213
use Magento\Catalog\Model\Product\Attribute\Source\Status;
1314
use Magento\Catalog\Model\Product\Copier;
1415
use Magento\Catalog\Model\Product\Visibility;
16+
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
17+
use Magento\Framework\App\Cache\Type\Block;
1518
use Magento\Framework\App\Filesystem\DirectoryList;
1619
use Magento\Framework\Exception\CouldNotSaveException;
1720
use Magento\Framework\Exception\InputException;
@@ -21,8 +24,11 @@
2124
use Magento\Framework\Math\Random;
2225
use Magento\Framework\ObjectManagerInterface;
2326
use Magento\Store\Model\Store;
27+
use Magento\TestFramework\Fixture\DataFixture;
28+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
2429
use Magento\TestFramework\Helper\Bootstrap;
2530
use Magento\TestFramework\ObjectManager;
31+
use Magento\Widget\Model\Widget\Instance;
2632

2733
/**
2834
* Tests product model:
@@ -54,13 +60,19 @@ class ProductTest extends \PHPUnit\Framework\TestCase
5460
*/
5561
private $objectManager;
5662

63+
/**
64+
* @var DataFixtureStorageManager
65+
*/
66+
private $fixtures;
67+
5768
/**
5869
* @inheritdoc
5970
*/
6071
protected function setUp(): void
6172
{
6273
$this->objectManager = Bootstrap::getObjectManager();
6374
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
75+
$this->fixtures = DataFixtureStorageManager::getStorage();
6476
$this->_model = $this->objectManager->create(Product::class);
6577
}
6678

@@ -869,4 +881,33 @@ public function testSetPriceWithoutTypeId()
869881
$product = $this->productRepository->get('some_sku', false, null, true);
870882
$this->assertEquals(9.95, $product->getPrice());
871883
}
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+
}
872913
}

dev/tests/integration/testsuite/Magento/Cms/Controller/PageTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88

99
use Magento\Cms\Api\GetPageByIdentifierInterface;
1010
use Magento\Cms\Model\Page\CustomLayoutManagerInterface;
11+
use Magento\Framework\App\Cache\Type\Block;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Exception\NoSuchEntityException;
1114
use Magento\Framework\View\LayoutInterface;
1215
use Magento\TestFramework\Cms\Model\CustomLayoutManager;
16+
use Magento\Cms\Api\PageRepositoryInterface;
1317
use Magento\TestFramework\TestCase\AbstractController;
1418

1519
/**
@@ -126,6 +130,7 @@ public function testHomePageCustomHandles(): void
126130
* @dataProvider pageLayoutDataProvider
127131
* @param string $pageIdentifier
128132
* @return void
133+
* @throws NoSuchEntityException
129134
*/
130135
public function testPageWithCustomLayout(string $pageIdentifier): void
131136
{
@@ -147,4 +152,38 @@ public static function pageLayoutDataProvider(): array
147152
'Page with unavailable layout' => ['page-with-unavailable-layout']
148153
];
149154
}
155+
156+
/**
157+
* Tests page renders with changed layout
158+
*
159+
* @magentoDataFixture Magento/Cms/Fixtures/page_list.php
160+
* @return void
161+
* @throws NoSuchEntityException|LocalizedException
162+
*/
163+
public function testPageWithChangedLayoutCanCleanCacheTag(): void
164+
{
165+
$pageIdentifier = 'page-with-1column-layout';
166+
$blockHtmlCache = $this->_objectManager->get(
167+
Block::class
168+
);
169+
$page = $this->pageRetriever->execute($pageIdentifier, 0);
170+
$cacheKey = sprintf(
171+
'%s_%s',
172+
'CMS_PAGE_VIEW_ID',
173+
str_replace('-', '_', strtoupper($page->getId()))
174+
);
175+
176+
$this->dispatch('/cms/page/view/page_id/' . $page->getId());
177+
$this->assertStringContainsString(
178+
'<main id="maincontent" class="page-main">',
179+
$this->getResponse()->getBody()
180+
);
181+
$pageRepository = $this->_objectManager->get(PageRepositoryInterface::class);
182+
$page->setPageLayout('cms-full-width');
183+
$pageRepository->save($page);
184+
$this->dispatch('/cms/page/view/page_id/' . $page->getId());
185+
$this->assertFalse(
186+
$blockHtmlCache->test($cacheKey)
187+
);
188+
}
150189
}

0 commit comments

Comments
 (0)