DepersonalizeCheckerTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\PageCache\Test\Unit\Model;
  7. use Magento\PageCache\Model\DepersonalizeChecker;
  8. class DepersonalizeCheckerTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
  12. */
  13. private $requestMock;
  14. /**
  15. * @var \Magento\Framework\Module\Manager|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $moduleManagerMock;
  18. /**
  19. * @var \Magento\PageCache\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $cacheConfigMock;
  22. public function setup()
  23. {
  24. $this->requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
  25. $this->moduleManagerMock = $this->createMock(\Magento\Framework\Module\Manager::class);
  26. $this->cacheConfigMock = $this->createMock(\Magento\PageCache\Model\Config::class);
  27. }
  28. /**
  29. * @param array $requestResult
  30. * @param bool $moduleManagerResult
  31. * @param bool $cacheConfigResult
  32. * @param bool $layoutResult
  33. * @param bool $can Depersonalize
  34. * @dataProvider checkIfDepersonalizeDataProvider
  35. */
  36. public function testCheckIfDepersonalize(
  37. array $requestResult,
  38. $moduleManagerResult,
  39. $cacheConfigResult,
  40. $layoutResult,
  41. $canDepersonalize
  42. ) {
  43. $this->requestMock->expects($this->any())->method('isAjax')->willReturn($requestResult['ajax']);
  44. $this->requestMock->expects($this->any())->method('isGet')->willReturn($requestResult['get']);
  45. $this->requestMock->expects($this->any())->method('isHead')->willReturn($requestResult['head']);
  46. $this->moduleManagerMock
  47. ->expects($this->any())
  48. ->method('isEnabled')
  49. ->with('Magento_PageCache')
  50. ->willReturn($moduleManagerResult);
  51. $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($cacheConfigResult);
  52. $layoutMock = $this->getMockForAbstractClass(\Magento\Framework\View\LayoutInterface::class, [], '', false);
  53. $layoutMock->expects($this->any())->method('isCacheable')->willReturn($layoutResult);
  54. $object = new DepersonalizeChecker($this->requestMock, $this->moduleManagerMock, $this->cacheConfigMock);
  55. $this->assertEquals($canDepersonalize, $object->checkIfDepersonalize($layoutMock));
  56. }
  57. /**
  58. * return array
  59. */
  60. public function checkIfDepersonalizeDataProvider()
  61. {
  62. return [
  63. [['ajax' => false, 'get' => true, 'head' => false], true, true, true, true],
  64. [['ajax' => false, 'get' => false, 'head' => true], true, true, true, true],
  65. [['ajax' => false, 'get' => false, 'head' => false], true, true, true, false],
  66. [['ajax' => true, 'get' => true, 'head' => false], true, true, true, false],
  67. [['ajax' => false, 'get' => true, 'head' => false], false, true, true, false],
  68. [['ajax' => false, 'get' => true, 'head' => false], true, false, true, false],
  69. [['ajax' => false, 'get' => true, 'head' => false], true, true, false, false],
  70. ];
  71. }
  72. }