CacheIdentifierPluginTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\PageCache\Test\Unit\App;
  7. use Magento\PageCache\Model\Config;
  8. /**
  9. * Class CacheIdentifierPluginTest
  10. * Test for plugin to identifier to work with design exceptions
  11. */
  12. class CacheIdentifierPluginTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\PageCache\Model\App\CacheIdentifierPlugin
  16. */
  17. protected $plugin;
  18. /**
  19. * @var \Magento\Framework\View\DesignExceptions
  20. */
  21. protected $designExceptionsMock;
  22. /**
  23. * @var \Magento\Framework\App\Request\Http
  24. */
  25. protected $requestMock;
  26. /**
  27. * @var Config
  28. */
  29. protected $pageCacheConfigMock;
  30. /**
  31. * Set up data for test
  32. */
  33. protected function setUp()
  34. {
  35. $this->designExceptionsMock = $this->createPartialMock(
  36. \Magento\Framework\View\DesignExceptions::class,
  37. ['getThemeByRequest']
  38. );
  39. $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
  40. $this->pageCacheConfigMock = $this->createPartialMock(
  41. \Magento\PageCache\Model\Config::class,
  42. ['getType', 'isEnabled']
  43. );
  44. $this->plugin = new \Magento\PageCache\Model\App\CacheIdentifierPlugin(
  45. $this->designExceptionsMock,
  46. $this->requestMock,
  47. $this->pageCacheConfigMock
  48. );
  49. }
  50. /**
  51. * Test of adding design exceptions to the kay of cache hash
  52. *
  53. * @param string $cacheType
  54. * @param bool $isPageCacheEnabled
  55. * @param string|false $result
  56. * @param string $uaException
  57. * @param string $expected
  58. * @dataProvider afterGetValueDataProvider
  59. */
  60. public function testAfterGetValue($cacheType, $isPageCacheEnabled, $result, $uaException, $expected)
  61. {
  62. $identifierMock = $this->createMock(\Magento\Framework\App\PageCache\Identifier::class);
  63. $this->pageCacheConfigMock->expects($this->once())
  64. ->method('getType')
  65. ->will($this->returnValue($cacheType));
  66. $this->pageCacheConfigMock->expects($this->any())
  67. ->method('isEnabled')
  68. ->will($this->returnValue($isPageCacheEnabled));
  69. $this->designExceptionsMock->expects($this->any())
  70. ->method('getThemeByRequest')
  71. ->will($this->returnValue($uaException));
  72. $this->assertEquals($expected, $this->plugin->afterGetValue($identifierMock, $result));
  73. }
  74. /**
  75. * Data provider for testAfterGetValue
  76. *
  77. * @return array
  78. */
  79. public function afterGetValueDataProvider()
  80. {
  81. return [
  82. 'Varnish + PageCache enabled' => [Config::VARNISH, true, null, false, false],
  83. 'Built-in + PageCache disabled' => [Config::BUILT_IN, false, null, false, false],
  84. 'Built-in + PageCache enabled' => [Config::BUILT_IN, true, null, false, false],
  85. 'Built-in, PageCache enabled, no user-agent exceptions' =>
  86. [Config::BUILT_IN, true, 'aa123aa', false, 'aa123aa'],
  87. 'Built-in, PageCache enabled, with design exception' => [Config::BUILT_IN, true, 'aa123aa', '7', '7aa123aa']
  88. ];
  89. }
  90. }