/** * 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 = '*****@*****.**'; $sender->fromName = 'Zurmo System'; $sender->personOrAccount = $super; $emailMessage->sender = $sender; //Recipient is billy. $recipient = new EmailMessageRecipient(); $recipient->toAddress = '*****@*****.**'; $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'); }
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 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); }
/** * 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 = '*****@*****.**'; $sender->fromName = 'Zurmo System'; $emailMessage->sender = $sender; //Recipient is billy. $recipient = new EmailMessageRecipient(); $recipient->toAddress = '*****@*****.**'; $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())); }
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); }
public function testProjectNotifications() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $super->primaryEmail->emailAddress = '*****@*****.**'; $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); }
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()); }
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); }
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); }
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 = '*****@*****.**'; // 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 $this->assertEquals(5, EmailMessage::getCount()); $this->assertEquals(5, EmailHelper::getQueuedCount()); // Run ProcessOutboundEmail $job = new ProcessOutboundEmailJob(); $this->assertTrue($job->run()); // Ensure all email were sent $this->assertEquals(5, EmailMessage::getCount()); $this->assertEquals(0, EmailHelper::getQueuedCount()); foreach (EmailMessage::getAll() as $emailMessage) { $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT); } // Ensure campaign status $campaign = Campaign::getById($campaignId); $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status); // end of Run 1 // Run 2 starts here // Pause the campaign $campaign->status = Campaign::STATUS_PAUSED; $this->assertTrue($campaign->save()); // ensure campaign items are still there $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId); $this->assertCount(5, $campaignItems); $this->assertNotEmpty($campaignItems); // Unpause campaign $campaign = Campaign::getById($campaignId); $this->assertEquals(Campaign::STATUS_PAUSED, $campaign->status); $campaign->status = Campaign::STATUS_ACTIVE; $this->assertTrue($campaign->save()); // ensure campaign items are still there $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId); $this->assertCount(5, $campaignItems); $this->assertNotEmpty($campaignItems); // Ensure status change $campaign = Campaign::getById($campaignId); $this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status); // Run CampaignGenerateDueCampaignItemsJob $job = new CampaignGenerateDueCampaignItemsJob(); $this->assertTrue($job->run()); // Ensure campaign status change $campaign = Campaign::getById($campaignId); $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status); // ensure all 5 (previously created in run1) campaign items are still processed $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $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 (previously created in run1) campaign items are still processed $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId); $this->assertNotEmpty($campaignItems); $this->assertCount(5, $campaignItems); // Ensure all 5 (previously created and sent in run1) emails are sent. $this->assertEquals(5, EmailMessage::getCount()); foreach (EmailMessage::getAll() as $emailMessage) { $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT); } // Run ProcessOutboundEmail $job = new ProcessOutboundEmailJob(); $this->assertTrue($job->run()); // Ensure all 5 (previously created and sent in run1) emails are sent. $this->assertEquals(5, EmailMessage::getCount()); foreach (EmailMessage::getAll() as $emailMessage) { $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT); } // Ensure campaign status $campaign = Campaign::getById($campaignId); $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status); // end of Run 2 // Run 3 starts here // Run CampaignMarkCompleted $job = new CampaignMarkCompletedJob(); $this->assertTrue($job->run()); // Ensure campaign status change $campaign = Campaign::getById($campaignId); $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign->status); // end of Run 3 }
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(); } }
/** * 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)); }
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 = '*****@*****.**'; $steven->primaryEmail->emailAddress = '*****@*****.**'; $jack->primaryEmail->emailAddress = '*****@*****.**'; $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)); }
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; }
/** * @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); }
public function testMakeMonitorStuckJobNotification() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $super->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($super->save()); $notificationInitalCount = Notification::getCount(); $emailMessageInitialCount = EmailMessage::getCount(); JobsManagerUtil::makeMonitorStuckJobNotification(); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount($emailMessageInitialCount + 1, $notifications); $this->assertCount($notificationInitalCount + 1, $emailMessages); $this->assertEquals('The monitor job is stuck.', $notifications[0]->notificationMessage->htmlContent); $this->assertEquals('The monitor job is stuck.', $notifications[0]->notificationMessage->textContent); $this->assertContains('The monitor job is stuck.', $emailMessages[0]->content->htmlContent); $this->assertContains('The monitor job is stuck.', $emailMessages[0]->content->textContent); }
/** * @depends testCreateAndSendEmailMessageWithAttachment */ public function testMultipleRecipientsAndTypes() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $billy = User::getByUsername('billy'); $jane = User::getByUsername('jane'); $sally = User::getByUsername('sally'); $jason = User::getByUsername('jason'); $this->assertEquals(3, count(EmailMessage::getAll())); $emailMessage = new EmailMessage(); $emailMessage->owner = $jane; $emailMessage->subject = 'My Third Email'; //Attempt to save without setting required information $saved = $emailMessage->save(); $this->assertFalse($saved); $compareData = array('folder' => array('name' => array('Name cannot be blank.'), 'emailBox' => array('name' => array('Name cannot be blank.'))), 'sender' => array('fromAddress' => array('From Address cannot be blank.'))); $this->assertEquals($compareData, $emailMessage->getErrors()); //Set sender, and recipient, and content $emailContent = new EmailMessageContent(); $emailContent->textContent = 'My Third Message'; $emailMessage->content = $emailContent; //Sending from jane $sender = new EmailMessageSender(); $sender->fromAddress = '*****@*****.**'; $sender->fromName = 'Jane Smith'; $sender->personOrAccount = $jane; $emailMessage->sender = $sender; //Recipient is billy. $recipient = new EmailMessageRecipient(); $recipient->toAddress = '*****@*****.**'; $recipient->toName = 'Billy James'; $recipient->type = EmailMessageRecipient::TYPE_TO; $recipient->personOrAccount = $billy; $emailMessage->recipients->add($recipient); //CC recipient is Sally $recipient = new EmailMessageRecipient(); $recipient->toAddress = '*****@*****.**'; $recipient->toName = 'Sally Pail'; $recipient->type = EmailMessageRecipient::TYPE_CC; $recipient->personOrAccount = $sally; $emailMessage->recipients->add($recipient); //BCC recipient is Jason $recipient = new EmailMessageRecipient(); $recipient->toAddress = '*****@*****.**'; $recipient->toName = 'Jason Blue'; $recipient->type = EmailMessageRecipient::TYPE_BCC; $recipient->personOrAccount = $jason; $emailMessage->recipients->add($recipient); //At this point the message is not in a folder. $this->assertTrue($emailMessage->folder->id < 0); $box = EmailBox::resolveAndGetByName('JaneBox'); $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); //Now send the message. Yii::app()->emailHelper->send($emailMessage); }
public function testSuperUserCreateMessageAndViewDetails() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); Yii::app()->emailHelper->outboundHost = 'temporaryForTesting'; $superContactId = self::getModelIdByModelNameAndName('Contact', 'superContact superContactson'); $contact = Contact::getById($superContactId); //Just going to compose without coming from any specific record $this->resetGetArray(); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/createEmailMessage'); //Go to compose without the email address set but the contact set $this->setGetArray(array('relatedId' => $superContactId, 'relatedModelClassName' => 'Contact')); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/createEmailMessage'); //Go to compose with the email address set and the contact set $this->setGetArray(array('toAddress' => '*****@*****.**', 'relatedId' => $superContactId, 'relatedModelClassName' => 'Contact')); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/createEmailMessage'); //confirm there are no email messages currently $this->assertEquals(0, EmailMessage::getCount()); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //Test create email with invalid form $createEmailMessageFormData = array('recipientsData' => array('to' => '*****@*****.**'), 'subject' => '', 'content' => ''); $this->setPostArray(array('ajax' => 'edit-form', 'CreateEmailMessageForm' => $createEmailMessageFormData)); $content = $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/createEmailMessage'); //Confirm that error messages are displayed $this->assertContains(Zurmo::t('emailMessagesModule', 'Subject cannot be blank.'), $content); //Confirm that no email messages was sent $this->assertEquals(0, EmailMessage::getCount()); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //Validate form $createEmailMessageFormData = array('recipientsData' => array('to' => '*****@*****.**'), 'subject' => 'test subject', 'content' => array('htmlContent' => '<p>html body content</p>')); $this->setGetArray(array('toAddress' => '*****@*****.**', 'relatedId' => $superContactId, 'relatedModelClassName' => 'Contact')); $this->setPostArray(array('ajax' => 'edit-form', 'CreateEmailMessageForm' => $createEmailMessageFormData)); $this->runControllerWithExitExceptionAndGetContent('emailMessages/default/createEmailMessage'); //create email message $this->setGetArray(array('toAddress' => '*****@*****.**', 'relatedId' => $superContactId, 'relatedModelClassName' => 'Contact')); $this->setPostArray(array('CreateEmailMessageForm' => $createEmailMessageFormData)); $this->runControllerWithNoExceptionsAndGetContent('emailMessages/default/createEmailMessage', true); //confirm there is one email $this->assertEquals(1, EmailMessage::getCount()); $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //To address must be the one in postArray $emailMessages = EmailMessage::getAll(); $this->assertEquals('*****@*****.**', $emailMessages[0]->recipients[0]->toAddress); //Test the default permission was setted $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME); $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessages[0]); $readWritePermitables = $explicitReadWriteModelPermissions->getReadWritePermitables(); $this->assertEquals($everyoneGroup, $readWritePermitables[$everyoneGroup->getClassId('Permitable')]); }
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()); //Confirm there is no inbox notification $this->assertEquals(0, Notification::getCount()); //No message was sent because Steven and Jack don't have primary email address CommentsUtil::sendNotificationOnNewComment($conversation, $comment, array($steven, $jack)); $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //Two inbox notifications sent $this->assertEquals(2, Notification::getCount()); $super->primaryEmail->emailAddress = '*****@*****.**'; $steven->primaryEmail->emailAddress = '*****@*****.**'; $jack->primaryEmail->emailAddress = '*****@*****.**'; $this->assertTrue($super->save()); $this->assertTrue($steven->save()); $this->assertTrue($jack->save()); //Two email message were sent one to Steven and one to Jack CommentsUtil::sendNotificationOnNewComment($conversation, $comment, array($steven, $jack)); $this->assertEquals(2, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage1 = $emailMessages[0]; $emailMessage2 = $emailMessages[1]; $this->assertCount(1, $emailMessage1->recipients); $this->assertCount(1, $emailMessage2->recipients); //Two inbox notifications created $this->assertEquals(4, Notification::getCount()); //One email message was sent to Super but not to Steven //One inbox notification to Steven but not to Super NotificationTestHelper::setNotificationSettingsForUser($steven, 'ConversationNewComment', true, false); NotificationTestHelper::setNotificationSettingsForUser($super, 'ConversationNewComment', false, true); CommentsUtil::sendNotificationOnNewComment($conversation, $comment, array($steven, $super)); $this->assertEquals(3, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[2]; $this->assertEquals(1, count($emailMessage->recipients)); $this->assertEquals(5, Notification::getCount()); $notifications = Notification::getAll(); $notification = $notifications[4]; $this->assertEquals(strval($steven), strval($notification->owner)); }
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); } }
/** * @depends testClosingConversations */ public function testSendEmailInNewComment() { if (!SECURITY_OPTIMIZED) { return; } $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $steven = User::getByUsername('steven'); $sally = User::getByUsername('sally'); $mary = User::getByUsername('mary'); $conversations = Conversation::getAll(); $this->assertEquals(2, count($conversations)); $this->assertEquals(0, $conversations[0]->comments->count()); foreach (EmailMessage::getAll() as $emailMessage) { $emailMessage->delete(); } $initialQueued = 0; $conversation = $conversations[0]; $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $steven; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $sally; $conversation->conversationParticipants->add($conversationParticipant); $conversationParticipant = new ConversationParticipant(); $conversationParticipant->person = $mary; $conversation->conversationParticipants->add($conversationParticipant); $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser(); $inboxAndEmailNotificationSettings['enableConversationNewCommentNotification'] = array('inbox' => false, 'email' => false); UserNotificationUtil::setValue($mary, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false); //Save a new comment $this->setGetArray(array('relatedModelId' => $conversation->id, 'relatedModelClassName' => 'Conversation', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name'))); $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $this->assertEquals(1, $conversation->comments->count()); $this->assertEquals($initialQueued + 2, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[$initialQueued]; $this->assertEquals(1, count($emailMessage->recipients)); $emailMessage = $emailMessages[$initialQueued + 1]; $this->assertEquals(1, count($emailMessage->recipients)); $this->assertContains('conversation', $emailMessage->subject); $this->assertContains(strval($conversation), $emailMessage->subject); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->htmlContent); $this->assertContains(strval($conversation->comments[0]), $emailMessage->content->textContent); }
/** * @depends testResolveConversationParticipants */ public function testResolveEmailInvitesByPeople() { $this->assertEquals(0, Notification::getCount()); $this->assertEquals(0, EmailMessage::getCount()); $super = Yii::app()->user->userModel; $super->primaryEmail->emailAddress = '*****@*****.**'; NotificationTestHelper::setNotificationSettingsForUser($super, 'ConversationInvites'); $jack = User::getByUsername('jack'); $jack->primaryEmail->emailAddress = '*****@*****.**'; NotificationTestHelper::setNotificationSettingsForUser($jack, 'ConversationInvites', true, false); $steven = User::getByUsername('steven'); $steven->primaryEmail->emailAddress = '*****@*****.**'; NotificationTestHelper::setNotificationSettingsForUser($steven, 'ConversationInvites', false, true); $mary = User::getByUsername('mary'); $mary->primaryEmail->emailAddress = '*****@*****.**'; NotificationTestHelper::setNotificationSettingsForUser($mary, 'ConversationInvites', false, false); $conversation = new Conversation(); $conversation->owner = $super; $conversation->subject = 'Test Resolve Conversation Participants'; $conversation->description = 'This is for testing conversation participants.'; $this->assertTrue($conversation->save()); ConversationParticipantsUtil::resolveEmailInvitesByPeople($conversation, array($super, $jack, $steven, $mary)); $this->assertEquals(2, Notification::getCount()); $notifications = Notification::getAll(); $this->assertContains('<h2 class="h2">Join the Conversation</h2>Clark Kent would like you to join a conversation <strong>"Test Resolve Conversation Participants"</strong><br/>', $notifications[0]->notificationMessage->htmlContent); $this->assertContains('Clark Kent would like you to join a conversation "Test Resolve Conversation Participants"', $notifications[0]->notificationMessage->textContent); $this->assertEquals(2, EmailMessage::getCount()); $emailMessages = EmailMessage::getAll(); $this->assertContains('<h2 class="h2">Join the Conversation</h2>Clark Kent would like you to join a conversation <strong>"Test Resolve Conversation Participants"</strong><br/>', $emailMessages[0]->content->htmlContent); $this->assertContains('Powered By <a href="http://www.zurmo.com">Zurmo</a>', $emailMessages[0]->content->htmlContent); $this->assertContains('Clark Kent would like you to join a conversation "Test Resolve Conversation Participants"', $emailMessages[0]->content->textContent); $this->assertContains('Manage your email preferences', $emailMessages[0]->content->textContent); $this->assertEquals('You have been invited to participate in a conversation', $emailMessages[0]->subject); }
public function testTaskNotifications() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $userOwner = UserTestHelper::createBasicUserWithEmailAddress('TaskUserOwner'); $userRequester = UserTestHelper::createBasicUserWithEmailAddress('TaskUserRequester'); Notification::deleteAll(); EmailMessage::deleteAll(); $dueStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 10000); $completedStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() + 9000); $task = new Task(); $task->name = 'Task for Notifications Test'; $task->owner = $userOwner; $task->requestedByUser = $userRequester; $task->dueDateTime = $dueStamp; $task->completedDateTime = $completedStamp; $task->description = 'my test description'; $task->status = Task::STATUS_NEW; $this->assertTrue($task->save()); //New task notification owned by other $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(1, $notifications); $this->assertCount(1, $emailMessages); $this->assertContains("The task, 'Task for Notifications Test', is now owned by you.", $notifications[0]->notificationMessage->textContent); $this->assertContains("The task, 'Task for Notifications Test', is now owned by you.", $emailMessages[0]->content->textContent); //Deliver task notification $task->status = TASK::STATUS_AWAITING_ACCEPTANCE; $task->save(); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(2, $notifications); $this->assertCount(2, $emailMessages); $this->assertContains("The task you requested, 'Task for Notifications Test', has been finished. You can now choose to accept or reject the task.", $notifications[1]->notificationMessage->textContent); $this->assertContains("The task you requested, 'Task for Notifications Test', has been finished. You can now choose to accept or reject the task.", $emailMessages[1]->content->textContent); //Reject task notification $task->status = TASK::STATUS_REJECTED; $task->save(); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(3, $notifications); $this->assertCount(3, $emailMessages); $this->assertContains("The task, 'Task for Notifications Test', has been rejected by Clark Kent.", $notifications[2]->notificationMessage->textContent); $this->assertContains("The task, 'Task for Notifications Test', has been rejected by Clark Kent.", $emailMessages[2]->content->textContent); //Accept task notification $task->status = TASK::STATUS_COMPLETED; $task->save(); $notifications = Notification::getAll(); $emailMessages = EmailMessage::getAll(); $this->assertCount(4, $notifications); $this->assertCount(4, $emailMessages); $this->assertContains("The task, 'Task for Notifications Test', was accepted by Clark Kent.", $notifications[3]->notificationMessage->textContent); $this->assertContains("The task, 'Task for Notifications Test', was accepted by Clark Kent.", $emailMessages[3]->content->textContent); }
/** * @depends testAjaxChangeStatus */ public function testSendEmailInNewComment() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $mary = User::getByUsername('mary'); $missions = Mission::getAll(); $this->assertEquals(1, count($missions)); $mission = $missions[0]; $this->assertEquals(0, $mission->comments->count()); foreach (EmailMessage::getAll() as $emailMessage) { $emailMessage->delete(); } $messageCount = 0; $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); //Save new comment. $this->setGetArray(array('relatedModelId' => $mission->id, 'relatedModelClassName' => 'Mission', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'a ValidComment Name'))); $content = $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $this->assertEquals(1, $mission->comments->count()); $this->assertEquals($messageCount + 1, Yii::app()->emailHelper->getQueuedCount()); $this->assertEquals(0, Yii::app()->emailHelper->getSentCount()); $emailMessages = EmailMessage::getAll(); $emailMessage = $emailMessages[$messageCount]; $this->assertEquals(1, count($emailMessage->recipients)); $this->assertContains('mission', $emailMessage->subject); $this->assertContains(strval($mission), $emailMessage->subject); $this->assertContains(strval($mission->comments[0]), $emailMessage->content->htmlContent); $this->assertContains(strval($mission->comments[0]), $emailMessage->content->textContent); }
/** * Test Case: email from User to Contact and CC to another Contact and BCC archive. * Expected Behavior: Email is archived to both contact records. */ public function testCase6B() { EmailMessage::deleteAll(); $imapMessage = new ImapMessage(); $imapMessage->fromName = 'steve'; $imapMessage->fromEmail = self::$user->primaryEmail->emailAddress; $imapMessage->senderEmail = self::$user->primaryEmail->emailAddress; $imapMessage->to = array(array('name' => self::$contact1->firstName, 'email' => self::$contact1->primaryEmail->emailAddress)); $imapMessage->cc = array(array('name' => self::$contact2->firstName, 'email' => self::$contact2->primaryEmail->emailAddress)); $imapMessage->subject = "Test Email 6b"; $imapMessage->htmlBody = "<strong>Email</strong> from Steve 6b"; $imapMessage->textBody = "Email from Steve 6b"; $emailArchivingJob = new EmailArchivingJob(); $result = $emailArchivingJob->saveEmailMessage($imapMessage); $this->assertTrue($result); $emailMessages = EmailMessage::getAll(); $this->assertEquals(1, count($emailMessages)); $emailMessage = $emailMessages[0]; $this->assertEquals($imapMessage->subject, $emailMessage->subject); $this->assertEquals($imapMessage->textBody, trim($emailMessage->content->textContent)); $this->assertEquals($imapMessage->htmlBody, trim($emailMessage->content->htmlContent)); $this->assertEquals(self::$user->primaryEmail->emailAddress, $emailMessage->sender->fromAddress); $this->assertEquals(2, count($emailMessage->recipients)); $this->assertEquals(self::$contact1->primaryEmail->emailAddress, $emailMessage->recipients[0]->toAddress); $this->assertEquals(EmailMessageRecipient::TYPE_TO, $emailMessage->recipients[0]->type); $this->assertEquals(self::$contact2->primaryEmail->emailAddress, $emailMessage->recipients[1]->toAddress); $this->assertEquals(EmailMessageRecipient::TYPE_CC, $emailMessage->recipients[1]->type); $this->assertEquals(EmailFolder::TYPE_ARCHIVED, $emailMessage->folder->type); }
public function testRedeemReward() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $super->primaryEmail->emailAddress = '*****@*****.**'; $super->save(); Yii::app()->user->userModel = $super; $gameRewards = GameReward::getByName('myNewGameReward'); //not enough coins $this->setGetArray(array('id' => $gameRewards[0]->id)); $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward'); $this->assertContains('You do not have enough coins to redeem this reward', $content); //enough coins $gameCoin = new GameCoin(); $gameCoin->person = $super; $gameCoin->value = 100; $this->assertTrue($gameCoin->save()); $notifications = Notification::getAll(); //check for no notification $this->assertEquals(0, EmailMessage::getCount()); $this->assertEquals(0, count($notifications)); $this->setGetArray(array('id' => $gameRewards[0]->id)); $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward'); $this->assertContains('myNewGameReward has been redeemed.', $content); //check for notification $notifications = Notification::getAll(); $this->assertEquals(1, count($notifications)); //email content $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $notifications[0]->notificationMessage->htmlContent); //check url $this->assertContains('/gameRewards/default/details?id=13', $notifications[0]->notificationMessage->htmlContent); // Not Coding Standard //check for email notification $emailMessages = EmailMessage::getAll(); $this->assertCount(1, $emailMessages); $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->htmlContent); $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->textContent); }
/** * Check if only new messages are pulled from dropdown * Also check case if message will be matched with user 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(); $john = User::getByUsername('john'); $john->primaryEmail->emailAddress = Yii::app()->params['emailTestAccounts']['testEmailAddress']; $this->assertTrue($john->save()); $messages = EmailMessage::getAll(); foreach ($messages as $message) { $message->delete(); } Yii::app()->imap->deleteMessages(true); // Check if there are no emails in dropbox $job = new EmailArchivingJob(); $this->assertTrue($job->run()); $this->assertEquals(0, count(EmailMessage::getAll())); $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, count(EmailMessage::getAll())); $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)); foreach ($emailMessage->recipients as $recipient) { $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, count(EmailMessage::getAll())); $this->assertEquals(1, Notification::getCountByTypeAndUser('EmailMessageArchivingEmailAddressNotMatching', $user)); }