public function testSendEmailWithFailedAttempts()
 {
     $noOfRecipients = 6;
     $communication = $this->createCommunicationWithMultipleRecipients(new RhubarbDateTime("now"), $noOfRecipients);
     $communicationEmail = $communication->Items[$noOfRecipients - 1];
     $communicationEmail->Sent = true;
     $communicationEmail->save();
     CommunicationProcessor::sendCommunication($communication);
     $this->assertCount(1, UnitTestingEmailProvider::GetLastEmail()->getRecipients(), "Communication scaffold should have unwrapped the recipients to individual email items. Each email item" . " should have just 1 recipient");
     $this->assertEquals("*****@*****.**", current(UnitTestingEmailProvider::GetLastEmail()->getRecipients())->email);
 }
 public function execute(BackgroundTaskStatus $status)
 {
     $status->Message = "Processing Communications to be sent";
     $status->save();
     $communicationID = $status->TaskSettings["CommunicationID"];
     if (!$communicationID) {
         throw new ImplementationException("Communication Background Task must have a Communication ID");
     }
     $communication = new Communication($communicationID);
     CommunicationProcessor::sendCommunication($communication);
 }
 public function testDraftPackageCantSend()
 {
     $email = $this->createEmailAndAddToPackage();
     $email->addRecipientByEmail("*****@*****.**");
     $email->setSubject("A test email");
     $email->setText("This is the end, my lonely friend, the end.");
     $this->package->title = "A test communication";
     $communication = $this->package->draft();
     $sent = CommunicationProcessor::sendCommunication($communication);
     $this->assertFalse($sent, "Draft communications shouldn't send");
 }
 protected function setUp()
 {
     parent::setUp();
     Application::current()->registerModule(new CommunicationsModule());
     Application::current()->initialiseModules();
     Model::clearAllRepositories();
     CommunicationProcessor::setProviderClassName(EmailProvider::class, UnitTestingEmailProvider::class);
     Repository::setDefaultRepositoryClassName(Offline::class);
     Communication::clearObjectCache();
     CommunicationItem::clearObjectCache();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     parent::execute($input, $output);
     $communicationID = $input->getArgument('communicationID');
     if (isset($communicationID)) {
         $communication = new Communication($communicationID);
         CommunicationProcessor::sendCommunication($communication);
     } else {
         $unsentCommunicationsArray = Communication::findUnsentCommunications();
         foreach ($unsentCommunicationsArray as $communication) {
             CommunicationProcessor::sendCommunication($communication);
         }
     }
 }
 public function testCommunicationEmailProviderCantBeAProcessor()
 {
     $this->assertCount(0, CommunicationItem::find(), "CommunicationItem count was not 0");
     $this->assertCount(0, Communication::find(), "Communication count was not 0");
     $email = new SimpleEmail();
     $email->setSubject("A fine day in the park");
     $email->addRecipientByEmail("*****@*****.**", "Joe Bloggs");
     $email->setHtml("<html><head>Test Head</head><body>Test Body</body></html>");
     $email->setText("Test Text Body");
     CommunicationProcessor::setProviderClassName(EmailProvider::class, CommunicationEmailProvider::class);
     try {
         EmailProvider::setProviderClassName(CommunicationEmailProvider::class);
         EmailProvider::getProvider()->send($email);
         $this->fail('Email should not sent due to invalid Communication Provider being set');
     } catch (InvalidProviderException $exception) {
     }
 }
 protected function createSubLeaves()
 {
     $communicationItems = $this->model->restCollection;
     if ($this->model->archive) {
         $communicationItems->filter(new Not(new Equals('Status', 'Not Sent')));
     }
     $communicationItems->intersectWith(Communication::find(), 'CommunicationID', 'CommunicationID', ['Title', 'DateToSend']);
     $this->registerSubLeaf($table = new Table($communicationItems->addSort('DateCreated', false)), $searchPanel = new CommunicationItemSearchPanel('SearchPanel'), $sendAllButton = new Button('SendAllCommunicationsButton', 'Send All Communications Now', function () {
         foreach (Communication::findUnsentCommunications() as $unsentCommunication) {
             CommunicationProcessor::sendCommunication($unsentCommunication, true);
         }
         throw new ForceResponseException(new RedirectResponse('./'));
     }), new CommunicationItemCollectionCheckbox('EnableSendingEmails'));
     $sendAllButton->setConfirmMessage('Are you sure you want to send all scheduled emails?');
     $table->bindEventsWith($searchPanel);
     $table->columns = ['#' => 'CommunicationItemID', 'Title' => '{Title}', 'Recipient', 'DateCreated', 'Date to Send' => new DateColumn('DateToSend', 'Date to Send', CommunicationDecorator::DATE_FORMAT), 'DateSent', 'Status', '' => '<a class="view-content-button" data-id="{CommunicationItemID}" href="#ViewContent">View Content</a>'];
 }
 public function draft()
 {
     return CommunicationProcessor::draftPackage($this);
 }