/**
  * @dataProvider dataProvider
  */
 public function testAroundDispatchDisabled($state)
 {
     $this->configMock->expects($this->any())->method('getType')->will($this->returnValue(null));
     $this->versionMock->expects($this->never())->method('process');
     $this->stateMock->expects($this->any())->method('getMode')->will($this->returnValue($state));
     $this->responseMock->expects($this->never())->method('setHeader');
     $this->plugin->aroundDispatch($this->frontControllerMock, $this->closure, $this->requestMock);
 }
Пример #2
0
 /**
  * @param \Magento\Framework\App\FrontControllerInterface $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return false|\Magento\Framework\App\Response\Http|\Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\FrontControllerInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     $response = $proceed($request);
     if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled() && $response instanceof \Magento\Framework\App\Response\Http) {
         $this->version->process();
         if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
             $response->setHeader('X-Magento-Debug', 1);
         }
     }
     return $response;
 }
Пример #3
0
 /**
  * @param \Magento\Framework\Controller\ResultInterface $subject
  * @param callable $proceed
  * @param ResponseHttp $response
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function aroundRenderResult(\Magento\Framework\Controller\ResultInterface $subject, \Closure $proceed, ResponseHttp $response)
 {
     $proceed($response);
     $usePlugin = $this->registry->registry('use_page_cache_plugin');
     if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled() && $usePlugin) {
         $this->version->process();
         if ($this->state->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
             $response->setHeader('X-Magento-Debug', 1);
         }
     }
     return $subject;
 }
Пример #4
0
 /**
  * @dataProvider processProvider
  * @param bool $isPost
  */
 public function testProcess($isPost)
 {
     $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
     if ($isPost) {
         $publicCookieMetadataMock = $this->getMock('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata');
         $publicCookieMetadataMock->expects($this->once())->method('setPath')->with('/')->will($this->returnSelf());
         $publicCookieMetadataMock->expects($this->once())->method('setDuration')->with(Version::COOKIE_PERIOD)->will($this->returnSelf());
         $this->cookieMetadataFactoryMock->expects($this->once())->method('createPublicCookieMetadata')->with()->will($this->returnValue($publicCookieMetadataMock));
         $this->cookieManagerMock->expects($this->once())->method('setPublicCookie');
     }
     $this->version->process();
 }
Пример #5
0
 /**
  * @param \Magento\Framework\App\FrontControllerInterface $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return \Magento\Framework\Controller\ResultInterface|\Magento\Framework\App\Response\Http
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundDispatch(\Magento\Framework\App\FrontControllerInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->config->isEnabled() || $this->config->getType() != \Magento\PageCache\Model\Config::BUILT_IN) {
         return $proceed($request);
     }
     $this->version->process();
     $result = $this->kernel->load();
     if ($result === false) {
         $result = $proceed($request);
         if ($result instanceof ResponseHttp) {
             $this->addDebugHeaders($result);
             $this->kernel->process($result);
         }
     } else {
         $this->addDebugHeader($result, 'X-Magento-Cache-Debug', 'HIT', true);
     }
     return $result;
 }
Пример #6
0
 /**
  * @param \Magento\Framework\App\FrontControllerInterface $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return false|\Magento\Framework\App\Response\Http
  */
 public function aroundDispatch(\Magento\Framework\App\FrontControllerInterface $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if ($this->config->getType() == \Magento\PageCache\Model\Config::BUILT_IN && $this->config->isEnabled()) {
         $this->version->process();
         $response = $this->kernel->load();
         if ($response === false) {
             $response = $proceed($request);
             $cacheControl = $response->getHeader('Cache-Control')['value'];
             $this->addDebugHeader($response, 'X-Magento-Cache-Control', $cacheControl);
             $this->kernel->process($response);
             $this->addDebugHeader($response, 'X-Magento-Cache-Debug', 'MISS');
         } else {
             $this->addDebugHeader($response, 'X-Magento-Cache-Debug', 'HIT');
         }
     } else {
         return $response = $proceed($request);
     }
     return $response;
 }