/**
  * Renders complex message
  *
  * @param MessageInterface $message
  * @param array $initializationData
  * @return string
  */
 public function render(MessageInterface $message, array $initializationData)
 {
     $this->setUpConfiguration($message->getData(), $initializationData);
     $result = $this->template->toHtml();
     $this->tearDownConfiguration();
     return $result;
 }
 /**
  * Interpret message
  *
  * @param MessageInterface $message
  * @return string
  */
 public function interpret(MessageInterface $message)
 {
     if ($message->getIdentifier()) {
         try {
             return $this->interpretationStrategy->interpret($message);
         } catch (\LogicException $e) {
             // pass
         }
     }
     return $message->getText();
 }
 /**
  * Interpret message
  *
  * @param MessageInterface $message
  * @return string
  * @throws \LogicException
  */
 public function interpret(MessageInterface $message)
 {
     $messageConfiguration = $this->messageConfigurationsPool->getMessageConfiguration($message->getIdentifier());
     if (null === $messageConfiguration) {
         throw new \LogicException();
     }
     $renderer = $this->renderersPool->get($messageConfiguration['renderer']);
     if (null === $renderer) {
         throw new \LogicException();
     }
     return $renderer->render($message, $messageConfiguration['data']);
 }
Example #4
0
 public function prepareMocksForTestExecute()
 {
     $postData = [1 => ['title' => '404 Not Found', 'identifier' => 'no-route', 'custom_theme' => '1', 'custom_root_template' => '2']];
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['isAjax', null, true], ['items', [], $postData]]);
     $this->pageRepository->expects($this->once())->method('getById')->with(1)->willReturn($this->cmsPage);
     $this->dataProcessor->expects($this->once())->method('filter')->with($postData[1])->willReturnArgument(0);
     $this->dataProcessor->expects($this->once())->method('validate')->with($postData[1])->willReturn(false);
     $this->messageManager->expects($this->once())->method('getMessages')->with(true)->willReturn($this->messageCollection);
     $this->messageCollection->expects($this->once())->method('getItems')->willReturn([$this->message]);
     $this->message->expects($this->once())->method('getText')->willReturn('Error message');
     $this->cmsPage->expects($this->atLeastOnce())->method('getId')->willReturn('1');
     $this->cmsPage->expects($this->atLeastOnce())->method('getData')->willReturn(['layout' => '1column', 'identifier' => 'test-identifier']);
     $this->cmsPage->expects($this->once())->method('setData')->with(['layout' => '1column', 'title' => '404 Not Found', 'identifier' => 'no-route', 'custom_theme' => '1', 'custom_root_template' => '2']);
     $this->jsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
 }
 public function testAdminAuthenticate()
 {
     $password = "******";
     $uid = 123;
     $authResult = true;
     $lockExpires = false;
     $userPassword = ['expires' => 1];
     /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserverMock */
     $eventObserverMock = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->setMethods([])->getMock();
     /** @var Event|\PHPUnit_Framework_MockObject_MockObject */
     $eventMock = $this->getMockBuilder('Magento\\Framework\\Event')->disableOriginalConstructor()->setMethods(['getPassword', 'getUser', 'getResult'])->getMock();
     /** @var ModelUser|\PHPUnit_Framework_MockObject_MockObject $userMock */
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->setMethods(['getId', 'getLockExpires', 'getPassword', 'save'])->getMock();
     $eventObserverMock->expects($this->atLeastOnce())->method('getEvent')->willReturn($eventMock);
     $eventMock->expects($this->once())->method('getPassword')->willReturn($password);
     $eventMock->expects($this->once())->method('getUser')->willReturn($userMock);
     $eventMock->expects($this->once())->method('getResult')->willReturn($authResult);
     $userMock->expects($this->atLeastOnce())->method('getId')->willReturn($uid);
     $userMock->expects($this->once())->method('getLockExpires')->willReturn($lockExpires);
     $this->userMock->expects($this->once())->method('unlock');
     $this->userMock->expects($this->once())->method('getLatestPassword')->willReturn($userPassword);
     $this->configInterfaceMock->expects($this->atLeastOnce())->method('getValue')->willReturn(1);
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Framework\\Message\\Collection')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->managerInterfaceMock->expects($this->once())->method('getMessages')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('getLastAddedMessage')->willReturn($this->messageInterfaceMock);
     $this->messageInterfaceMock->expects($this->once())->method('setIdentifier')->willReturnSelf();
     $this->authSessionMock->expects($this->once())->method('setPciAdminUserIsPasswordExpired');
     $this->encryptorMock->expects($this->once())->method('validateHashVersion')->willReturn(false);
     $this->model->execute($eventObserverMock);
 }
 /**
  * @param string $type
  *
  * @return array
  */
 protected function parseRecipients($type)
 {
     $all = $this->message->getRecipients();
     $headers = $this->message->getHeaders();
     $recipients = isset($headers[$type]) ? $headers[$type] : [];
     $result = [];
     foreach ($recipients as $key => $recipient) {
         if ($key === 'append') {
             continue;
         }
         if (in_array($recipient, $all)) {
             $result[] = trim($recipient);
         }
     }
     return $result;
 }
 protected function prepareMocksForErrorMessagesProcessing()
 {
     $this->messageManager->expects($this->atLeastOnce())->method('getMessages')->willReturn($this->messageCollection);
     $this->messageCollection->expects($this->once())->method('getItems')->willReturn([$this->message]);
     $this->messageCollection->expects($this->once())->method('getCount')->willReturn(1);
     $this->message->expects($this->once())->method('getText')->willReturn('Error text');
     $this->resultJson->expects($this->once())->method('setData')->with(['messages' => ['Error text'], 'error' => true])->willReturnSelf();
 }
 /**
  * Renders complex message
  *
  * @param MessageInterface $message
  * @param array $initializationData
  * @return string
  */
 public function render(MessageInterface $message, array $initializationData)
 {
     return $this->escaper->escapeHtml($message->getText());
 }