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 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) { } }
public function testPackageSends() { $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"; $this->package->send(); $this->assertCount(1, Communication::find()); $communication = Communication::findLast(); $this->assertEquals($this->package->title, $communication->Title, "The communication wasn't titled properly"); $this->assertCount(1, CommunicationItem::find()); $item = CommunicationItem::findLast(); $this->assertEquals("*****@*****.**", $item->Recipient, "The item didn't have a recipient"); $this->assertEquals("Email", $item->Type, "The type should have been email"); $this->assertEquals($email->getText(), $item->Text, "The text value wasn't set correctly"); $this->assertEquals(get_class($email), $item->SendableClassName, "The class name wasn't set correctly"); $this->assertEquals($email->toArray(), $item->Data, "The sendable wasn't encoded into data correctly"); $this->assertEquals($communication->UniqueIdentifier, $item->CommunicationID, "The item wasn't attached to the communication properly"); $lastEmail = UnitTestingEmailProvider::getLastEmail(); $this->assertEquals("A test email", $lastEmail->getSubject(), "The email should actually have been sent as it wasn't delayed"); }