Skip to content

Commit 2a08259

Browse files
committed
MAGETWO-33240: FPC is permanently invalidated by cron
- added unit test
1 parent 19585ea commit 2a08259

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\PageCache\Model\Observer;
8+
9+
class InvalidateCacheIfChangedTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/** @var \Magento\PageCache\Model\Observer\InvalidateCacheIfChanged */
12+
protected $model;
13+
14+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\PageCache\Model\Config */
15+
protected $configMock;
16+
17+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Cache\TypeListInterface */
18+
protected $typeListMock;
19+
20+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Event\Observer */
21+
protected $observerMock;
22+
23+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Object\IdentityInterface */
24+
protected $objectMock;
25+
26+
/**
27+
* Set up all mocks and data for test
28+
*/
29+
public function setUp()
30+
{
31+
$this->configMock = $this->getMock(
32+
'Magento\PageCache\Model\Config',
33+
['getType', 'isEnabled'],
34+
[],
35+
'',
36+
false
37+
);
38+
$this->typeListMock = $this->getMock('Magento\Framework\App\Cache\TypeList', [], [], '', false);
39+
40+
$this->model = new \Magento\PageCache\Model\Observer\InvalidateCacheIfChanged(
41+
$this->configMock,
42+
$this->typeListMock
43+
);
44+
45+
$this->observerMock = $this->getMock('Magento\Framework\Event\Observer', [], [], '', false);
46+
$eventMock = $this->getMock('Magento\Framework\Event', ['getObject'], [], '', false);
47+
$this->objectMock = $this->getMockForAbstractClass('Magento\Framework\Object\IdentityInterface', [], '', false);
48+
$eventMock->expects($this->any())->method('getObject')->willReturn($this->objectMock);
49+
$this->observerMock->expects($this->any())->method('getEvent')->willReturn($eventMock);
50+
}
51+
52+
/**
53+
* @dataProvider invalidateCacheDataProvider
54+
* @param bool $cacheState
55+
*/
56+
public function testExecuteChanged($cacheState)
57+
{
58+
$this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState));
59+
60+
if ($cacheState) {
61+
$this->typeListMock->expects($this->once())->method('invalidate')->with($this->equalTo('full_page'));
62+
$this->objectMock->expects($this->once())->method('getIdentities')->will($this->returnValue(['tag_1']));
63+
}
64+
$this->model->execute($this->observerMock);
65+
}
66+
67+
/**
68+
* @dataProvider invalidateCacheDataProvider
69+
* @param bool $cacheState
70+
*/
71+
public function testExecuteNoChanged($cacheState)
72+
{
73+
$this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState));
74+
$this->typeListMock->expects($this->never())->method('invalidate');
75+
76+
if ($cacheState) {
77+
$this->objectMock->expects($this->once())->method('getIdentities')->will($this->returnValue([]));
78+
}
79+
$this->model->execute($this->observerMock);
80+
}
81+
82+
public function invalidateCacheDataProvider()
83+
{
84+
return [[true], [false]];
85+
}
86+
}

0 commit comments

Comments
 (0)