/**
  * @return ViewModel|Response
  */
 public function updateAction()
 {
     $campaignId = $this->params('entityId');
     /** @var Campaign $campaign */
     $campaign = $this->campaignRepository->getOneById($campaignId);
     if (!$campaign) {
         return $this->redirect()->toRoute(static::BASE_ROUTE);
     }
     $message = $this->messageRepository->getSystemMessage($campaignId);
     if (!$message) {
         $message = $this->messageRepository->getNewEntity();
     }
     try {
         if ($this->manager->handlePost($campaign, $message)) {
             $msg = $this->userText->getMessage(EntityName::CAMPAIGN, Message::UPDATE_SUCCESS);
             $this->flashMessenger()->addSuccessMessage($msg);
             $this->addSystemMessageMessages();
             return $this->redirect()->toRoute(static::BASE_ROUTE);
         }
     } catch (Manager\Exception\Db $exc) {
         $campaignMsg = $this->userText->getMessage(EntityName::CAMPAIGN, Message::SAVE_FAILED);
         $messageMsg = $this->userText->getMessage(EntityName::MESSAGE, Message::SAVE_FAILED);
         $this->currentMessages[FeedbackType::DANGER][] = $campaignMsg;
         $this->currentMessages[FeedbackType::DANGER][] = $messageMsg;
     }
     $this->layout()->currentMessages = $this->currentMessages;
     return new ViewModel(['form' => $this->manager->getForm(), 'tinyMceLang' => $this->tinyMceLang]);
 }
Esempio n. 2
0
 /**
  * @TODO   Remove when Handle system message is moved to an event
  *
  * @covers DmMailer\Manager\Campaign
  */
 public function testHandleSystemMessageSkipsMessageOperation()
 {
     $this->formMock->expects($this->any())->method('isValid')->willReturn(true);
     $this->formMock->expects($this->any())->method('get')->willReturn($this->getInputMock());
     $this->requestMock->expects($this->any())->method('isPost')->willReturn(true);
     $this->requestMock->expects($this->any())->method('getPost')->willReturn([]);
     // Actual test
     $this->messageMock->expects($this->any())->method('getBody')->willReturn('');
     $this->messageMock->expects($this->any())->method('getSubject')->willReturn('');
     $this->messageMock->expects($this->any())->method('getId')->willReturn(0);
     // End of actual test
     $actualResult = $this->sut->handlePost($this->campaignMock, $this->messageMock);
     $this->assertTrue($actualResult);
     $this->assertEquals(Campaign::SYSTEM_MESSAGE_SKIPPED, $this->sut->getSystemMessageOp());
 }