Skip to content

Commit 41b60a4

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-99677' into 2.3-develop-pr25
2 parents 219588b + b98e8ba commit 41b60a4

File tree

3 files changed

+146
-1
lines changed

3 files changed

+146
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Cms\Model\Plugin;
9+
10+
use Magento\Catalog\Model\Product as CatalogProduct;
11+
use Magento\Cms\Model\Page;
12+
13+
/**
14+
* Cleaning no-route page cache for the product details page after enabling product that is not assigned to a category
15+
*/
16+
class Product
17+
{
18+
/**
19+
* @var Page
20+
*/
21+
private $page;
22+
23+
/**
24+
* @param Page $page
25+
*/
26+
public function __construct(Page $page)
27+
{
28+
$this->page = $page;
29+
}
30+
31+
/**
32+
* After get identities
33+
*
34+
* @param CatalogProduct $product
35+
* @param array $identities
36+
* @return array
37+
*/
38+
public function afterGetIdentities(CatalogProduct $product, array $identities)
39+
{
40+
if ($product->getOrigData('status') > $product->getData('status')) {
41+
if (empty($product->getCategoryIds())) {
42+
$noRoutePage = $this->page->load(Page::NOROUTE_PAGE_ID);
43+
$noRoutePageId = $noRoutePage->getId();
44+
$identities[] = Page::CACHE_TAG . '_' . $noRoutePageId;
45+
}
46+
}
47+
48+
return array_unique($identities);
49+
}
50+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Cms\Test\Unit\Model\Plugin;
9+
10+
use Magento\Catalog\Model\Product as CatalogProduct;
11+
use Magento\Cms\Model\Page;
12+
use Magento\Cms\Model\Plugin\Product;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Product plugin test
19+
*/
20+
class ProductTest extends TestCase
21+
{
22+
/**
23+
* @var Product
24+
*/
25+
private $plugin;
26+
27+
/**
28+
* @var MockObject|CatalogProduct
29+
*/
30+
private $product;
31+
32+
/**
33+
* @var MockObject|Page
34+
*/
35+
private $page;
36+
37+
/**
38+
* @inheritdoc
39+
*/
40+
protected function setUp()
41+
{
42+
$objectManager = new ObjectManager($this);
43+
44+
$this->product = $this->getMockBuilder(CatalogProduct::class)
45+
->disableOriginalConstructor()
46+
->setMethods(['getEntityId', 'getOrigData', 'getData', 'getCategoryIds'])
47+
->getMock();
48+
49+
$this->page = $this->getMockBuilder(Page::class)
50+
->disableOriginalConstructor()
51+
->setMethods(['getId', 'load'])
52+
->getMock();
53+
54+
$this->plugin = $objectManager->getObject(
55+
Product::class,
56+
[
57+
'page' => $this->page
58+
]
59+
);
60+
}
61+
62+
public function testAfterGetIdentities()
63+
{
64+
$baseIdentities = [
65+
'SomeCacheId',
66+
'AnotherCacheId',
67+
];
68+
$id = 12345;
69+
$pageId = 1;
70+
$expectedIdentities = [
71+
'SomeCacheId',
72+
'AnotherCacheId',
73+
Page::CACHE_TAG . '_' . $pageId,
74+
];
75+
76+
$this->product->method('getEntityId')
77+
->willReturn($id);
78+
$this->product->method('getOrigData')
79+
->with('status')
80+
->willReturn(2);
81+
$this->product->method('getData')
82+
->with('status')
83+
->willReturn(1);
84+
$this->page->method('getId')
85+
->willReturn(1);
86+
$this->page->method('load')
87+
->willReturnSelf();
88+
89+
$identities = $this->plugin->afterGetIdentities($this->product, $baseIdentities);
90+
91+
$this->assertEquals($expectedIdentities, $identities);
92+
}
93+
}

app/code/Magento/Cms/etc/di.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,7 @@
233233
</argument>
234234
</arguments>
235235
</type>
236+
<type name="Magento\Catalog\Model\Product">
237+
<plugin name="cms" type="Magento\Cms\Model\Plugin\Product" sortOrder="100"/>
238+
</type>
236239
</config>
237-

0 commit comments

Comments
 (0)