Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CacheIdentifierPluginTest.php
Go to the documentation of this file.
1 <?php
7 
9 
14 class CacheIdentifierPluginTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $plugin;
20 
25 
29  protected $requestMock;
30 
35 
39  protected function setUp()
40  {
41  $this->designExceptionsMock = $this->createPartialMock(
42  \Magento\Framework\View\DesignExceptions::class,
43  ['getThemeByRequest']
44  );
45  $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
46  $this->pageCacheConfigMock = $this->createPartialMock(
47  \Magento\PageCache\Model\Config::class,
48  ['getType', 'isEnabled']
49  );
50 
51  $this->plugin = new \Magento\PageCache\Model\App\CacheIdentifierPlugin(
52  $this->designExceptionsMock,
53  $this->requestMock,
54  $this->pageCacheConfigMock
55  );
56  }
57 
68  public function testAfterGetValue($cacheType, $isPageCacheEnabled, $result, $uaException, $expected)
69  {
70  $identifierMock = $this->createMock(\Magento\Framework\App\PageCache\Identifier::class);
71 
72  $this->pageCacheConfigMock->expects($this->once())
73  ->method('getType')
74  ->will($this->returnValue($cacheType));
75  $this->pageCacheConfigMock->expects($this->any())
76  ->method('isEnabled')
77  ->will($this->returnValue($isPageCacheEnabled));
78  $this->designExceptionsMock->expects($this->any())
79  ->method('getThemeByRequest')
80  ->will($this->returnValue($uaException));
81 
82  $this->assertEquals($expected, $this->plugin->afterGetValue($identifierMock, $result));
83  }
84 
90  public function afterGetValueDataProvider()
91  {
92  return [
93  'Varnish + PageCache enabled' => [Config::VARNISH, true, null, false, false],
94  'Built-in + PageCache disabled' => [Config::BUILT_IN, false, null, false, false],
95  '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']
99  ];
100  }
101 }
testAfterGetValue($cacheType, $isPageCacheEnabled, $result, $uaException, $expected)