Skip to content

Commit

Permalink
MAGETWO-43857: [github] cache types don't properly invalidate all the…
Browse files Browse the repository at this point in the history
… time #1844
  • Loading branch information
Joan He committed Oct 26, 2015
1 parent 503ab0b commit 8db40e1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
22 changes: 17 additions & 5 deletions app/code/Magento/Theme/Model/Design/Backend/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Theme extends Value
*/
protected $_design = null;

/**
* Path to config node with list of caches
*
* @var string
*/
const XML_PATH_INVALID_CACHES = 'design/invalid_caches';

/**
* Initialize dependencies
*
Expand Down Expand Up @@ -59,17 +66,22 @@ public function beforeSave()
/**
* {@inheritdoc}
*
* {@inheritdoc}. In addition, it cleans all Magento cache
* {@inheritdoc}. In addition, it sets status 'invalidate' for blocks and other output caches
*
* @return $this
*/
public function afterSave()
{
parent::afterSave();
$types = array_keys(
$this->_config->getValue(
self::XML_PATH_INVALID_CACHES,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
);
if ($this->isValueChanged()) {
$this->_cacheManager->clean();
$this->_eventManager->dispatch('adminhtml_cache_flush_system');
$this->cacheTypeList->invalidate($types);
}
return $this;

return parent::afterSave();
}
}
63 changes: 26 additions & 37 deletions app/code/Magento/Theme/Test/Unit/Model/Design/Backend/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
protected $model;

/**
* @var \Magento\Framework\Model\Context
* @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject
*/
protected $context;
protected $contextMock;

/**
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
Expand All @@ -32,50 +32,30 @@ class ThemeTest extends \PHPUnit_Framework_TestCase
*/
protected $cacheTypeListMock;

/**
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $eventManagerMock;

/**
* @var \Magento\Framework\App\CacheInterface | \PHPUnit_Framework_MockObject_MockObject
*/
protected $cacheManagerMock;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $configMock;

protected function setUp()
{
$objectManager = new ObjectManager($this);
$this->cacheManagerMock = $this->getMockBuilder('Magento\Framework\App\CacheInterface')
$this->contextMock = $this->getMockBuilder('Magento\Framework\Model\Context')
->disableOriginalConstructor()
->getMock();
$this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->context = $objectManager->getObject(
'Magento\Framework\Model\Context',
[
'cacheManager' => $this->cacheManagerMock,
'eventDispatcher' => $this->eventManagerMock,
]
);

$this->designMock = $this->getMockBuilder('Magento\Framework\View\DesignInterface')->getMock();
$this->cacheTypeListMock = $this->getMockBuilder('Magento\Framework\App\Cache\TypeListInterface')
->disableOriginalConstructor()
->getMock();
$this->contextMock->expects($this->once())
->method('getEventDispatcher')
->willReturn($this->getMockBuilder('Magento\Framework\Event\ManagerInterface')->getMock());
$this->configMock = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')->getMock();


$this->model = $objectManager->getObject(
$this->model = (new ObjectManager($this))->getObject(
'Magento\Theme\Model\Design\Backend\Theme',
[
'design' => $this->designMock,
'context' => $this->context,
'context' => $this->contextMock,
'cacheTypeList' => $this->cacheTypeListMock,
'config' => $this->configMock,
]
Expand Down Expand Up @@ -106,16 +86,25 @@ public function testAfterSave($callNumber, $oldValue)
{
$this->cacheTypeListMock->expects($this->exactly($callNumber))
->method('invalidate');
$this->cacheManagerMock->expects($this->exactly($callNumber))
->method('clean');
$this->configMock->expects($this->any())
->method('getValue')
->willReturn($oldValue);
if ($callNumber) {
$this->eventManagerMock->expects($this->at(3))
->method('dispatch')
->with('adminhtml_cache_flush_system');
}
->willReturnMap(
[
[
Theme::XML_PATH_INVALID_CACHES,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
null,
['block_html' => 1, 'layout' => 1, 'translate' => 1]
],
[
null,
\Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
null,
$oldValue
],

]
);
$this->model->setValue('some_value');
$this->assertInstanceOf(get_class($this->model), $this->model->afterSave());
}
Expand All @@ -124,7 +113,7 @@ public function afterSaveDataProvider()
{
return [
[0, 'some_value'],
[1, 'other_value'],
[2, 'other_value'],
];
}
}
5 changes: 5 additions & 0 deletions app/code/Magento/Theme/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<design>
<invalid_caches>
<block_html />
<layout />
<translate />
</invalid_caches>
<head translate="default_description">
<default_title>Magento Commerce</default_title>
<default_description>Default Description</default_description>
Expand Down

0 comments on commit 8db40e1

Please sign in to comment.