Skip to content

Commit 614d525

Browse files
committed
Merge branch 'AC-13719' into spartans_pr_05062025
2 parents bf79b4a + bfa4d40 commit 614d525

File tree

3 files changed

+209
-2
lines changed

3 files changed

+209
-2
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All rights reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageCache\Model\App;
9+
10+
use Magento\Store\Model\StoreManager;
11+
12+
/**
13+
* Class CacheIdentifierForSavePlugin
14+
*
15+
* Should add design exceptions to identifier for built-in cache when saving
16+
*/
17+
class CacheIdentifierForSavePlugin
18+
{
19+
/**
20+
* @var \Magento\Framework\View\DesignExceptions
21+
*/
22+
private $designExceptions;
23+
24+
/**
25+
* @var \Magento\Framework\App\RequestInterface
26+
*/
27+
private $request;
28+
29+
/**
30+
* @var \Magento\PageCache\Model\Config
31+
*/
32+
private $config;
33+
34+
/**
35+
* @param \Magento\Framework\View\DesignExceptions $designExceptions
36+
* @param \Magento\Framework\App\RequestInterface $request
37+
* @param \Magento\PageCache\Model\Config $config
38+
*/
39+
public function __construct(
40+
\Magento\Framework\View\DesignExceptions $designExceptions,
41+
\Magento\Framework\App\RequestInterface $request,
42+
\Magento\PageCache\Model\Config $config
43+
) {
44+
$this->designExceptions = $designExceptions;
45+
$this->request = $request;
46+
$this->config = $config;
47+
}
48+
49+
/**
50+
* Adds a theme key to identifier for a built-in cache if user-agent theme rule is actual
51+
*
52+
* @param \Magento\PageCache\Model\App\Request\Http\IdentifierForSave $identifier
53+
* @param string $result
54+
* @return string
55+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
56+
*/
57+
public function afterGetValue(\Magento\PageCache\Model\App\Request\Http\IdentifierForSave $identifier, $result)
58+
{
59+
if ($this->config->getType() === \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) {
60+
$identifierPrefix = '';
61+
62+
$ruleDesignException = $this->designExceptions->getThemeByRequest($this->request);
63+
if ($ruleDesignException !== false) {
64+
$identifierPrefix .= 'DESIGN' . '=' . $ruleDesignException . '|';
65+
}
66+
67+
if ($runType = $this->request->getServerValue(StoreManager::PARAM_RUN_TYPE)) {
68+
$identifierPrefix .= StoreManager::PARAM_RUN_TYPE . '=' . $runType . '|';
69+
}
70+
71+
if ($runCode = $this->request->getServerValue(StoreManager::PARAM_RUN_CODE)) {
72+
$identifierPrefix .= StoreManager::PARAM_RUN_CODE . '=' . $runCode . '|';
73+
}
74+
75+
return $identifierPrefix . $result;
76+
}
77+
return $result;
78+
}
79+
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2015 Adobe
5+
* All rights reserved.
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Framework\App\PageCache\Identifier">
10+
<plugin name="core-app-area-design-exception-plugin" type="Magento\PageCache\Model\App\CacheIdentifierPlugin" sortOrder="10"/>
11+
</type>
12+
<type name="Magento\PageCache\Model\App\Request\Http\IdentifierForSave">
13+
<plugin name="core-app-area-design-exception-plugin-for-save" type="Magento\PageCache\Model\App\CacheIdentifierForSavePlugin" sortOrder="10"/>
14+
</type>
915
<type name="Magento\Framework\App\PageCache\Cache">
1016
<plugin name="fpc-type-plugin" type="Magento\PageCache\Model\App\PageCachePlugin"/>
1117
</type>
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All rights reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageCache\Model\App;
9+
10+
use Magento\Framework\App\Cache\StateInterface;
11+
use Magento\Framework\App\PageCache\Identifier;
12+
use Magento\Framework\App\Request\Http;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\PageCache\Model\App\Request\Http\IdentifierForSave;
15+
use Magento\PageCache\Model\Cache\Type;
16+
use Magento\Store\Model\StoreManager;
17+
use Magento\Store\Test\Fixture\Group as StoreGroupFixture;
18+
use Magento\Store\Test\Fixture\Store as StoreFixture;
19+
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
20+
use Magento\TestFramework\Fixture\Config as ConfigFixture;
21+
use Magento\TestFramework\Fixture\DataFixture;
22+
use Magento\TestFramework\Fixture\DataFixtureStorage;
23+
use Magento\TestFramework\Fixture\DataFixtureStorageManager;
24+
use Magento\TestFramework\Fixture\DbIsolation;
25+
use Magento\TestFramework\Helper\Bootstrap;
26+
use PHPUnit\Framework\TestCase;
27+
28+
/**
29+
* Integration test for \Magento\PageCache\Model\App\CacheIdentifierPlugin
30+
*/
31+
class CacheIdentifierPluginTest extends TestCase
32+
{
33+
/**
34+
* @var ObjectManagerInterface
35+
*/
36+
private $objectManager;
37+
38+
/**
39+
* @var Http
40+
*/
41+
private $request;
42+
43+
/**
44+
* @var Identifier
45+
*/
46+
private $identifier;
47+
48+
/**
49+
* @var IdentifierForSave
50+
*/
51+
private $identifierForSave;
52+
53+
/**
54+
* @var DataFixtureStorage
55+
*/
56+
private $fixtures;
57+
58+
/**
59+
* @var StateInterface
60+
*/
61+
private $cacheState;
62+
63+
/**
64+
* @var bool
65+
*/
66+
private $originalCacheState;
67+
68+
protected function setUp(): void
69+
{
70+
$this->objectManager = Bootstrap::getObjectManager();
71+
$this->request = $this->objectManager->get(Http::class);
72+
$this->identifier = $this->objectManager->get(Identifier::class);
73+
$this->identifierForSave = $this->objectManager->get(IdentifierForSave::class);
74+
$this->fixtures = $this->objectManager->get(DataFixtureStorageManager::class)->getStorage();
75+
$this->cacheState = $this->objectManager->get(StateInterface::class);
76+
77+
// Store original cache state
78+
$this->originalCacheState = $this->cacheState->isEnabled(Type::TYPE_IDENTIFIER);
79+
80+
// Enable the cache type
81+
$this->cacheState->setEnabled(Type::TYPE_IDENTIFIER, true);
82+
}
83+
84+
protected function tearDown(): void
85+
{
86+
// Revert cache state to original
87+
if (isset($this->cacheState) && isset($this->originalCacheState)) {
88+
$this->cacheState->setEnabled(Type::TYPE_IDENTIFIER, $this->originalCacheState);
89+
}
90+
}
91+
92+
/**
93+
* Test that cache identifier includes run type and run code
94+
*/
95+
#[
96+
DbIsolation(false),
97+
ConfigFixture('system/full_page_cache/caching_application', '1', 'store'),
98+
ConfigFixture('system/full_page_cache/enabled', '1', 'store'),
99+
DataFixture(WebsiteFixture::class, as: 'website'),
100+
DataFixture(StoreGroupFixture::class, ['website_id' => '$website.id$'], 'store_group'),
101+
DataFixture(StoreFixture::class, ['store_group_id' => '$store_group.id$'], 'store')
102+
]
103+
public function testAfterGetValueWithRunTypeAndCode()
104+
{
105+
$storeCode = $this->fixtures->get('store')->getCode();
106+
$serverParams = [
107+
StoreManager::PARAM_RUN_TYPE => 'store',
108+
StoreManager::PARAM_RUN_CODE => $storeCode
109+
];
110+
$this->request->setServer(new \Laminas\Stdlib\Parameters($serverParams));
111+
112+
$result = $this->identifier->getValue();
113+
$this->assertNotEmpty($result);
114+
$this->assertStringContainsString('MAGE_RUN_TYPE=store', $result);
115+
$this->assertStringContainsString('MAGE_RUN_CODE=' . $storeCode, $result);
116+
117+
$resultForSave = $this->identifierForSave->getValue();
118+
$this->assertNotEmpty($resultForSave);
119+
$this->assertStringContainsString('MAGE_RUN_TYPE=store', $resultForSave);
120+
$this->assertStringContainsString('MAGE_RUN_CODE=' . $storeCode, $resultForSave);
121+
}
122+
}

0 commit comments

Comments
 (0)