InvalidateCacheTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\PageCache\Test\Unit\Observer;
  8. class InvalidateCacheTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\PageCache\Observer\InvalidateCache */
  11. protected $_model;
  12. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\PageCache\Model\Config */
  13. protected $_configMock;
  14. /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Cache\TypeListInterface */
  15. protected $_typeListMock;
  16. /**
  17. * @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject|
  18. */
  19. protected $observerMock;
  20. /**
  21. * Set up all mocks and data for test
  22. */
  23. protected function setUp()
  24. {
  25. $this->_configMock = $this->createPartialMock(\Magento\PageCache\Model\Config::class, ['getType', 'isEnabled']);
  26. $this->_typeListMock = $this->createMock(\Magento\Framework\App\Cache\TypeList::class);
  27. $this->observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
  28. $this->_model = new \Magento\PageCache\Observer\InvalidateCache(
  29. $this->_configMock,
  30. $this->_typeListMock
  31. );
  32. }
  33. /**
  34. * @dataProvider invalidateCacheDataProvider
  35. * @param bool $cacheState
  36. */
  37. public function testExecute($cacheState)
  38. {
  39. $this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState));
  40. if ($cacheState) {
  41. $this->_typeListMock->expects($this->once())->method('invalidate')->with($this->equalTo('full_page'));
  42. }
  43. $this->_model->execute($this->observerMock);
  44. }
  45. /**
  46. * @return array
  47. */
  48. public function invalidateCacheDataProvider()
  49. {
  50. return [[true], [false]];
  51. }
  52. }