本文整理汇总了PHP中EmailMessage::getAll方法的典型用法代码示例。如果您正苦于以下问题:PHP EmailMessage::getAll方法的具体用法?PHP EmailMessage::getAll怎么用?PHP EmailMessage::getAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EmailMessage
的用法示例。
在下文中一共展示了EmailMessage::getAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRenderSummaryContentWithEmailMessage
/**
* Testing that each model type can render properly and does not throw an exception
*/
public function testRenderSummaryContentWithEmailMessage()
{
$super = User::getByUsername('super');
$billy = User::getByUsername('billy');
$this->assertEquals(0, count(EmailMessage::getAll()));
$emailMessage = new EmailMessage();
$emailMessage->owner = BaseControlUserConfigUtil::getUserToRunAs();
$emailMessage->subject = 'My First Email';
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending from the system, does not have a 'person'.
$sender = new EmailMessageSender();
$sender->fromAddress = 'system@somewhere.com';
$sender->fromName = 'Zurmo System';
$sender->personOrAccount = $super;
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personOrAccount = $billy;
$emailMessage->recipients->add($recipient);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
$saved = $emailMessage->save();
$this->assertTrue($saved);
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'HomeModule');
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'UserModule');
$content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'UserModule');
}
示例2: testRun
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);
}
示例3: testRun
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);
}
示例4: testCreateEmailMessageThatIsANotification
/**
* A notification email is different than a regular outbound email because it is owned by a super user
* that is different than the user logged in. So the sender does not have a 'person'
*/
public function testCreateEmailMessageThatIsANotification()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$billy = User::getByUsername('billy');
$this->assertEquals(0, count(EmailMessage::getAll()));
$emailMessage = new EmailMessage();
$emailMessage->owner = BaseJobControlUserConfigUtil::getUserToRunAs();
$emailMessage->subject = 'My First Email';
//Set sender, and recipient, and content
$emailContent = new EmailMessageContent();
$emailContent->textContent = 'My First Message';
$emailContent->htmlContent = 'Some fake HTML content';
$emailMessage->content = $emailContent;
//Sending from the system, does not have a 'person'.
$sender = new EmailMessageSender();
$sender->fromAddress = 'system@somewhere.com';
$sender->fromName = 'Zurmo System';
$emailMessage->sender = $sender;
//Recipient is billy.
$recipient = new EmailMessageRecipient();
$recipient->toAddress = 'billy@fakeemail.com';
$recipient->toName = 'Billy James';
$recipient->type = EmailMessageRecipient::TYPE_TO;
$recipient->personOrAccount = $billy;
$emailMessage->recipients->add($recipient);
//At this point the message is in no folder
$this->assertTrue($emailMessage->folder->id < 0);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
//Save, at this point the email should be in the draft folder
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertTrue($emailMessage->folder->id > 0);
$this->assertEquals(0, count(EmailMessageSendError::getAll()));
$emailMessageSendError = new EmailMessageSendError();
$data = array();
$data['message'] = 'error message';
$emailMessageSendError->serializedData = serialize($data);
$emailMessage->folder = EmailFolder::getByBoxAndType($emailMessage->folder->emailBox, EmailFolder::TYPE_OUTBOX_ERROR);
$emailMessage->error = $emailMessageSendError;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertEquals(1, count(EmailMessageSendError::getAll()));
//Now swap the error with a new one
$emailMessageId = $emailMessage->id;
$emailMessage->forget();
$emailMessage = EmailMessage::getById($emailMessageId);
$emailMessageSendError = new EmailMessageSendError();
$data = array();
$data['message'] = 'error message 2';
$emailMessageSendError->serializedData = serialize($data);
$emailMessage->error = $emailMessageSendError;
$saved = $emailMessage->save();
$this->assertTrue($saved);
$this->assertEquals(1, count(EmailMessageSendError::getAll()));
}
示例5: testRun
public function testRun()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$this->assertEquals(0, EmailMessage::getCount());
$job = new TestOutboundEmailJob();
$this->assertTrue($job->run());
$emailMessages = EmailMessage::getAll();
$this->assertEquals(1, count($emailMessages));
$this->assertEquals(EmailFolder::TYPE_SENT, $emailMessages[0]->folder->type);
}
示例6: testProjectNotifications
public function testProjectNotifications()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$super->primaryEmail->emailAddress = 'super@zurmo.com';
$super->save();
Yii::app()->user->userModel = $super;
$user = UserTestHelper::createBasicUser('ProjectUser');
Notification::deleteAll();
EmailMessage::deleteAll();
$project = new Project();
$project->name = 'Project For Notifications Test';
$project->owner = $super;
$project->description = 'Description';
$this->assertTrue($project->save());
//New project notification
$notifications = Notification::getAll();
$emailMessages = EmailMessage::getAll();
$this->assertCount(1, $notifications);
$this->assertCount(1, $emailMessages);
$this->assertContains("The project, 'Project For Notifications Test', is now owned by you.", $notifications[0]->notificationMessage->textContent);
$this->assertContains("The project, 'Project For Notifications Test', is now owned by you.", $emailMessages[0]->content->textContent);
//Project archived notification
$project->status = Project::STATUS_ARCHIVED;
$this->assertTrue($project->save());
$notifications = Notification::getAll();
$emailMessages = EmailMessage::getAll();
$this->assertCount(2, $notifications);
$this->assertCount(2, $emailMessages);
$this->assertContains("The project, 'Project For Notifications Test', is now archived.", $notifications[1]->notificationMessage->textContent);
$this->assertContains("The project, 'Project For Notifications Test', is now archived.", $emailMessages[1]->content->textContent);
}
示例7: testAfterSaveForImportModel
public function testAfterSaveForImportModel()
{
$testUser = UserTestHelper::createBasicUserWithEmailAddress('jimmy');
UserConfigurationFormAdapter::setValue($testUser, false, 'turnOffEmailNotifications');
Yii::app()->user->userModel = User::getByUsername('super');
$this->assertCount(0, EmailMessage::getAll());
$task = new Task();
$task->name = 'MyTaskWithoutImport';
$task->owner = $testUser;
$task->requestedByUser = Yii::app()->user->userModel;
$this->assertTrue($task->save());
$this->assertEquals(2, count($task->notificationSubscribers));
$this->assertCount(1, EmailMessage::getAll());
//With import
$task = new Task();
$task->setScenario('importModel');
$task->name = 'MyTaskWithImport';
$task->owner = $testUser;
$task->requestedByUser = Yii::app()->user->userModel;
$this->assertTrue($task->save());
$this->assertEquals(2, count($task->notificationSubscribers));
$this->assertCount(1, EmailMessage::getAll());
}
示例8: testProcessAfterSaveWhenSendIsImmediateAndToAContactThatIsRelatedToTheTriggeredModel
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 = 'jason@something.com';
$this->assertTrue($contact->save());
$contact2 = new Contact();
$contact2->firstName = 'Laura';
$contact2->lastName = 'Blue';
$contact2->state = ContactsUtil::getStartingState();
$contact2->primaryEmail->emailAddress = 'laura@something.com';
$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('jason@something.com', $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('laura@something.com', $queuedEmailMessages[0]->recipients[1]->toAddress);
$this->assertEquals($contact2->id, $queuedEmailMessages[0]->recipients[1]->personOrAccount->id);
}
示例9: testNewNotificationWhenProjectIsArchived
public function testNewNotificationWhenProjectIsArchived()
{
$project = new Project();
$project->name = 'project-' . __FUNCTION__;
$project->owner = self::$steve;
$project->status = Project::STATUS_ARCHIVED;
$this->assertEquals(0, EmailMessage::getCount());
$this->assertEquals(0, Notification::getCount());
ProjectsNotificationUtil::submitProjectNotificationMessage($project, ProjectAuditEvent::PROJECT_ARCHIVED);
$emailMessages = EmailMessage::getAll();
$notifications = Notification::getAll();
$this->assertCount(1, $emailMessages);
$this->assertCount(1, $notifications);
$this->assertEquals('PROJECT: project-' . __FUNCTION__, $emailMessages[0]->subject);
$this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $emailMessages[0]->content->textContent);
$this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $emailMessages[0]->content->htmlContent);
$this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $notifications[0]->notificationMessage->textContent);
$this->assertContains("The project, 'project-" . __FUNCTION__ . "', is now archived.", $notifications[0]->notificationMessage->htmlContent);
}
示例10: testRunWithCampaignPausedAfterAllItemsGeneratedAndThenUnpaused
public function testRunWithCampaignPausedAfterAllItemsGeneratedAndThenUnpaused()
{
// Cleanup
Campaign::deleteAll();
$this->assertEquals(0, Campaign::getCount());
$this->assertEquals(0, CampaignItem::getCount());
$this->assertEquals(0, CampaignItemActivity::getCount());
MarketingList::deleteAll();
$this->assertEquals(0, MarketingList::getCount());
$this->assertEquals(0, MarketingListMember::getCount());
EmailMessage::deleteAll();
$this->assertEquals(0, EmailMessage::getCount());
$this->assertEquals(0, EmailMessageContent::getCount());
$this->assertEquals(0, EmailMessageSender::getCount());
$this->assertEquals(0, EmailMessageRecipient::getCount());
Contact::deleteAll();
$this->assertEquals(0, Contact::getCount());
// setup an email address for contacts
$email = new Email();
$email->emailAddress = 'demo@zurmo.com';
// create a marketing list with 5 members
$marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05');
$marketingListId = $marketingList->id;
for ($i = 1; $i <= 5; $i++) {
$contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $i, $this->user);
$contact->primaryEmail = $email;
$this->assertTrue($contact->save());
MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
}
$marketingList->forgetAll();
// create a due campaign with that marketing list
$campaign = CampaignTestHelper::createCampaign('campaign 04', 'subject', 'text Content', 'Html Content', null, null, null, null, null, null, MarketingList::getById($marketingListId));
$campaignId = $campaign->id;
/*
* Run 1:
* CampaignGenerateDueCampaignItemsJob
* status == processing
* items generated but unprocessed
*
* CampaignQueueMessagesInOutboxJob
* status == processing
* items processed with email messages generated and queued
*
* ProcessOutboundEmailJob
* status == processing
* email items attempted to be sent
*
* Run 2:
* Pause the campaign
* items are processed and still present
*
* Unpause the campaign
* status == active
* items are processed and still present
*
* CampaignGenerateDueCampaignItemsJob
* status == processing
* ensure all items are present and processed
*
* CampaignQueueMessagesInOutboxJob
* status == processing
* ensure all items are present and processed
* ensure all email messages are present with correct folder type
*
* ProcessOutboundEmailJob
* ensure all email messages are present with correct folder type
* status == processing
*
*
* Run 3:
* Mark Campaign as Completed
* status == completed
*/
// we have to do this to ensure when we retrieve the data status is updated from db.
$campaign->forgetAll();
$this->assertEmpty(CampaignItem::getAll());
// Run 1 starts here
// Run CampaignGenerateDueCampaignItemsJob
$job = new CampaignGenerateDueCampaignItemsJob();
$this->assertTrue($job->run());
$campaign = Campaign::getById($campaignId);
// ensure status is processing
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
// ensure 5 campaign items have been generated
$this->assertEquals(5, CampaignItem::getCount());
// ensure all 5 campaign items are unprocessed
$campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
// Run CampaignQueueMessagesInOutboxJob
$job = new CampaignQueueMessagesInOutboxJob();
$this->assertTrue($job->run());
// Ensure campaign status
$campaign = Campaign::getById($campaignId);
$this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
// ensure all 5 campaign items are processed
$campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
$this->assertNotEmpty($campaignItems);
$this->assertCount(5, $campaignItems);
// Ensure 5 new email messages
//.........这里部分代码省略.........
示例11: clearNotificationsWorkflowsAndEmailMessages
protected function clearNotificationsWorkflowsAndEmailMessages()
{
$notifications = Notification::getAll();
foreach ($notifications as $notification) {
$notification->delete();
}
$emailMessages = EmailMessage::getAll();
foreach ($emailMessages as $emailMessage) {
$emailMessage->delete();
}
$workflows = SavedWorkflow::getAll();
foreach ($workflows as $workflow) {
$workflow->delete();
}
}
示例12: testRunCaseFive
/**
* 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()
{
$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(2, EmailMessage::getCount());
$emailMessages = EmailMessage::getAll();
$emailMessage = $emailMessages[1];
$this->assertEquals('Email from Steve 3', $emailMessage->subject);
$this->assertEquals('Email from Steve', trim($emailMessage->content->textContent));
$this->assertEquals('<!-- zurmo css inline --><strong>Email</strong> from Steve', preg_replace("/\r|\n/", "", $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(2, EmailMessage::getCount());
$this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user));
}
示例13: testsSendNotificationOnNewComment
public function testsSendNotificationOnNewComment()
{
$super = User::getByUsername('super');
$steven = User::getByUsername('steven');
$jack = User::getByUsername('jack');
$conversation = new Conversation();
$conversation->owner = Yii::app()->user->userModel;
$conversation->subject = 'My test subject2';
$conversation->description = 'My test description2';
$this->assertTrue($conversation->save());
$comment = new Comment();
$comment->description = 'This is the 1st test comment';
//Confirm no email notifications are sitting in the queue
$this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
$this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
//No message was sent because Steven and Jack don't have primary email address
CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack));
$this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
$this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
$super->primaryEmail->emailAddress = 'super@zurmo.org';
$steven->primaryEmail->emailAddress = 'steven@zurmo.org';
$jack->primaryEmail->emailAddress = 'jack@zurmo.org';
$this->assertTrue($super->save());
$this->assertTrue($steven->save());
$this->assertTrue($jack->save());
//One email message was sent because to Steven and Jack
CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $super, array($steven, $jack));
$this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
$this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
$emailMessages = EmailMessage::getAll();
$emailMessage = $emailMessages[0];
$this->assertEquals(2, count($emailMessage->recipients));
//One email message was sent to Super but not to Steven
UserConfigurationFormAdapter::setValue($steven, true, 'turnOffEmailNotifications');
CommentsUtil::sendNotificationOnNewComment($conversation, $comment, $jack, array($steven, $super));
$this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount());
$this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
$emailMessages = EmailMessage::getAll();
$emailMessage = $emailMessages[1];
$this->assertEquals(1, count($emailMessage->recipients));
}
示例14: generateAndProcessEmailMessages
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;
}
示例15: testAttemptingToSendEmailNotOutbox
/**
* @depends testAttemptingToSendEmailInOutbox
*/
public function testAttemptingToSendEmailNotOutbox()
{
$this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
$emailMessages = EmailMessage::getAll();
$this->assertEquals(1, count($emailMessages));
//Because it was set to outbox from last test, stil at outbox.
$this->assertTrue($emailMessages[0]->folder->type == EmailFolder::TYPE_OUTBOX);
$box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
$emailMessages[0]->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
$sentOrQueued = Yii::app()->emailHelper->send($emailMessages[0]);
$this->assertTrue($sentOrQueued);
$this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
//The message, because it is queued, should still be in the outbox
$this->assertEquals(EmailFolder::TYPE_OUTBOX, $emailMessages[0]->folder->type);
}