public function testSendSystemEmail()
 {
     if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         $this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test email settings are not configured in perInstanceTest.php file.'));
     }
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     Yii::app()->imap->connect();
     EmailMessage::deleteAll();
     // Expunge all emails from dropbox
     Yii::app()->imap->deleteMessages(true);
     $this->assertEquals(0, EmailMessage::getCount());
     $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
     $this->assertEquals(0, $imapStats->Nmsgs);
     $subject = "System Message";
     $textMessage = "System message content.";
     $htmlMessage = "<strong>System</strong> message content.";
     EmailMessageHelper::sendSystemEmail($subject, array(Yii::app()->imap->imapUsername), $textMessage, $htmlMessage);
     sleep(30);
     Yii::app()->imap->connect();
     $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
     $this->assertEquals(1, $imapStats->Nmsgs);
     $this->assertEquals(1, EmailMessage::getCount());
     $emailMessages = EmailMessage::getAll();
     $emailMessage = $emailMessages[0];
     $this->assertEquals('System Message', $emailMessage->subject);
     $this->assertEquals('System message content.', trim($emailMessage->content->textContent));
     $this->assertEquals('<strong>System</strong> message content.', trim($emailMessage->content->htmlContent));
     $this->assertEquals(1, count($emailMessage->recipients));
     foreach ($emailMessage->recipients as $recipient) {
         $this->assertEquals($recipient->toAddress, Yii::app()->imap->imapUsername);
         $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipient->type);
     }
 }
Ejemplo n.º 2
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     Yii::app()->user->userModel = User::getByUsername('super');
     ReadPermissionsOptimizationUtil::rebuild();
     SecurityTestHelper::createUsers();
     $billy = User::getByUsername('billy');
     EmailMessageTestHelper::createEmailAccount($billy);
     $billy->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS);
     $billy->setRight('ContactsModule', ContactsModule::RIGHT_CREATE_CONTACTS);
     $billy->setRight('ContactsModule', ContactsModule::RIGHT_DELETE_CONTACTS);
     assert($billy->save());
     // Not Coding Standard
     $contact = ContactTestHelper::createContactByNameForOwner('sally', Yii::app()->user->userModel);
     $contact->primaryEmail = new Email();
     $contact->primaryEmail->emailAddress = '*****@*****.**';
     $contact->secondaryEmail->emailAddress = '*****@*****.**';
     $contact->addPermissions($billy, Permission::READ);
     $contact->addPermissions($billy, Permission::WRITE);
     $contact->save();
     $molly = ContactTestHelper::createContactByNameForOwner('molly', User::getByUsername('bobby'));
     $molly->primaryEmail = new Email();
     $molly->primaryEmail->emailAddress = '*****@*****.**';
     $molly->secondaryEmail->emailAddress = '*****@*****.**';
     $contact->save();
     ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForUser($contact, $billy);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     SecurityTestHelper::createUsers();
     $super = User::getByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $saved = $super->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     MarketingListTestHelper::createMarketingListByName('testMarketingList');
     $campaign = CampaignTestHelper::createCampaign('testCampaign', 'testSubject', 'testContent', 'testHtmlContent');
     $contact = ContactTestHelper::createContactByNameForOwner('test', $super);
     $emailMessage = EmailMessageTestHelper::createArchivedUnmatchedSentMessage($super);
     $campaignItem = new CampaignItem();
     $campaignItem->contact = $contact;
     $campaignItem->processed = true;
     $campaignItem->campaign = $campaign;
     $campaignItem->emailMessage = $emailMessage;
     $campaignItem->unrestrictedSave();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     AllPermissionsOptimizationUtil::rebuild();
 }
 public function setUp()
 {
     parent::setUp();
     if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         $this->markTestSkipped('Please fix the test email settings');
     }
 }
 public function testRun()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $outboxFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
     $sentFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage->folder = $outboxFolder;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $emailMessageId = $emailMessage->id;
     $emailMessage->forget();
     unset($emailMessage);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage2->folder = $outboxFolder;
     $saved = $emailMessage2->save();
     $this->assertTrue($saved);
     $emailMessage2Id = $emailMessage2->id;
     $emailMessage2->forget();
     unset($emailMessage2);
     $this->assertEquals(2, EmailMessage::getCount());
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(2, count($emailMessages));
     $emailMessage = EmailMessage::getById($emailMessageId);
     $this->assertEquals($sentFolder, $emailMessage->folder);
     $emailMessage2 = EmailMessage::getById($emailMessage2Id);
     $this->assertEquals($sentFolder, $emailMessage2->folder);
 }
 public function testRun()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     //Create 2 sent notifications, and set one with a date over a week ago (8 days ago) for the modifiedDateTime
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage->folder = $folder;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8);
     $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $emailMessage->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message 2', $super);
     $emailMessage2->folder = $folder;
     $saved = $emailMessage2->save();
     $this->assertTrue($saved);
     $this->assertEquals(2, EmailMessage::getCount());
     $job = new ClearSentNotificationsEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(1, count($emailMessages));
     $this->assertEquals($emailMessage2->id, $emailMessages[0]->id);
 }
 public function setUp()
 {
     parent::setUp();
     if (!(EmailMessageTestHelper::isSetEmailAccountsTestConfiguration() && SendGridTestHelper::isSetSendGridAccountTestConfiguration())) {
         $this->markTestSkipped('Please fix the test email settings');
     }
     $this->user = User::getByUsername('super');
     Yii::app()->user->userModel = $this->user;
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     self::$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('a test message', $super);
     SecurityTestHelper::createUsers();
     SecurityTestHelper::createGroups();
     SecurityTestHelper::createRoles();
     RedBeanModel::forgetAll();
     //do the rebuild to ensure the tables get created properly.
     ReadPermissionsOptimizationUtil::rebuild();
 }
Ejemplo n.º 9
0
 public function testActionSend()
 {
     if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         $super = User::getByUsername('super');
         Yii::app()->user->userModel = $super;
         chdir(COMMON_ROOT . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'commands');
         $outboundHost = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundHost'];
         $outboundPort = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundPort'];
         $outboundUsername = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundUsername'];
         $outboundPassword = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundPassword'];
         $outboundSecurity = Yii::app()->params['emailTestAccounts']['smtpSettings']['outboundSecurity'];
         $toAddress = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername'];
         $subject = 'A test email from Zurmo';
         $textContent = 'A test text message from Zurmo.';
         $htmlContent = 'A test html message from Zurmo.';
         self::$userImap->deleteMessages(true);
         self::$userImap->connect();
         $imapStats = self::$userImap->getMessageBoxStatsDetailed();
         $this->assertEquals(0, $imapStats->Nmsgs);
         // Begin Not Coding Standard
         $command = "php zurmocTest.php email send --username=super --toAddress={$toAddress} --subject='{$subject}' --textContent='{$textContent}' " . "--htmlContent='{$htmlContent}' --host={$outboundHost} --port={$outboundPort} --outboundUsername={$outboundUsername} " . "--outboundPassword={$outboundPassword}";
         // End Not Coding Standard
         if (isset($outboundSecurity) && $outboundSecurity != false) {
             $command .= " --outboundSecurity={$outboundSecurity}";
             // Not Coding Standard
         }
         if (!IS_WINNT) {
             $command .= ' 2>&1';
         }
         exec($command, $output);
         // Check if user got email
         sleep(30);
         self::$userImap->connect();
         $imapStats = self::$userImap->getMessageBoxStatsDetailed();
         $this->assertEquals(1, $imapStats->Nmsgs);
         $messages = self::$userImap->getMessages();
         $this->assertEquals(1, count($messages));
         $this->assertEquals('A test email from Zurmo', trim($messages[0]->subject));
         $this->assertEquals('<!-- zurmo css inline -->A test html message from Zurmo.', preg_replace("/\r|\n/", "", $messages[0]->htmlBody));
         $this->assertEquals('A test text message from Zurmo.', trim($messages[0]->textBody));
         $this->assertEquals(strval(Yii::app()->user->userModel), trim($messages[0]->fromName));
         $this->assertEquals(Yii::app()->emailHelper->resolveFromAddressByUser(Yii::app()->user->userModel), trim($messages[0]->fromEmail));
         $this->assertTrue(empty($messages[0]->attachments));
     }
 }
 public function testDeletingSenderAndRecipientsPersonsOrAccountsItems()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('test crud relations', $super);
     $contact = ContactTestHelper::createContactByNameForOwner('samson', $super);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagerecipient_item');
     $this->assertEquals(0, $count['count']);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagesender_item');
     $this->assertEquals(0, $count['count']);
     //Add contact as sender personOrAccounts
     $emailMessageSender = new EmailMessageSender();
     $emailMessageSender->fromAddress = '*****@*****.**';
     $emailMessageSender->fromName = 'system name';
     $emailMessageSender->personsOrAccounts->add($contact);
     $emailMessage->sender = $emailMessageSender;
     //Add also as recipient personOrAccounts
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Sam Sammy';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($contact);
     $emailMessage->recipients->add($recipient);
     //Save emailMessage
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagerecipient_item');
     $this->assertEquals(1, $count['count']);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagesender_item');
     $this->assertEquals(1, $count['count']);
     $emailMessage->forget();
     //Now delete the contact and try to retrieve the email message
     $deleted = $contact->delete();
     $this->assertTrue($deleted);
     //Now make sure the intermediate join table rows are removed
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagerecipient_item');
     $this->assertEquals(0, $count['count']);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagesender_item');
     $this->assertEquals(0, $count['count']);
 }
Ejemplo n.º 11
0
 protected function skipTestIfMissingSettings($checkBounceSettingsToo = false)
 {
     if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         $this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test email settings are not configured in perInstanceTest.php file.'));
     } elseif ($checkBounceSettingsToo && !BounceMessageTestHelper::isSetBounceImapSettings()) {
         $this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test bounce settings are not configured in perInstanceTest.php file.'));
     }
 }
 public function testUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived()
 {
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('subject 1', Yii::app()->user->userModel);
     $account3 = AccountTestHelper::createAccountByNameForOwner('account3', Yii::app()->user->userModel);
     $account4 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
     $account5 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
     $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $account5->setLatestActivityDateTime($dateTime);
     $this->assertTrue($account5->save());
     $account3Id = $account3->id;
     $account4Id = $account4->id;
     $account5Id = $account5->id;
     $this->assertNull($account3->latestActivityDateTime);
     $this->assertNull($account4->latestActivityDateTime);
     $this->assertEquals($dateTime, $account5->latestActivityDateTime);
     $emailMessage->sender->personsOrAccounts->add($account3);
     $emailMessage->recipients[0]->personsOrAccounts->add($account4);
     $emailMessage->recipients[0]->personsOrAccounts->add($account5);
     $this->assertTrue($emailMessage->save());
     $this->assertNull($account3->latestActivityDateTime);
     $this->assertNull($account4->latestActivityDateTime);
     $this->assertEquals($dateTime, $account5->latestActivityDateTime);
     $emailMessageId = $emailMessage->id;
     $emailMessage->forget();
     $account3->forget();
     $account4->forget();
     $account5->forget();
     //Retrieve email message and set sentDateTime, at this point the accounts should update with this value
     $sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 86400);
     $emailMessage = EmailMessage::getById($emailMessageId);
     $emailMessage->sentDateTime = $sentDateTime;
     $this->assertTrue($emailMessage->save());
     $account3 = Account::getById($account3Id);
     $account4 = Account::getById($account4Id);
     $account5 = Account::getById($account5Id);
     $this->assertEquals($sentDateTime, $account3->latestActivityDateTime);
     $this->assertEquals($sentDateTime, $account4->latestActivityDateTime);
     $this->assertEquals($dateTime, $account5->latestActivityDateTime);
 }
 /**
  * Check if only new messages are pulled from dropdown
  * Also check case if message will be matched with user/contact/account primary email
  *
  * @depends testRunCaseFour
  */
 public function testRunCaseFive()
 {
     if (!EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         $this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test email settings are not configured in perInstanceTest.php file.'));
     }
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $user = User::getByUsername('steve');
     Yii::app()->imap->connect();
     ContactTestHelper::createContactByNameForOwner('contact', $user);
     $contacts = Contact::getByName('contact contactson');
     $contacts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
     $this->assertTrue($contacts[0]->save());
     AccountTestHelper::createAccountByNameForOwner('account', $user);
     $accounts = Account::getByName('account');
     $accounts[0]->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
     $this->assertTrue($accounts[0]->save());
     $john = User::getByUsername('john');
     $john->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress'];
     $this->assertTrue($john->save());
     EmailMessage::deleteAll();
     Yii::app()->imap->deleteMessages(true);
     // Check if there are no emails in dropbox
     $job = new EmailArchivingJob();
     $this->assertTrue($job->run());
     $this->assertEquals(0, EmailMessage::getCount());
     $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
     $this->assertEquals(0, $imapStats->Nmsgs);
     //Now user send email to another user, and to dropbox
     $pathToFiles = Yii::getPathOfAlias('application.modules.emailMessages.tests.unit.files');
     Yii::app()->emailHelper->sendRawEmail("Email from Steve 3", $user->primaryEmail->emailAddress, array(Yii::app()->params['emailTestAccounts']['testEmailAddress']), 'Email from Steve', '<strong>Email</strong> from Steve', null, array(Yii::app()->imap->imapUsername), null, self::$userMailer);
     sleep(30);
     $job = new EmailArchivingJob();
     $this->assertTrue($job->run());
     $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
     $this->assertEquals(0, $imapStats->Nmsgs);
     $this->assertEquals(1, EmailMessage::getCount());
     $emailMessages = EmailMessage::getAll();
     $emailMessage = $emailMessages[0];
     $this->assertEquals('Email from Steve 3', $emailMessage->subject);
     $this->assertEquals('Email from Steve', trim($emailMessage->content->textContent));
     $this->assertEquals('<strong>Email</strong> from Steve', trim($emailMessage->content->htmlContent));
     $this->assertEquals($user->primaryEmail->emailAddress, $emailMessage->sender->fromAddress);
     $this->assertEquals(1, count($emailMessage->recipients));
     $recipient = $emailMessage->recipients[0];
     $this->assertCount(3, $recipient->personsOrAccounts);
     $this->assertEquals($recipient->toAddress, Yii::app()->params['emailTestAccounts']['testEmailAddress']);
     $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipient->type);
     $this->assertEquals(EmailFolder::TYPE_ARCHIVED, $emailMessage->folder->type);
     $job = new EmailArchivingJob();
     $this->assertTrue($job->run());
     $imapStats = Yii::app()->imap->getMessageBoxStatsDetailed();
     $this->assertEquals(0, $imapStats->Nmsgs);
     $this->assertEquals(1, EmailMessage::getCount());
     $this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user));
 }
 public function testDeleteAction()
 {
     $userCanDelete = $this->logoutCurrentUserLoginNewUserAndGetByUsername('usercandelete');
     $userCanDelete->setRight('EmailMessagesModule', EmailMessagesModule::RIGHT_DELETE_EMAIL_MESSAGES);
     $this->assertTrue($userCanDelete->save());
     $userCanDelete->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS);
     $userCanDelete->setRight('ContactsModule', ContactsModule::RIGHT_CREATE_CONTACTS);
     $userCanDelete->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS);
     $message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($userCanDelete);
     $this->setGetArray(array('id' => $message1->id, 'redirect' => false));
     $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/delete', true);
 }
Ejemplo n.º 15
0
 public function testCrudForHasOneAndHasManyEmailAccountRelations()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $emailAccount = EmailAccount::resolveAndGetByUserAndName($super);
     $emailAccountId = $emailAccount->id;
     $emailAccount->forgetAll();
     //Check read hasOne relation
     $emailAccount = EmailAccount::getById($emailAccountId);
     $user = $emailAccount->user;
     $this->assertEquals($super->username, $user->username);
     //Check update hasOne relation
     $user = User::getByUsername('billy');
     $emailAccount->user = $user;
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertEquals('billy', $emailAccount->user->username);
     //Check delete hasOne relation
     $emailAccount->user = null;
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertLessThan(0, $emailAccount->user->id);
     //Check create and read hasMany relation model
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('first test email', $user);
     $emailAccount->messages->add($emailMessage);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(1, $emailAccount->messages);
     $this->assertEquals('first test email', $emailAccount->messages[0]->subject);
     //Check update hasMany relation
     $emailMessage = $emailAccount->messages[0];
     $emailMessage->subject = 'first test email modified';
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(1, $emailAccount->messages);
     $this->assertEquals($emailMessage->subject, $emailAccount->messages[0]->subject);
     //Check add and read another hasMany relation model
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('second test email', $user);
     $emailAccount->messages->add($emailMessage2);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(2, $emailAccount->messages);
     $this->assertEquals($emailMessage2->subject, $emailAccount->messages[1]->subject);
     //Check delete hasMany relation first model
     $emailAccount->messages->remove($emailMessage);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(1, $emailAccount->messages);
     $this->assertEquals($emailMessage2->subject, $emailAccount->messages[0]->subject);
     //Check delete last hasMany relation model
     $emailAccount->messages->remove($emailMessage2);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(0, $emailAccount->messages);
 }
Ejemplo n.º 16
0
 public function testCrudForHasOneAndHasManyEmailMessageRelations()
 {
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('test crud relations', $this->user);
     $this->assertTrue($emailMessage->save());
     $emailMessageId = $emailMessage->id;
     $emailMessage->forgetAll();
     //Check read hasOne relation
     $emailMessage = EmailMessage::getById($emailMessageId);
     $emailMessageSender = $emailMessage->sender;
     $this->assertEquals('*****@*****.**', $emailMessageSender->fromAddress);
     //Check update hasOne relation
     $emailMessageSender->fromAddress = '*****@*****.**';
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $emailMessageSender = $emailMessage->sender;
     $this->assertEquals('*****@*****.**', $emailMessageSender->fromAddress);
     //Check delete hasOne relation
     $emailMessageSender2 = new EmailMessageSender();
     $emailMessageSender2->fromAddress = '*****@*****.**';
     $emailMessageSender2->fromName = 'system name';
     $emailMessage->sender = $emailMessageSender2;
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $found = true;
     try {
         EmailMessageSender::getById($emailMessageSender->id);
     } catch (NotFoundException $exception) {
         $found = false;
     }
     $this->assertFalse($found);
     //Check read hasMany relation
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipients = $emailMessage->recipients;
     $recipient = $recipients[0];
     $this->assertCount(1, $recipients);
     $this->assertEquals('*****@*****.**', $recipient->toAddress);
     //Check update hasMany relation
     $recipient->toAddress = '*****@*****.**';
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = $emailMessage->recipients[0];
     $this->assertEquals('*****@*****.**', $recipient->toAddress);
     //Check add hasMany relation
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Anne Frank';
     $recipient->type = EmailMessageRecipient::TYPE_BCC;
     $emailMessage->recipients->add($recipient);
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipients = $emailMessage->recipients;
     $recipient = $recipients[1];
     $this->assertCount(2, $recipients);
     //Check update hasMany relation with more than one model set
     $recipient->toAddress = '*****@*****.**';
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = $emailMessage->recipients[1];
     $this->assertEquals('*****@*****.**', $recipient->toAddress);
     //Check delete hasMany relation
     $emailMessage->recipients->remove($recipient);
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $found = true;
     try {
         EmailMessageRecipient::getById($recipient->id);
     } catch (NotFoundException $exception) {
         $found = false;
     }
     $this->assertFalse($found);
     //Check delete last hasMany relation model
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = $emailMessage->recipients[0];
     $emailMessage->recipients->remove($recipient);
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $found = true;
     try {
         EmailMessageRecipient::getById($recipient->id);
     } catch (NotFoundException $exception) {
         $found = false;
     }
     $this->assertFalse($found);
     $this->assertCount(0, $emailMessage->recipients);
 }
 public function setup()
 {
     ForgetAllCacheUtil::forgetAllCaches();
     //Special situation to deal with email box and ensuring the user cache doesn't get corrupted
     parent::setup();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         $user = User::getByUsername('steve');
         $user->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername'];
         $this->assertTrue($user->save());
     } else {
         $this->markTestSkipped(Zurmo::t('EmailMessagesModule', 'Test email settings are not configured in perInstanceTest.php file.'));
     }
 }
 /**
  * @depends testResolveEmailAddressToContactIfEmailRelationAvailableForSentMessage
  */
 public function testResolveContactToSenderOrRecipient()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $message1 = EmailMessageTestHelper::createArchivedUnmatchedReceivedMessage($super);
     $contact = new Contact();
     $this->assertCount(0, $message1->sender->personsOrAccounts);
     ArchivedEmailMatchingUtil::resolveContactToSenderOrRecipient($message1, $contact);
     $this->assertTrue($message1->recipients->count() == 1);
     $this->assertTrue($message1->recipients->offsetGet(0)->personsOrAccounts[0]->isSame($super));
     $this->assertTrue($message1->sender->personsOrAccounts[0]->isSame($contact));
     $message1 = EmailMessageTestHelper::createArchivedUnmatchedSentMessage($super);
     $contact = new Contact();
     $this->assertTrue($message1->recipients->count() == 1);
     $this->assertCount(0, $message1->recipients->offsetGet(0)->personsOrAccounts);
     ArchivedEmailMatchingUtil::resolveContactToSenderOrRecipient($message1, $contact);
     $this->assertTrue($message1->sender->personsOrAccounts[0]->isSame($super));
     $this->assertTrue($message1->recipients->count() == 1);
     $this->assertTrue($message1->recipients->offsetGet(0)->personsOrAccounts[0]->isSame($contact));
 }
Ejemplo n.º 19
0
 /**
  * @depends testSendRealEmail
  */
 public function testTooManySendAttemptsResultingInFailure()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //add a message in the outbox_error folder.
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('a test email 2', $super);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX_ERROR);
     $emailMessage->sendAttempts = 5;
     $emailMessage->save();
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(4, Yii::app()->emailHelper->getSentCount());
     Yii::app()->emailHelper->sendQueued();
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(4, Yii::app()->emailHelper->getSentCount());
     $this->assertTrue($emailMessage->folder->isSame(EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX_FAILURE)));
 }
 /**
  * For testing only
  * @param string $subject
  * @param string $from
  * @param mixed(string || array) $to
  * @param string $textContent
  * @param string $htmlContent
  * @param mixed(string || array) $cc
  * @param mixed(string || array) $bcc
  * @param array $attachments
  * @param array $settings
  * @param array $headers
  * @param array $parts
  */
 public function sendRawEmail($subject, $from, $to, $textContent = '', $htmlContent = '', $cc = null, $bcc = null, $attachments = null, $settings = null, $headers = array(), $parts = array())
 {
     assert('is_string($subject) && $subject != ""');
     assert('is_string($from)    && $from != ""');
     assert('(is_array($to) && !empty($to)) || is_string($to) || !isset($to)');
     assert('is_string($textContent) || $textContent == null');
     assert('is_string($htmlContent) || $htmlContent == null');
     assert('(is_array($cc) && !empty($cc)) || is_string($cc) || !isset($cc)');
     assert('(is_array($bcc) && !empty($bcc)) || is_string($bcc) || !isset($bcc)');
     assert('isset($to) || isset($cc) || isset($bcc)');
     assert('is_array($attachments) || !isset($attachments)');
     assert('is_array($parts) || !isset($parts)');
     $toName = null;
     $toAddress = null;
     if (is_string($to)) {
         $toAddress = $to;
     } elseif (is_array($to)) {
         foreach ($to as $key => $value) {
             $toName = $key;
             $toAddress = $value;
         }
     }
     $emailMessage = EmailMessageTestHelper::createOutboxEmail(Yii::app()->user->userModel, $subject, $htmlContent, $textContent, null, $from, $toName, $toAddress, $cc, $bcc);
     $mailer = new ZurmoSwiftMailer($emailMessage, null);
     if (!empty($parts)) {
         $mailer->parts = $parts;
     }
     $mailer->From = $from;
     if (is_array($to) && !empty($to)) {
         foreach ($to as $recipientEmail) {
             $mailer->addAddressByType($recipientEmail, '', EmailMessageRecipient::TYPE_TO);
         }
     } elseif (is_string($to)) {
         $mailer->addAddressByType($to, '', EmailMessageRecipient::TYPE_TO);
     }
     if (is_array($cc) && !empty($cc)) {
         foreach ($cc as $recipientEmail) {
             $mailer->addAddressByType($recipientEmail, '', EmailMessageRecipient::TYPE_CC);
         }
     } elseif (is_string($cc)) {
         $mailer->addAddressByType($cc, '', EmailMessageRecipient::TYPE_CC);
     }
     if (is_array($bcc) && !empty($bcc)) {
         foreach ($bcc as $recipientEmail) {
             $mailer->addAddressByType($recipientEmail, '', EmailMessageRecipient::TYPE_BCC);
         }
     } elseif (is_string($bcc)) {
         $mailer->addAddressByType($bcc, '', EmailMessageRecipient::TYPE_BCC);
     }
     if (isset($attachments) && !empty($attachments)) {
         foreach ($attachments as $file) {
             $mailer->attachFromPath($file);
         }
     }
     $mailer->headers = $headers;
     $acceptedRecipients = $mailer->send();
     if ($acceptedRecipients > 0) {
         // Do nothing
     } else {
         // To-Do: make exception or something else
         echo "There was error while sending email";
     }
 }
Ejemplo n.º 21
0
 public function testSendMessagePopulatesEmailAccountSettings()
 {
     $jane = User::getByUsername('jane');
     Yii::app()->user->userModel = $jane;
     $emailHelper = new EmailHelper();
     EmailMessageTestHelper::createEmailAccount($jane);
     $emailAccount = EmailAccount::getByUserAndName($jane);
     $emailAccount->useCustomOutboundSettings = EmailMessageUtil::OUTBOUND_PERSONAL_SMTP_SETTINGS;
     $emailAccount->outboundType = 'abc';
     $emailAccount->outboundPort = 11;
     $emailAccount->outboundHost = 'dumb.domain';
     $emailAccount->outboundUsername = '******';
     $emailAccount->outboundPassword = '******';
     $emailAccount->outboundSecurity = 'ssl';
     $emailAccount->save();
     $emailMessage = EmailMessageTestHelper::createOutboxEmail($jane, 'Test email', 'Raw content', 'Html content', 'Zurmo', Yii::app()->emailHelper->outboundUsername, 'John Doe', Yii::app()->params['emailTestAccounts']['userImapSettings']['imapUsername']);
     $emailMessage->account = $emailAccount;
     $emailMessage->save();
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     Yii::app()->emailHelper->sendQueued();
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     //Since user email account has invalid settings message is not sent
     $this->assertContains('Connection could not be established with host dumb.domain', strval($emailMessage->error));
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
 }
 public function generateAndProcessEmailMessages($count)
 {
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $outboxFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
     $sentFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
     $emailMessageIds = array();
     $files = array();
     for ($i = 0; $i < $count; $i++) {
         $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message ' . $i, $this->user);
         foreach ($fileNames as $index => $fileName) {
             $file = ZurmoTestHelper::createFileModel($fileName);
             $files[$index]['name'] = $fileName;
             $files[$index]['type'] = $file->type;
             $files[$index]['size'] = $file->size;
             $files[$index]['contents'] = $file->fileContent->content;
             $emailMessage->files->add($file);
         }
         $emailMessage->folder = $outboxFolder;
         $saved = $emailMessage->save(false);
         $this->assertTrue($saved);
         $emailMessageIds[] = $emailMessage->id;
         $emailMessage->forget();
         unset($emailMessage);
     }
     OutboundEmailBatchSizeConfigUtil::setBatchSize($count + 1);
     Yii::app()->jobQueue->deleteAll();
     ForgetAllCacheUtil::forgetAllCaches();
     $job = new ProcessOutboundEmailJob();
     $startedAt = microtime(true);
     $this->assertTrue($job->run());
     $timeTaken = microtime(true) - $startedAt;
     ForgetAllCacheUtil::forgetAllCaches();
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals($count, count($emailMessages));
     foreach ($emailMessageIds as $i => $emailMessageId) {
         $emailMessage = EmailMessage::getById($emailMessageId);
         $this->assertEquals('My Email Message ' . $i, $emailMessage->subject);
         $this->assertEquals(1, $emailMessage->sendAttempts);
         $this->assertEquals($sentFolder->id, $emailMessage->folder->id);
         $this->assertNotEmpty($emailMessage->files);
         $this->assertCount(count($files), $emailMessage->files);
         foreach ($emailMessage->files as $index => $file) {
             $this->assertEquals($file->name, $emailMessage->files[$index]->name);
             $this->assertEquals($file->type, $emailMessage->files[$index]->type);
             $this->assertEquals($file->size, $emailMessage->files[$index]->size);
             $this->assertEquals($file->fileContent->content, $emailMessage->files[$index]->fileContent->content);
             $this->assertEquals($file->fileContent->id, $emailMessage->files[$index]->fileContent->id);
         }
     }
     return $timeTaken;
 }
 public function testEmailCopyActivity()
 {
     $this->markTestSkipped();
     Yii::app()->user->userModel = User::getByUsername('super');
     $this->setFirstModel();
     $this->setSecondModel();
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('Subject 1', Yii::app()->user->userModel);
     $this->assertTrue($emailMessage->save());
     $emailMessageId = $emailMessage->id;
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $newSender = new EmailMessageSender();
     $newSender->fromAddress = $this->selectedModels[1]->primaryEmail->emailAddress;
     $newSender->fromName = strval($this->selectedModels[1]);
     $newSender->personsOrAccounts->add($this->selectedModels[1]);
     $emailMessage->sender = $newSender;
     $emailMessage->save();
     ListViewMergeUtil::processCopyEmailActivity($this->selectedModels[0], $this->selectedModels[1]);
     $emailMessage = EmailMessage::getById($emailMessageId);
     $this->assertEquals(strval($this->selectedModels[0]), $emailMessage->sender->fromName);
     $this->assertEquals('*****@*****.**', $emailMessage->sender->fromAddress);
     //For recipient
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('Subject 2', Yii::app()->user->userModel);
     $this->assertTrue($emailMessage->save());
     $emailMessageId = $emailMessage->id;
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = $this->selectedModels[1]->primaryEmail->emailAddress;
     $recipient->toName = strval($this->selectedModels[1]);
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($this->selectedModels[1]);
     $emailMessage->recipients->add($recipient);
     $this->assertTrue($emailMessage->save());
     ListViewMergeUtil::processCopyEmailActivity($this->selectedModels[0], $this->selectedModels[1]);
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipients = $emailMessage->recipients;
     $this->assertCount(2, $recipients);
     $this->assertEquals(strval($this->selectedModels[0]), $recipients[1]->toName);
     $this->assertEquals('*****@*****.**', $recipients[1]->toAddress);
     $this->assertCount(1, $recipients[1]->personsOrAccounts);
 }
Ejemplo n.º 24
0
 /**
  * @depends testRequiredAttributes
  */
 public function testDeleteCampaign()
 {
     $campaigns = Campaign::getAll();
     $this->assertEquals(4, count($campaigns));
     CampaignItemTestHelper::createCampaignItem(0, $campaigns[0]);
     $campaignItems = CampaignItem::getAll();
     $this->assertCount(1, $campaignItems);
     $campaignItemActivity = new CampaignItemActivity();
     $campaignItemActivity->type = CampaignItemActivity::TYPE_CLICK;
     $campaignItemActivity->quantity = 1;
     $campaignItemActivity->campaignItem = $campaignItems[0];
     $campaignItemActivity->latestSourceIP = '121.212.122.112';
     $this->assertTrue($campaignItemActivity->save());
     $emailMessage = EmailMessageTestHelper::createOutboxEmail(Yii::app()->user->userModel, 'subject', 'html', 'text', 'from', '*****@*****.**', 'to', '*****@*****.**');
     $campaignItems[0]->emailMessage = $emailMessage;
     $this->assertTrue($campaignItems[0]->unrestrictedSave());
     $this->assertEquals(1, CampaignItemActivity::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
     $campaigns[0]->delete();
     $this->assertEquals(3, Campaign::getCount());
     $this->assertEquals(0, CampaignItem::getCount());
     $this->assertEquals(0, CampaignItemActivity::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
Ejemplo n.º 25
0
 public function testSavePurgesUnsetCampaignItemsForPausedToActiveStatusChangeIfNeeded()
 {
     $campaign = CampaignTestHelper::createCampaign('afterSaveDeleteUnsetCampaignItemsTest', 'subject', 'text');
     // 3 items, 1 unprocessed, 1 processed with email in outbox, 1 processed with email in sent.
     $campaignItem = CampaignItemTestHelper::createCampaignItem(1, $campaign);
     $emailMessage = EmailMessageTestHelper::createOutboxEmail(Yii::app()->user->userModel, 'subject', 'html', 'text', 'from', '*****@*****.**', 'to', '*****@*****.**');
     $campaignItem->emailMessage = $emailMessage;
     $this->assertTrue($campaignItem->unrestrictedSave());
     $campaignItem2 = CampaignItemTestHelper::createCampaignItem(1, $campaign);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('subject2', Yii::app()->user->userModel);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage2->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $this->assertTrue($emailMessage2->save());
     $campaignItem2->emailMessage = $emailMessage2;
     $this->assertTrue($campaignItem2->unrestrictedSave());
     CampaignItemTestHelper::createCampaignItem(0, $campaign);
     $this->assertCount(2, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
     // set initial status
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     $this->assertCount(2, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
     // change a non-dependent property, no change in campaign items
     $campaign->status = Campaign::STATUS_ACTIVE;
     $campaign->name = $campaign->name . 'modified';
     $this->assertCount(2, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
     // reset status
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     // change a dependent property, unset should be deleted.
     $campaign->status = Campaign::STATUS_ACTIVE;
     $campaign->subject = $campaign->subject . 'modified';
     $this->assertTrue($campaign->save());
     // deleted: 1 processed with email in outbox, 1 unprocessed.
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(0, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(0, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
 }