/**
  * @return ViewModel
  */
 public function indexAction()
 {
     $campaign = $this->campaignRepository->getOneBySecurityKey($this->params('securityKey'));
     if (!$campaign) {
         return $this->redirect()->toRoute(static::ERROR_ROUTE);
     }
     /** @var Request $request */
     $request = $this->getRequest();
     $subscriber = $this->subscriberRepository->getOneByEmailAddress($request->getPost('emailAddress'));
     if (!$subscriber) {
         $subscriber = $this->subscriberRepository->getNewEntity();
     }
     try {
         if ($this->manager->handlePost($subscriber, $campaign)) {
             if ($request->getPost('successUrl')) {
                 return $this->redirect()->toUrl($request->getPost('successUrl'));
             }
             return $this->redirect()->toRoute($this->baseRoute, array('securityKey' => $this->params('securityKey')));
         }
         if ($request->getPost('failureUrl')) {
             return $this->redirect()->toUrl($request->getPost('failureUrl'));
         }
     } catch (Manager\Exception\Db $exc) {
         $feedback = $this->userText->getMessage(EntityName::MESSAGE, Message::SAVE_FAILED);
         $this->currentMessages[FeedbackType::DANGER][] = $feedback;
     }
     $this->layout()->currentMessages = $this->currentMessages;
     return new ViewModel(array('form' => $this->manager->getForm(), 'campaignName' => $campaign->getName()));
 }
示例#2
0
 /**
  * @covers DmMailer\Manager\Unsubscribe
  */
 public function testHandlePostReturnsTrueOnSaveSuccess()
 {
     $this->formMock->expects($this->any())->method('isValid')->will($this->returnValue(true));
     $this->requestMock->expects($this->any())->method('isPost')->will($this->returnValue(true));
     $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue([]));
     $actualResult = $this->sut->handlePost($this->subscriberMock, $this->campaignMock);
     $this->assertTrue($actualResult);
 }