diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php index 5974798f74be4355cff4926d0bd4e65b48f583f9..56970004795e1b93758432657da8bf4db3e06af8 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php @@ -6,11 +6,28 @@ namespace Magento\Backend\Console\Command; +use Magento\Framework\Event\ManagerInterface as EventManagerInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Magento\Framework\App\Cache\Manager; abstract class AbstractCacheTypeManageCommand extends AbstractCacheManageCommand { + /** @var EventManagerInterface */ + protected $eventManager; + + /** + * @param Manager $cacheManager + * @param EventManagerInterface $eventManager + */ + public function __construct( + Manager $cacheManager, + EventManagerInterface $eventManager + ) { + $this->eventManager = $eventManager; + parent::__construct($cacheManager); + } + /** * Perform a cache management action on cache types * diff --git a/app/code/Magento/Backend/Console/Command/CacheCleanCommand.php b/app/code/Magento/Backend/Console/Command/CacheCleanCommand.php index ab57f0ff7b578611ee3a64402650aa07ba52219e..49aeb17839e2ae54fd39c86865c8b2e4e36b2941 100644 --- a/app/code/Magento/Backend/Console/Command/CacheCleanCommand.php +++ b/app/code/Magento/Backend/Console/Command/CacheCleanCommand.php @@ -29,6 +29,7 @@ class CacheCleanCommand extends AbstractCacheTypeManageCommand */ protected function performAction(array $cacheTypes) { + $this->eventManager->dispatch('adminhtml_cache_flush_system'); $this->cacheManager->clean($cacheTypes); } diff --git a/app/code/Magento/Backend/Console/Command/CacheFlushCommand.php b/app/code/Magento/Backend/Console/Command/CacheFlushCommand.php index c847204de9043e84ded25607e890273441ec0e4e..7572fb21cba6dc3e8fb6a7d785ed3d7bbf32e97d 100644 --- a/app/code/Magento/Backend/Console/Command/CacheFlushCommand.php +++ b/app/code/Magento/Backend/Console/Command/CacheFlushCommand.php @@ -29,6 +29,7 @@ class CacheFlushCommand extends AbstractCacheTypeManageCommand */ protected function performAction(array $cacheTypes) { + $this->eventManager->dispatch('adminhtml_cache_flush_all'); $this->cacheManager->flush($cacheTypes); } diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php index 33bce6388fb71d5a8765c86e2c078916858b1741..b7ecddf4d23610b94cee2519c597a907cb4effe5 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheCommandTest.php @@ -13,7 +13,7 @@ abstract class AbstractCacheCommandTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject */ - protected $cacheManager; + protected $cacheManagerMock; /** * @var AbstractCacheManageCommand @@ -22,7 +22,7 @@ abstract class AbstractCacheCommandTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); + $this->cacheManagerMock = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false); } /** diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php index 53ed624db47685ea3b72ed92b8b466dbeca363bb..97d1f57ad1c1f67eb2af82640bc3e81f679c9199 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/AbstractCacheManageCommandTest.php @@ -10,6 +10,20 @@ use Symfony\Component\Console\Tester\CommandTester; abstract class AbstractCacheManageCommandTest extends AbstractCacheCommandTest { + /** @var string */ + protected $cacheEventName; + + /** @var \Magento\Framework\Event\ManagerInterface | \PHPUnit_Framework_MockObject_MockObject */ + protected $eventManagerMock; + + public function setUp() + { + $this->eventManagerMock = $this->getMockBuilder('\Magento\Framework\Event\ManagerInterface') + ->disableOriginalConstructor() + ->getMock(); + parent::setUp(); + } + /** * @return array */ @@ -35,7 +49,7 @@ abstract class AbstractCacheManageCommandTest extends AbstractCacheCommandTest */ public function testExecuteInvalidCacheType() { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); + $this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); $param = ['types' => ['A', 'D']]; $commandTester = new CommandTester($this->command); $commandTester->execute($param); diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php index a51fa92c1addf7dfca4f654a6d5e72079cc9d3ca..fe812c1a93daa190f555e189f9fc95aa26471b05 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php @@ -13,8 +13,9 @@ class CacheCleanCommandTest extends AbstractCacheManageCommandTest { public function setUp() { + $this->cacheEventName = 'adminhtml_cache_flush_system'; parent::setUp(); - $this->command = new CacheCleanCommand($this->cacheManager); + $this->command = new CacheCleanCommand($this->cacheManagerMock, $this->eventManagerMock); } /** @@ -25,8 +26,9 @@ class CacheCleanCommandTest extends AbstractCacheManageCommandTest */ public function testExecute($param, $types, $output) { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('clean')->with($types); + $this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); + $this->cacheManagerMock->expects($this->once())->method('clean')->with($types); + $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->cacheEventName); $commandTester = new CommandTester($this->command); $commandTester->execute($param); diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php index 1eb4cffd23fd64cda13e2cc49c7ac4dd557dc374..4446b1b992e03b44bb3602adbab2c16cda301106 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php @@ -14,7 +14,7 @@ class CacheDisableCommandTest extends AbstractCacheSetCommandTest public function setUp() { parent::setUp(); - $this->command = new CacheDisableCommand($this->cacheManager); + $this->command = new CacheDisableCommand($this->cacheManagerMock); } /** @@ -26,8 +26,13 @@ class CacheDisableCommandTest extends AbstractCacheSetCommandTest */ public function testExecute($param, $enable, $result, $output) { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('setEnabled')->with($enable, false)->willReturn($result); + $this->cacheManagerMock->expects($this->once()) + ->method('getAvailableTypes') + ->willReturn(['A', 'B', 'C']); + $this->cacheManagerMock->expects($this->once()) + ->method('setEnabled') + ->with($enable, false) + ->willReturn($result); $commandTester = new CommandTester($this->command); $commandTester->execute($param); diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php index e20978e81e7d759e23e18f1fc1bdd5277cebed8a..e44b71d06f9fdc9a624959b50a32521c2db479eb 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheEnableCommandTest.php @@ -14,7 +14,7 @@ class CacheEnableCommandTest extends AbstractCacheSetCommandTest public function setUp() { parent::setUp(); - $this->command = new CacheEnableCommand($this->cacheManager); + $this->command = new CacheEnableCommand($this->cacheManagerMock); } /** @@ -26,9 +26,15 @@ class CacheEnableCommandTest extends AbstractCacheSetCommandTest */ public function testExecute($param, $enable, $result, $output) { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('setEnabled')->with($enable, true)->willReturn($result); - $this->cacheManager->expects($result === [] ? $this->never() : $this->once())->method('clean')->with($enable); + $this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); + $this->cacheManagerMock->expects($this->once()) + ->method('setEnabled') + ->with($enable, true) + ->willReturn($result); + $cleanInvocationCount = $result === [] ? 0 : 1; + $this->cacheManagerMock->expects($this->exactly($cleanInvocationCount)) + ->method('clean') + ->with($enable); $commandTester = new CommandTester($this->command); $commandTester->execute($param); diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php index 53032fe55ae049267f802b85b3e6127a02def5d7..07828c6627d5d440e9c10fcd28716ed7b280c067 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheFlushCommandTest.php @@ -13,8 +13,9 @@ class CacheFlushCommandTest extends AbstractCacheManageCommandTest { public function setUp() { + $this->cacheEventName = 'adminhtml_cache_flush_all'; parent::setUp(); - $this->command = new CacheFlushCommand($this->cacheManager); + $this->command = new CacheFlushCommand($this->cacheManagerMock, $this->eventManagerMock); } /** @@ -25,8 +26,9 @@ class CacheFlushCommandTest extends AbstractCacheManageCommandTest */ public function testExecute($param, $types, $output) { - $this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); - $this->cacheManager->expects($this->once())->method('flush')->with($types); + $this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']); + $this->cacheManagerMock->expects($this->once())->method('flush')->with($types); + $this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->cacheEventName); $commandTester = new CommandTester($this->command); $commandTester->execute($param); diff --git a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php index 4c792a4548dd1833d33334c6005ea4b2953f52e3..a8ee48491fbb7523f23cdc3d230092f86a967293 100644 --- a/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php +++ b/app/code/Magento/Backend/Test/Unit/Console/Command/CacheStatusCommandTest.php @@ -14,13 +14,13 @@ class CacheStatusCommandTest extends AbstractCacheCommandTest public function setUp() { parent::setUp(); - $this->command = new CacheStatusCommand($this->cacheManager); + $this->command = new CacheStatusCommand($this->cacheManagerMock); } public function testExecute() { $cacheTypes = ['A' => 0, 'B' => 1, 'C' => 1]; - $this->cacheManager->expects($this->once())->method('getStatus')->willReturn($cacheTypes); + $this->cacheManagerMock->expects($this->once())->method('getStatus')->willReturn($cacheTypes); $commandTester = new CommandTester($this->command); $commandTester->execute([]); diff --git a/app/code/Magento/PageCache/Model/Cache/Server.php b/app/code/Magento/PageCache/Model/Cache/Server.php index fc52e41e3b23428142c147c8a13556005ca72e12..2e2f3a87fb8c07a7eb33c9b61f4ef421992e6c49 100644 --- a/app/code/Magento/PageCache/Model/Cache/Server.php +++ b/app/code/Magento/PageCache/Model/Cache/Server.php @@ -60,7 +60,7 @@ class Server $httpHost = $this->request->getHttpHost(); $servers[] = $httpHost ? UriFactory::factory('')->setHost($httpHost)->setPort(self::DEFAULT_PORT)->setScheme('http') : - UriFactory::factory($this->urlBuilder->getUrl('*')) + UriFactory::factory($this->urlBuilder->getUrl('*', ['_nosid' => true])) // Don't use SID in building URL ->setScheme('http') ->setPath(null) ->setQuery(null); diff --git a/app/code/Magento/PageCache/Test/Unit/Model/Cache/ServerTest.php b/app/code/Magento/PageCache/Test/Unit/Model/Cache/ServerTest.php index 38cc49be2ff4839736af9bd27d18752a585e8aee..f18c5e04468da59169ae6b3b5642d428b7113667 100644 --- a/app/code/Magento/PageCache/Test/Unit/Model/Cache/ServerTest.php +++ b/app/code/Magento/PageCache/Test/Unit/Model/Cache/ServerTest.php @@ -64,7 +64,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase ->willReturn($httpHost); $this->urlBuilderMock->expects($this->exactly($getUrlCallCtr)) ->method('getUrl') - ->with('*') + ->with('*', ['_nosid' => true]) ->willReturn($url); $uris = [];