|
6 | 6 | namespace Magento\PageCache\Test\Unit\App;
|
7 | 7 |
|
8 | 8 | use Magento\PageCache\Model\Config;
|
| 9 | +use Magento\Store\Model\StoreManager; |
9 | 10 |
|
10 | 11 | /**
|
11 | 12 | * Class CacheIdentifierPluginTest
|
| 13 | + * |
12 | 14 | * Test for plugin to identifier to work with design exceptions
|
13 | 15 | */
|
14 | 16 | class CacheIdentifierPluginTest extends \PHPUnit\Framework\TestCase
|
@@ -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
|
@@ -93,9 +95,83 @@ public function afterGetValueDataProvider()
|
93 | 95 | 'Varnish + PageCache enabled' => [Config::VARNISH, true, null, false, false],
|
94 | 96 | 'Built-in + PageCache disabled' => [Config::BUILT_IN, false, null, false, false],
|
95 | 97 | 'Built-in + PageCache enabled' => [Config::BUILT_IN, true, null, false, false],
|
96 |
| - 'Built-in, PageCache enabled, no user-agent exceptions' => |
97 |
| - [Config::BUILT_IN, true, 'aa123aa', false, 'aa123aa'], |
98 |
| - 'Built-in, PageCache enabled, with design exception' => [Config::BUILT_IN, true, 'aa123aa', '7', '7aa123aa'] |
| 98 | + 'Built-in, PageCache enabled, no user-agent exceptions' => [Config::BUILT_IN, |
| 99 | + true, |
| 100 | + 'aa123aa', |
| 101 | + false, |
| 102 | + 'aa123aa' |
| 103 | + ], |
| 104 | + 'Built-in, PageCache enabled, with design exception' => [Config::BUILT_IN, |
| 105 | + true, |
| 106 | + 'aa123aa', |
| 107 | + '7', |
| 108 | + 'DESIGN=7|aa123aa' |
| 109 | + ] |
99 | 110 | ];
|
100 | 111 | }
|
| 112 | + |
| 113 | + /** |
| 114 | + * Tests that different stores cause different identifiers |
| 115 | + * (property based testing approach) |
| 116 | + */ |
| 117 | + public function testAfterGetValueRunParamsCauseDifferentIdentifiers() |
| 118 | + { |
| 119 | + $identifierMock = $this->createMock(\Magento\Framework\App\PageCache\Identifier::class); |
| 120 | + |
| 121 | + $this->pageCacheConfigMock->expects($this->any()) |
| 122 | + ->method('getType') |
| 123 | + ->willReturn(Config::BUILT_IN); |
| 124 | + $this->pageCacheConfigMock->expects($this->any()) |
| 125 | + ->method('isEnabled') |
| 126 | + ->willReturn(true); |
| 127 | + |
| 128 | + $defaultRequestMock = clone $this->requestMock; |
| 129 | + $defaultRequestMock->expects($this->any()) |
| 130 | + ->method('getServerValue') |
| 131 | + ->willReturnCallback( |
| 132 | + function ($param) { |
| 133 | + if ($param == StoreManager::PARAM_RUN_TYPE) { |
| 134 | + return 'store'; |
| 135 | + } |
| 136 | + if ($param == StoreManager::PARAM_RUN_CODE) { |
| 137 | + return 'default'; |
| 138 | + } |
| 139 | + } |
| 140 | + ); |
| 141 | + |
| 142 | + $nullSha1 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'; |
| 143 | + |
| 144 | + $defaultPlugin = new \Magento\PageCache\Model\App\CacheIdentifierPlugin( |
| 145 | + $this->designExceptionsMock, |
| 146 | + $defaultRequestMock, |
| 147 | + $this->pageCacheConfigMock |
| 148 | + ); |
| 149 | + |
| 150 | + $defaultStoreResult = $defaultPlugin->afterGetValue($identifierMock, $nullSha1); |
| 151 | + |
| 152 | + $otherRequestMock = clone $this->requestMock; |
| 153 | + $otherRequestMock->expects($this->any()) |
| 154 | + ->method('getServerValue') |
| 155 | + ->willReturnCallback( |
| 156 | + function ($param) { |
| 157 | + if ($param == StoreManager::PARAM_RUN_TYPE) { |
| 158 | + return 'store'; |
| 159 | + } |
| 160 | + if ($param == StoreManager::PARAM_RUN_CODE) { |
| 161 | + return 'klingon'; |
| 162 | + } |
| 163 | + } |
| 164 | + ); |
| 165 | + |
| 166 | + $otherPlugin = new \Magento\PageCache\Model\App\CacheIdentifierPlugin( |
| 167 | + $this->designExceptionsMock, |
| 168 | + $otherRequestMock, |
| 169 | + $this->pageCacheConfigMock |
| 170 | + ); |
| 171 | + $otherStoreResult = $otherPlugin->afterGetValue($identifierMock, $nullSha1); |
| 172 | + |
| 173 | + $this->assertNotEquals($nullSha1, $defaultStoreResult); |
| 174 | + $this->assertNotEquals($nullSha1, $otherStoreResult); |
| 175 | + $this->assertNotEquals($defaultStoreResult, $otherStoreResult); |
| 176 | + } |
101 | 177 | }
|
0 commit comments