public function testEmailExtractionFromCommunicationEmail()
 {
     $email = new SimpleEmail();
     $email->addRecipientByEmail("John Smith", "*****@*****.**");
     $email->setSender("Jane Smith", "*****@*****.**");
     $email->setSubject("The three billy goats");
     $email->setText("Michael went to mow, went to mow a meadow.");
     $email->setHtml("<p>Michael went to mow, went to mow a meadow.</p>");
     $email->addAttachment("file_location.txt");
     $email->addAttachment("file_location1.txt", "TestFakeFileName");
     $package = new CommunicationPackage();
     $package->addSendable($email);
     $package->title = $email->getSubject();
     $package->send();
     $item = CommunicationItem::findLast();
     $derivedEmail = $item->getSendable();
     $this->assertEquals($email, $derivedEmail, "The derived email isn't exactly the same as the original");
     $this->assertInstanceOf(SimpleEmail::class, $derivedEmail);
     // Next test is that a different sendable generates the correct type when getSendable is called.
     $unitTestingEmail = new UnitTestingTemplateEmail(['Name' => "", 'Age' => "", 'HairColour' => ""]);
     $unitTestingEmail->addRecipientByEmail("*****@*****.**");
     $package = new CommunicationPackage();
     $package->addSendable($unitTestingEmail);
     $package->title = $unitTestingEmail->getSubject();
     $package->send();
     $item = CommunicationItem::findLast();
     $derivedEmail = $item->getSendable();
     $this->assertInstanceOf(UnitTestingTemplateEmail::class, $derivedEmail);
 }
 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();
 }
 private static final function sendItem(CommunicationItem $item)
 {
     if ($item->Sent) {
         Log::warning("Attempt blocked to send already sent email", "COMMS", ["CommunicationItemID" => $item->CommunicationItemID, "EmailProvider" => self::$emailProviderClassName]);
         return true;
     }
     $sendable = $item->getSendable();
     $providerClass = $sendable->getProviderClassName();
     $provider = self::getContainer()->getInstance($providerClass);
     if ($provider instanceof CaptureToCommunicationsProcessorInterface) {
         throw new InvalidProviderException();
     }
     try {
         $provider->send($sendable);
         $item->markSent();
     } catch (\Exception $exception) {
         $item->Status = CommunicationItem::STATUS_FAILED;
     }
     $item->markSent();
     $item->save();
     Log::debug("Sending communication by Email", "COMMS", ["CommunicationID" => $item->CommunicationID, "EmailProvider" => self::$emailProviderClassName]);
     return $item->Status == CommunicationItem::STATUS_SENT;
 }
 public function testPackageWithMultipleSendables()
 {
     $email = $this->createEmailAndAddToPackage();
     $email->addRecipientByEmail("*****@*****.**");
     $email->setSubject("A test email");
     $email->setText("This is the end, my lonely friend, the end.");
     $email = $this->createEmailAndAddToPackage();
     $email->addRecipientByEmail("*****@*****.**");
     $email->setSubject("A second test email");
     $email->setText("This is the end, my lonely friend, the end.");
     $this->package->title = "A test communication";
     $this->package->send();
     $this->assertCount(2, CommunicationItem::find());
 }
 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) {
     }
 }