123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\PageCache\Test\Unit\Model\App\FrontController;
- use Magento\PageCache\Model\App\FrontController\VarnishPlugin;
- use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
- use Magento\PageCache\Model\Config;
- use Magento\Framework\App\PageCache\Version;
- use Magento\Framework\App\State as AppState;
- use Magento\Framework\App\FrontControllerInterface;
- use Magento\Framework\App\Response\Http as ResponseHttp;
- use Magento\Framework\Controller\ResultInterface;
- /**
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class VarnishPluginTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var VarnishPlugin
- */
- private $plugin;
- /**
- * @var ObjectManagerHelper
- */
- private $objectManagerHelper;
- /**
- * @var Config|\PHPUnit_Framework_MockObject_MockObject
- */
- private $configMock;
- /**
- * @var Version|\PHPUnit_Framework_MockObject_MockObject
- */
- private $versionMock;
- /**
- * @var AppState|\PHPUnit_Framework_MockObject_MockObject
- */
- private $stateMock;
- /**
- * @var FrontControllerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $frontControllerMock;
- /**
- * @var ResponseHttp|\PHPUnit_Framework_MockObject_MockObject
- */
- private $responseMock;
- /**
- * @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $resultMock;
- protected function setUp()
- {
- $this->configMock = $this->getMockBuilder(Config::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->versionMock = $this->getMockBuilder(Version::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->stateMock = $this->getMockBuilder(AppState::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->frontControllerMock = $this->getMockBuilder(FrontControllerInterface::class)
- ->getMockForAbstractClass();
- $this->responseMock = $this->getMockBuilder(ResponseHttp::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->resultMock = $this->getMockBuilder(ResultInterface::class)
- ->getMockForAbstractClass();
- $this->objectManagerHelper = new ObjectManagerHelper($this);
- $this->plugin = $this->objectManagerHelper->getObject(
- VarnishPlugin::class,
- [
- 'config' => $this->configMock,
- 'version' => $this->versionMock,
- 'state' => $this->stateMock
- ]
- );
- }
- /**
- * @param string $state
- * @param int $countHeader
- *
- * @dataProvider afterDispatchDataProvider
- */
- public function testAfterDispatchReturnsCache($state, $countHeader)
- {
- $this->configMock->expects(static::once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->configMock->expects(static::once())
- ->method('getType')
- ->willReturn(Config::VARNISH);
- $this->versionMock->expects(static::once())
- ->method('process');
- $this->stateMock->expects(static::once())
- ->method('getMode')
- ->willReturn($state);
- $this->responseMock->expects(static::exactly($countHeader))
- ->method('setHeader')
- ->with('X-Magento-Debug');
- $this->assertSame(
- $this->responseMock,
- $this->plugin->afterDispatch($this->frontControllerMock, $this->responseMock)
- );
- }
- public function testAfterDispatchNotResponse()
- {
- $this->configMock->expects(static::once())
- ->method('isEnabled')
- ->willReturn(true);
- $this->configMock->expects(static::once())
- ->method('getType')
- ->willReturn(Config::VARNISH);
- $this->versionMock->expects(static::never())
- ->method('process');
- $this->stateMock->expects(static::never())
- ->method('getMode');
- $this->resultMock->expects(static::never())
- ->method('setHeader');
- $this->assertSame(
- $this->resultMock,
- $this->plugin->afterDispatch($this->frontControllerMock, $this->resultMock)
- );
- }
- public function testAfterDispatchDisabled()
- {
- $this->configMock->expects(static::any())
- ->method('getType')
- ->willReturn(null);
- $this->versionMock->expects(static::never())
- ->method('process');
- $this->stateMock->expects(static::any())
- ->method('getMode')
- ->willReturn(AppState::MODE_DEVELOPER);
- $this->responseMock->expects(static::never())
- ->method('setHeader');
- $this->assertSame(
- $this->responseMock,
- $this->plugin->afterDispatch($this->frontControllerMock, $this->responseMock)
- );
- }
- /**
- * @return array
- */
- public function afterDispatchDataProvider()
- {
- return [
- 'developer_mode' => [AppState::MODE_DEVELOPER, 1],
- 'production' => [AppState::MODE_PRODUCTION, 0]
- ];
- }
- }
|