/**
  * @return integer count of how many emails are queued to go.  This means they are in either the TYPE_OUTBOX
  * folder or the TYPE_OUTBOX_ERROR folder.
  */
 public static function getQueuedCount()
 {
     return count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX)) + count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX_ERROR));
 }
 /**
  * To try to show failure of https://www.pivotaltracker.com/story/show/81571830
  * Using trademark symbol to demonstrate merge tag resolution working correctly and it properly printing
  * text after the trademark symbol
  */
 public function testNonAlphaNumericSymbolsAsMergeTagFields()
 {
     $account = AccountTestHelper::createAccountByNameForOwner('Candyland™', Yii::app()->user->userModel);
     $emailTemplate = new EmailTemplate();
     $emailTemplate->builtType = EmailTemplate::BUILT_TYPE_PASTED_HTML;
     $emailTemplate->modelClassName = 'Account';
     $emailTemplate->type = 1;
     $emailTemplate->name = 'some template';
     $emailTemplate->subject = 'some subject [[NAME]] is great';
     $emailTemplate->htmlContent = 'Account HTML: [[NAME]] after the merge tag is resolved';
     $emailTemplate->textContent = 'Account Text: [[NAME]] after the merge tag is resolved';
     $this->assertTrue($emailTemplate->save());
     $message = new EmailMessageForWorkflowForm('Account', Workflow::TYPE_ON_SAVE);
     $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER));
     $message->emailTemplateId = $emailTemplate->id;
     $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_CUSTOM;
     $message->sendFromAddress = '*****@*****.**';
     $message->sendFromName = 'Jason';
     $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
     $helper = new WorkflowEmailMessageProcessingHelper($message, $account, Yii::app()->user->userModel);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $helper->process();
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals('some subject Candyland™ is great', $emailMessages[0]->subject);
     $this->assertEquals('Account Text: Candyland™ after the merge tag is resolved', $emailMessages[0]->content->textContent);
     $this->assertEquals('Account HTML: Candyland™ after the merge tag is resolved', $emailMessages[0]->content->htmlContent);
 }
 public function testSubmitCriticalNotificationWithInboxNotificationSettingEnabledAndEmailNotificationSettingEnabled()
 {
     $initialNotificationCount = Notification::getCount();
     $initialEmailMessageCount = EmailMessage::getCount();
     $initialSentEmailMessageCount = count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_SENT));
     $rules = new SimpleNotificationRules();
     $rules->setAllowDuplicates(true);
     $rules->addUser($this->user);
     $rules->setCritical(true);
     $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser();
     $inboxAndEmailNotificationSettings['enableSimpleNotification']['email'] = true;
     $inboxAndEmailNotificationSettings['enableSimpleNotification']['inbox'] = true;
     UserNotificationUtil::setValue($this->user, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false);
     $this->assertTrue(UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($this->user, 'enableSimpleNotification', 'email'));
     $this->assertTrue(UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($this->user, 'enableSimpleNotification', 'inbox'));
     $message = new NotificationMessage();
     $message->textContent = 'text content for' . __FUNCTION__;
     $message->htmlContent = 'html content for' . __FUNCTION__;
     NotificationsUtil::submit($message, $rules);
     $this->assertEquals($initialNotificationCount + 1, Notification::getCount());
     // because it was a critical notification, an email should have been sent immediately.
     $this->assertEquals($initialEmailMessageCount + 1, EmailMessage::getCount());
     $this->assertEquals($initialSentEmailMessageCount + 1, count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_SENT)));
 }
 public function testTaskStatusBecomesRejectedNotificationWhenOwnerIsNotCurrentUser()
 {
     $task = new Task();
     $task->name = 'RejectOwner Task';
     $task->requestedByUser = self::$sally;
     $task->owner = self::$katie;
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertTrue($task->save());
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     EmailMessage::deleteAll();
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     //Now change status
     $task->status = Task::STATUS_REJECTED;
     $this->assertTrue($task->save());
     //One email should be queued up
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertCount(1, $emailMessages);
     $this->assertEquals(1, $emailMessages[0]->recipients->count());
     $this->assertEquals('*****@*****.**', $emailMessages[0]->recipients[0]->toAddress);
 }
 /**
  * @depends testProcessWithCustomSender
  */
 public function testInvalidMergeTagsReturnOriginalContent()
 {
     self::$emailTemplate->subject = 'bad subject [[LASTNAME]]';
     self::$emailTemplate->textContent = 'bad text [[LASTNAME]]';
     self::$emailTemplate->htmlContent = 'bad html [[LASTNAME]]';
     $message = new EmailMessageForWorkflowForm('WorkflowModelTestItem', Workflow::TYPE_ON_SAVE);
     $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_USER, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'dynamicUserType' => DynamicTriggeredModelUserWorkflowEmailMessageRecipientForm::DYNAMIC_USER_TYPE_CREATED_BY_USER));
     $message->emailTemplateId = self::$emailTemplate->id;
     $message->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_CUSTOM;
     $message->sendFromAddress = '*****@*****.**';
     $message->sendFromName = 'Jason';
     $message->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
     $model = new WorkflowModelTestItem();
     $model->lastName = 'the lastName';
     $model->string = 'the string';
     $model->phone = 'the phone';
     $saved = $model->save();
     $this->assertTrue($saved);
     $helper = new WorkflowEmailMessageProcessingHelper($message, $model, Yii::app()->user->userModel);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $helper->process();
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals('bad subject [[LASTNAME]]', $emailMessages[0]->subject);
     $this->assertEquals('bad text [[LASTNAME]]', $emailMessages[0]->content->textContent);
     $this->assertEquals('bad html [[LASTNAME]]', $emailMessages[0]->content->htmlContent);
     $this->assertEquals('Jason', $emailMessages[0]->sender->fromName);
     $this->assertEquals('*****@*****.**', $emailMessages[0]->sender->fromAddress);
     $this->assertEquals(1, $emailMessages[0]->recipients->count());
     $this->assertEquals('*****@*****.**', $emailMessages[0]->recipients[0]->toAddress);
     $emailMessages[0]->delete();
 }
 public function getSentCount()
 {
     return count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_SENT));
 }
 public function testProcessAfterSaveWhenSendIsImmediateAndToAContactThatIsRelatedToTheTriggeredModel()
 {
     foreach (EmailMessage::getAll() as $emailMessage) {
         $emailMessage->delete();
     }
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $emailTemplate = new EmailTemplate();
     $emailTemplate->name = 'the name';
     $emailTemplate->modelClassName = 'Account';
     $emailTemplate->textContent = 'some content';
     $emailTemplate->type = 2;
     $emailTemplate->subject = 'subject';
     $saved = $emailTemplate->save();
     $this->assertTrue($saved);
     $workflow = new Workflow();
     $workflow->setId(self::$savedWorkflow->id);
     $workflow->type = Workflow::TYPE_ON_SAVE;
     $emailMessageForm = new EmailMessageForWorkflowForm('Account', Workflow::TYPE_ON_SAVE);
     $emailMessageForm->sendAfterDurationSeconds = 0;
     $emailMessageForm->emailTemplateId = $emailTemplate->id;
     $emailMessageForm->sendFromType = EmailMessageForWorkflowForm::SEND_FROM_TYPE_DEFAULT;
     $recipients = array(array('type' => WorkflowEmailMessageRecipientForm::TYPE_DYNAMIC_TRIGGERED_MODEL_RELATION, 'audienceType' => EmailMessageRecipient::TYPE_TO, 'relation' => 'contacts'));
     $emailMessageForm->setAttributes(array(EmailMessageForWorkflowForm::EMAIL_MESSAGE_RECIPIENTS => $recipients));
     $workflow->addEmailMessage($emailMessageForm);
     $model = new Account();
     $model->name = 'the account';
     $contact = new Contact();
     $contact->firstName = 'Jason';
     $contact->lastName = 'Blue';
     $contact->state = ContactsUtil::getStartingState();
     $contact->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact->save());
     $contact2 = new Contact();
     $contact2->firstName = 'Laura';
     $contact2->lastName = 'Blue';
     $contact2->state = ContactsUtil::getStartingState();
     $contact2->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($contact2->save());
     $model->contacts->add($contact);
     $model->contacts->add($contact2);
     $this->assertTrue($model->save());
     WorkflowEmailMessagesUtil::processAfterSave($workflow, $model, Yii::app()->user->userModel);
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $queuedEmailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals(1, count($queuedEmailMessages));
     $this->assertEquals(2, count($queuedEmailMessages[0]->recipients));
     $this->assertEquals('Jason Blue', $queuedEmailMessages[0]->recipients[0]->toName);
     $this->assertEquals('*****@*****.**', $queuedEmailMessages[0]->recipients[0]->toAddress);
     $this->assertEquals($contact->id, $queuedEmailMessages[0]->recipients[0]->personOrAccount->id);
     $this->assertEquals('Laura Blue', $queuedEmailMessages[0]->recipients[1]->toName);
     $this->assertEquals('*****@*****.**', $queuedEmailMessages[0]->recipients[1]->toAddress);
     $this->assertEquals($contact2->id, $queuedEmailMessages[0]->recipients[1]->personOrAccount->id);
 }
 /**
  * @depends testSuperUserAllSimpleControllerActions
  */
 public function testSuperUserCreateConversation()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $mary = User::getByUsername('mary');
     $accounts = Account::getByName('superAccount');
     $superAccountId = $accounts[0]->id;
     //Confirm no email notifications are sitting in the queue
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     //Test creating conversation via POST, invite Mary
     $conversations = Conversation::getAll();
     $this->assertEquals(0, count($conversations));
     $itemPostData = array('Account' => array('id' => $superAccountId));
     $this->setPostArray(array('ConversationParticipantsForm' => array('itemIds' => $mary->getClassId('Item')), 'ConversationItemForm' => $itemPostData, 'Conversation' => array('subject' => 'TestSubject', 'description' => 'TestDescription')));
     $this->runControllerWithRedirectExceptionAndGetContent('conversations/default/create');
     //Confirm conversation saved.
     $conversations = Conversation::getAll();
     $this->assertEquals(1, count($conversations));
     //Confirm conversation is connected to the related account.
     $this->assertEquals(1, $conversations[0]->conversationItems->count());
     $this->assertEquals($accounts[0], $conversations[0]->conversationItems->offsetGet(0));
     //Confirm Mary is invited.
     $this->assertEquals(1, $conversations[0]->conversationParticipants->count());
     $this->assertEquals($mary, $conversations[0]->conversationParticipants->offsetGet(0)->person);
     $this->assertEquals(0, $conversations[0]->conversationParticipants->offsetGet(0)->hasReadLatest);
     //Confirm Mary got the email invite and it was correctly setup with a valid conversation id
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals(1, count($emailMessages));
     $this->assertNotContains('conversations/default/details?id=' . $conversations[0]->id . '">', $emailMessages[0]->content->textContent);
     //Confirm Mary is the only one with explicit permissions on the conversation
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($conversations[0]);
     $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables();
     $this->assertEquals(1, count($readWritePermitables));
     $this->assertTrue(isset($readWritePermitables[$mary->getClassId('Permitable')]));
 }
 public function testGetAllByFolderExcludedPausedCampaignMessages()
 {
     $countBefore = EmailMessage::getCount();
     $job = new CampaignQueueMessagesInOutboxJob();
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01');
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
     $campaign = CampaignTestHelper::createCampaign('campaign 01', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, 0, $marketingList);
     $processed = 0;
     CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     $this->assertTrue($job->run());
     $campaignItems = CampaignItem::getAll();
     $this->assertCount(1, $campaignItems);
     $campaignItemsProcessed = CampaignItem::getByProcessedAndCampaignId(1, $campaign->id);
     $this->assertCount(1, $campaignItemsProcessed);
     $countAfter = EmailMessage::getCount();
     $this->assertEquals($countAfter, $countBefore + 1);
     $outboxCount = count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX));
     $outboxNonPausedCount = count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX, true));
     $this->assertEquals($outboxCount, $outboxNonPausedCount);
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     $outboxCount = count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX));
     $outboxNonPausedCount = count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX, true));
     $this->assertEquals($outboxCount, $outboxNonPausedCount + 1);
 }
Beispiel #10
0
 /**
  * @depends testMultipleRecipientsAndTypes
  */
 public function testQueuedEmailsWhenEmailMessageChangeToSentFolder()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount());
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX);
     $this->assertEquals(2, count($emailMessages));
     $emailMessages[0]->folder->type = EmailFolder::TYPE_OUTBOX;
     $emailMessages[1]->folder->type = EmailFolder::TYPE_OUTBOX;
     $emailMessageId = $emailMessages[0]->id;
     $sent = Yii::app()->emailHelper->sendQueued();
     $this->assertTrue($sent);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, count(EmailMessage::getAllByFolderType(EmailFolder::TYPE_OUTBOX)));
     $emailMessages = EmailMessage::getAllByFolderType(EmailFolder::TYPE_SENT);
     $this->assertEquals(2, count($emailMessages));
     $this->assertEquals($emailMessageId, $emailMessages[0]->id);
 }