|
6 | 6 | namespace Magento\PageCache\Test\Unit\App;
|
7 | 7 |
|
8 | 8 | use Magento\PageCache\Model\Config;
|
| 9 | +use Magento\Store\Model\Store; |
| 10 | +use Magento\Store\Model\StoreManager; |
9 | 11 |
|
10 | 12 | /**
|
11 | 13 | * Class CacheIdentifierPluginTest
|
@@ -56,7 +58,7 @@ protected function setUp()
|
56 | 58 | }
|
57 | 59 |
|
58 | 60 | /**
|
59 |
| - * Test of adding design exceptions to the kay of cache hash |
| 61 | + * Test of adding design exceptions + run code to the key of cache hash |
60 | 62 | *
|
61 | 63 | * @param string $cacheType
|
62 | 64 | * @param bool $isPageCacheEnabled
|
@@ -95,7 +97,68 @@ public function afterGetValueDataProvider()
|
95 | 97 | 'Built-in + PageCache enabled' => [Config::BUILT_IN, true, null, false, false],
|
96 | 98 | 'Built-in, PageCache enabled, no user-agent exceptions' =>
|
97 | 99 | [Config::BUILT_IN, true, 'aa123aa', false, 'aa123aa'],
|
98 |
| - 'Built-in, PageCache enabled, with design exception' => [Config::BUILT_IN, true, 'aa123aa', '7', '7aa123aa'] |
| 100 | + 'Built-in, PageCache enabled, with design exception' => [Config::BUILT_IN, true, 'aa123aa', '7', 'DESIGN=7|aa123aa'] |
99 | 101 | ];
|
100 | 102 | }
|
| 103 | + |
| 104 | + /** |
| 105 | + * Tests that different stores cause different identifiers |
| 106 | + * (property based testing approach) |
| 107 | + */ |
| 108 | + public function testAfterGetValueRunParamsCauseDifferentIdentifiers() |
| 109 | + { |
| 110 | + $identifierMock = $this->createMock(\Magento\Framework\App\PageCache\Identifier::class); |
| 111 | + |
| 112 | + $this->pageCacheConfigMock->expects($this->any()) |
| 113 | + ->method('getType') |
| 114 | + ->willReturn(Config::BUILT_IN); |
| 115 | + $this->pageCacheConfigMock->expects($this->any()) |
| 116 | + ->method('isEnabled') |
| 117 | + ->willReturn(true); |
| 118 | + |
| 119 | + $defaultRequestMock = clone $this->requestMock; |
| 120 | + $defaultRequestMock->expects($this->any()) |
| 121 | + ->method('getServerValue') |
| 122 | + ->willReturnCallback(function ($param) { |
| 123 | + if ($param == StoreManager::PARAM_RUN_TYPE) { |
| 124 | + return 'store'; |
| 125 | + } |
| 126 | + if ($param == StoreManager::PARAM_RUN_CODE) { |
| 127 | + return 'default'; |
| 128 | + } |
| 129 | + }); |
| 130 | + |
| 131 | + $nullSha1 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; |
| 132 | + |
| 133 | + $defaultPlugin = new \Magento\PageCache\Model\App\CacheIdentifierPlugin( |
| 134 | + $this->designExceptionsMock, |
| 135 | + $defaultRequestMock, |
| 136 | + $this->pageCacheConfigMock |
| 137 | + ); |
| 138 | + |
| 139 | + $defaultStoreResult = $defaultPlugin->afterGetValue($identifierMock, $nullSha1); |
| 140 | + |
| 141 | + $otherRequestMock = clone $this->requestMock; |
| 142 | + $otherRequestMock->expects($this->any()) |
| 143 | + ->method('getServerValue') |
| 144 | + ->willReturnCallback(function ($param) { |
| 145 | + if ($param == StoreManager::PARAM_RUN_TYPE) { |
| 146 | + return 'store'; |
| 147 | + } |
| 148 | + if ($param == StoreManager::PARAM_RUN_CODE) { |
| 149 | + return 'klingon'; |
| 150 | + } |
| 151 | + }); |
| 152 | + |
| 153 | + $otherPlugin = new \Magento\PageCache\Model\App\CacheIdentifierPlugin( |
| 154 | + $this->designExceptionsMock, |
| 155 | + $otherRequestMock, |
| 156 | + $this->pageCacheConfigMock |
| 157 | + ); |
| 158 | + $otherStoreResult = $otherPlugin->afterGetValue($identifierMock, $nullSha1); |
| 159 | + |
| 160 | + $this->assertNotEquals($nullSha1, $defaultStoreResult); |
| 161 | + $this->assertNotEquals($nullSha1, $otherStoreResult); |
| 162 | + $this->assertNotEquals($defaultStoreResult, $otherStoreResult); |
| 163 | + } |
101 | 164 | }
|
0 commit comments