Exemple #1
0
 /**
  * Set Cookie for msg box when it displays first
  *
  * @param \Magento\Framework\App\FrontController $subject
  * @param \Magento\Framework\App\ResponseInterface $response
  *
  * @return \Magento\Framework\App\ResponseInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterDispatch(\Magento\Framework\App\FrontController $subject, \Magento\Framework\App\ResponseInterface $response)
 {
     if ($this->request->isPost() && $this->messageManager->hasMessages()) {
         $this->cookie->set(self::COOKIE_NAME, 1, self::COOKIE_PERIOD, '/');
     }
     return $response;
 }
 /**
  * Set Cookie for msg box when it displays first
  *
  * @param FrontController $subject
  * @param \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface $result
  *
  * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterDispatch(FrontController $subject, $result)
 {
     if ($this->request->isPost() && $this->messageManager->hasMessages()) {
         $publicCookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata()->setDuration(self::COOKIE_PERIOD)->setPath('/')->setHttpOnly(false);
         $this->cookieManager->setPublicCookie(self::COOKIE_NAME, 1, $publicCookieMetadata);
     }
     return $result;
 }
 /**
  * @param string $type
  * @param string $methodName
  * @dataProvider addMessageDataProvider
  */
 public function testAddMessage($type, $methodName)
 {
     $this->assertFalse($this->model->hasMessages());
     $message = 'Message';
     $messageCollection = $this->getMock('Magento\\Framework\\Message\\Collection', ['addMessage'], [], '', false);
     $this->session->expects($this->any())->method('getData')->will($this->returnValue($messageCollection));
     $this->eventManager->expects($this->once())->method('dispatch')->with('session_abstract_add_message');
     $this->messageFactory->expects($this->once())->method('create')->with($type, $message)->will($this->returnValue($this->messageMock));
     $this->model->{$methodName}($message, 'group');
     $this->assertTrue($this->model->hasMessages());
 }