Skip to content

Commit

Permalink
Merge pull request #131 from magento-extensibility/MAGETWO-44798-disa…
Browse files Browse the repository at this point in the history
…ble-varnish

[Extensibility] Bugfix
  • Loading branch information
He, Joan(johe) committed Nov 5, 2015
2 parents ea2c7c8 + b68d092 commit 869f987
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function execute()
}
$this->_validateTypes($types);
foreach ($types as $code) {
$this->_cacheTypeList->cleanType($code);
if ($this->_cacheState->isEnabled($code)) {
$this->_cacheState->setEnabled($code, false);
$updatedTypes++;
}
$this->_cacheTypeList->cleanType($code);
}
if ($updatedTypes > 0) {
$this->_cacheState->persist();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public function execute()
$this->_validateTypes($types);
foreach ($types as $type) {
$this->_cacheTypeList->cleanType($type);
$this->_eventManager->dispatch('adminhtml_cache_refresh_type', ['type' => $type]);
$updatedTypes++;
}
if ($updatedTypes > 0) {
Expand Down
26 changes: 24 additions & 2 deletions app/code/Magento/PageCache/Model/Cache/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,33 @@ class Type extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
*/
const CACHE_TAG = 'FPC';

/**
* @var \Magento\Framework\Event\ManagerInterface
*/
private $eventManager;

/**
* @param \Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool
* @param \Magento\Framework\Event\ManagerInterface $eventManager
*/
public function __construct(\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool)
{
public function __construct(
\Magento\Framework\App\Cache\Type\FrontendPool $cacheFrontendPool,
\Magento\Framework\Event\ManagerInterface $eventManager
) {
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
$this->eventManager = $eventManager;
}

/**
* {@inheritdoc}
*
* @param string $mode
* @param array $tags
* @return bool
*/
public function clean($mode = \Zend_Cache::CLEANING_MODE_ALL, array $tags = [])
{
$this->eventManager->dispatch('adminhtml_cache_refresh_type');
return parent::clean($mode, $tags);
}
}
51 changes: 51 additions & 0 deletions app/code/Magento/PageCache/Test/Unit/Model/Cache/TypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\PageCache\Test\Unit\Model\Cache;

class TypeTest extends \PHPUnit_Framework_TestCase
{
/** @var \Magento\PageCache\Model\Cache\Type */
protected $model;

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

/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Cache\Type\FrontendPool */
protected $cacheFrontendPoolMock;

public function setUp()
{
$this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->cacheFrontendPoolMock = $this->getMockBuilder('Magento\Framework\App\Cache\Type\FrontendPool')
->disableOriginalConstructor()
->getMock();
$cacheFrontend = $this->getMockBuilder('Magento\Framework\Cache\FrontendInterface')
->disableOriginalConstructor()
->getMock();
$this->cacheFrontendPoolMock->expects($this->once())
->method('get')
->willReturn($cacheFrontend);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->model = $objectManager->getObject(
'Magento\PageCache\Model\Cache\Type',
[
'eventManager' => $this->eventManagerMock,
'cacheFrontendPool' => $this->cacheFrontendPoolMock,
]
);
}

public function testClean()
{
$this->eventManagerMock->expects($this->once())
->method('dispatch')
->with('adminhtml_cache_refresh_type');

$this->model->clean();
}
}
2 changes: 1 addition & 1 deletion setup/src/Magento/Setup/Model/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,8 @@ public function uninstall()
{
$this->log->log('Starting Magento uninstallation:');

$this->cleanupDb();
$this->cleanCaches();
$this->cleanupDb();

$this->log->log('File system cleanup:');
$messages = $this->cleanupFiles->clearAllFiles();
Expand Down
6 changes: 3 additions & 3 deletions setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function testUninstall()
]));
$this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:');
$this->logger
->expects($this->at(1))
->expects($this->at(2))
->method('log')
->with('No database connection defined - skipping database cleanup');
$cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
Expand All @@ -400,7 +400,7 @@ public function testUninstall()
->method('get')
->with('Magento\Framework\App\Cache\Manager')
->willReturn($cacheManager);
$this->logger->expects($this->at(2))->method('log')->with('Cache cleared successfully');
$this->logger->expects($this->at(1))->method('log')->with('Cache cleared successfully');
$this->logger->expects($this->at(3))->method('log')->with('File system cleanup:');
$this->logger
->expects($this->at(4))
Expand Down Expand Up @@ -494,7 +494,7 @@ private function prepareForUpdateModulesTests()

/**
* Mocking autoload function
*
*
* @returns array
*/
function spl_autoload_functions()
Expand Down

0 comments on commit 869f987

Please sign in to comment.