public function testRun()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $outboxFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
     $sentFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage->folder = $outboxFolder;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $emailMessageId = $emailMessage->id;
     $emailMessage->forget();
     unset($emailMessage);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage2->folder = $outboxFolder;
     $saved = $emailMessage2->save();
     $this->assertTrue($saved);
     $emailMessage2Id = $emailMessage2->id;
     $emailMessage2->forget();
     unset($emailMessage2);
     $this->assertEquals(2, EmailMessage::getCount());
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(2, count($emailMessages));
     $emailMessage = EmailMessage::getById($emailMessageId);
     $this->assertEquals($sentFolder, $emailMessage->folder);
     $emailMessage2 = EmailMessage::getById($emailMessage2Id);
     $this->assertEquals($sentFolder, $emailMessage2->folder);
 }
 public function testRun()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     //Create 2 sent notifications, and set one with a date over a week ago (8 days ago) for the modifiedDateTime
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage->folder = $folder;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8);
     $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $emailMessage->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message 2', $super);
     $emailMessage2->folder = $folder;
     $saved = $emailMessage2->save();
     $this->assertTrue($saved);
     $this->assertEquals(2, EmailMessage::getCount());
     $job = new ClearSentNotificationsEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(1, count($emailMessages));
     $this->assertEquals($emailMessage2->id, $emailMessages[0]->id);
 }
 public function testRun()
 {
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('WorkflowsTest2Module');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     //Add action that is missing required owner
     $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relation = 'hasMany2';
     $attributes = array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'lastName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $job = new WorkflowValidityCheckJob();
     $this->assertTrue($job->run());
     $this->assertEquals(1, Notification::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
 /**
  * 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, EmailMessage::getCount());
     $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->personsOrAccounts->add($super);
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($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');
 }
 /**
  * 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, EmailMessage::getCount());
     $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';
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($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, EmailMessageSendError::getCount());
     $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, EmailMessageSendError::getCount());
     //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, EmailMessageSendError::getCount());
 }
 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 testProcessWorkflowAfterSave()
 {
     $model = new WorkflowModelTestItem();
     $event = new CEvent($model);
     $observer = new WorkflowsObserver();
     $observer->setDepth(25);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $observer->processWorkflowAfterSave($event);
     $this->assertEquals(1, Notification::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
 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
 }
 public function testSubmitWithInboxNotificationSettingDisabledAndEmailNotificationSettingDisabled()
 {
     $initialNotificationCount = Notification::getCount();
     $initialEmailMessageCount = EmailMessage::getCount();
     $rules = new SimpleNotificationRules();
     $rules->setAllowDuplicates(true);
     $rules->addUser($this->user);
     $inboxAndEmailNotificationSettings = UserTestHelper::getDefaultNotificationSettingsValuesForTestUser();
     $inboxAndEmailNotificationSettings['enableSimpleNotification']['email'] = false;
     $inboxAndEmailNotificationSettings['enableSimpleNotification']['inbox'] = false;
     UserNotificationUtil::setValue($this->user, $inboxAndEmailNotificationSettings, 'inboxAndEmailNotificationSettings', false);
     $this->assertFalse(UserNotificationUtil::isEnabledByUserAndNotificationNameAndType($this->user, 'enableSimpleNotification', 'email'));
     $this->assertFalse(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, Notification::getCount());
     $this->assertEquals($initialEmailMessageCount, EmailMessage::getCount());
 }
 public function testRunWithMissingTriggerMultiselectPicklistValue()
 {
     $this->clearNotificationsWorkflowsAndEmailMessages();
     $this->createStageValues();
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('bDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('OpportunitiesModule');
     $workflow->setName('mySecondWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     $trigger = new TriggerForWorkflowForm('OpportunitiesModule', 'Opportunity', Workflow::TYPE_ON_SAVE);
     $trigger->attributeIndexOrDerivedType = 'stage';
     $trigger->value = 'Closed Won,Negotiating';
     $trigger->operator = OperatorRules::TYPE_ONE_OF;
     $trigger->relationFilter = TriggerForWorkflowForm::RELATION_FILTER_ANY;
     $workflow->addTrigger($trigger);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $job = new WorkflowValidityCheckJob();
     $this->assertTrue($job->run());
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $this->clearNotificationsWorkflowsAndEmailMessages();
     $workflow = new Workflow();
     $workflow->setDescription('cDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('OpportunitiesModule');
     $workflow->setName('mySecondWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     $trigger = new TriggerForWorkflowForm('OpportunitiesModule', 'Opportunity', Workflow::TYPE_ON_SAVE);
     $trigger->attributeIndexOrDerivedType = 'stage';
     $trigger->value = 'Closed Won,Unexisting state';
     $trigger->operator = OperatorRules::TYPE_BECOMES;
     $trigger->relationFilter = TriggerForWorkflowForm::RELATION_FILTER_ANY;
     $workflow->addTrigger($trigger);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $job = new WorkflowValidityCheckJob();
     $this->assertTrue($job->run());
     $this->assertEquals(1, Notification::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
 /**
  * @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);
 }
Esempio n. 12
0
 /**
  * @depends testExportByModelIds
  */
 public function testExportRedBeanDataProviderWithMultiplePagesOfData()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Disabling email notification
     NotificationTestHelper::setNotificationSettingsForUser($super, 'ExportProcessCompleted', true, false);
     $numberOfUserNotifications = Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel);
     $numberOfEmailMessages = EmailMessage::getCount();
     $account = new Account(false);
     $searchForm = new AccountsSearchForm($account);
     $dataProvider = ExportTestHelper::makeRedBeanDataProvider($searchForm, 'Account', 0, Yii::app()->user->userModel->id);
     $totalItems = $dataProvider->getTotalItemCount();
     $this->assertEquals(4, $totalItems);
     $exportItem = new ExportItem();
     $exportItem->isCompleted = 0;
     $exportItem->exportFileType = 'csv';
     $exportItem->exportFileName = 'test3';
     $exportItem->modelClassName = 'Account';
     $exportItem->serializedData = serialize($dataProvider);
     $this->assertTrue($exportItem->save());
     $id = $exportItem->id;
     $exportItem->forget();
     unset($exportItem);
     ExportModule::$asynchronousPageSize = 2;
     //Delete queued jobs from test exportItems created above
     Yii::app()->jobQueue->deleteAll();
     $job = new ExportJob();
     $this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
     $this->assertTrue($job->run());
     $this->assertEquals(0, count(Yii::app()->jobQueue->getAll()));
     $exportItem = ExportItem::getById($id);
     $fileModel = $exportItem->exportFileModel;
     $this->assertEquals(1, $exportItem->isCompleted);
     $this->assertEquals('csv', $exportItem->exportFileType);
     $this->assertEquals('test3', $exportItem->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     // Get csv string via regular csv export process(directly, not in background)
     // We suppose that csv generated thisway is corrected, this function itself
     // is tested in another test.
     $data = array();
     $rows = $dataProvider->getData();
     $modelToExportAdapter = new ModelToExportAdapter($rows[0]);
     $headerData = $modelToExportAdapter->getHeaderData();
     foreach ($rows as $model) {
         $modelToExportAdapter = new ModelToExportAdapter($model);
         $data[] = $modelToExportAdapter->getData();
     }
     $output = ExportItemToCsvFileUtil::export($data, $headerData, 'test3.csv', false);
     $this->assertEquals($output, $fileModel->fileContent->content);
     // Check if user got notification message, and if its type is ExportProcessCompleted
     $this->assertEquals($numberOfUserNotifications + 1, Notification::getCountByTypeAndUser('ExportProcessCompleted', Yii::app()->user->userModel));
     //Check no email notification was sent to super because he has disabled it
     $this->assertEquals($numberOfEmailMessages, EmailMessage::getCount());
 }
 public function testGetByFolderTypeAndCampaignId()
 {
     $countBefore = EmailMessage::getCount();
     $job = new CampaignQueueMessagesInOutboxJob();
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact = ContactTestHelper::createContactByNameForOwner('contact 02', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 02');
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
     $campaign = CampaignTestHelper::createCampaign('campaign 02', '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());
     $campaignItemsProcessed = CampaignItem::getByProcessedAndCampaignId(1, $campaign->id);
     $this->assertCount(1, $campaignItemsProcessed);
     $countAfter = EmailMessage::getCount();
     $this->assertEquals($countAfter, $countBefore + 1);
     $outboxCount = count(EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertEquals(1, $outboxCount);
 }
Esempio n. 14
0
 /**
  * @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, EmailMessage::getCount());
     $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->personsOrAccounts->add($jane);
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($billy);
     $emailMessage->recipients->add($recipient);
     //CC recipient is Sally
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Sally Pail';
     $recipient->type = EmailMessageRecipient::TYPE_CC;
     $recipient->personsOrAccounts->add($sally);
     $emailMessage->recipients->add($recipient);
     //BCC recipient is Jason
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Jason Blue';
     $recipient->type = EmailMessageRecipient::TYPE_BCC;
     $recipient->personsOrAccounts->add($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);
 }
 /**
  * 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 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);
     }
 }
Esempio n. 17
0
 /**
  * Test mission notifications
  * @depends testCreateAndGetMissionById
  */
 public function testMissionNotifications()
 {
     $super = User::getByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($super->save());
     $steven = User::getByUsername('steven');
     //A new mission notification was already created for steven
     $this->assertEquals(0, Notification::getCountByUser($super));
     $this->assertEquals(1, Notification::getCountByUser($steven));
     $this->assertEquals(1, EmailMessage::getCount());
     $missions = Mission::getAll();
     $mission = $missions[0];
     $mission->status = Mission::STATUS_TAKEN;
     $this->assertTrue($mission->save());
     $this->assertEquals(1, Notification::getCountByUser($super));
     $this->assertEquals(1, Notification::getCountByUser($steven));
     $this->assertEquals(2, EmailMessage::getCount());
     $mission->status = Mission::STATUS_COMPLETED;
     $this->assertTrue($mission->save());
     $this->assertEquals(2, Notification::getCountByUser($super));
     $this->assertEquals(1, Notification::getCountByUser($steven));
     $this->assertEquals(3, EmailMessage::getCount());
     $mission->status = Mission::STATUS_REJECTED;
     $this->assertTrue($mission->save());
     $this->assertEquals(2, Notification::getCountByUser($super));
     $this->assertEquals(2, Notification::getCountByUser($steven));
     $this->assertEquals(4, EmailMessage::getCount());
     $mission->status = Mission::STATUS_ACCEPTED;
     $this->assertTrue($mission->save());
     $this->assertEquals(2, Notification::getCountByUser($super));
     $this->assertEquals(3, Notification::getCountByUser($steven));
     $this->assertEquals(5, EmailMessage::getCount());
 }
 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 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 testRunAndProcessStuckJobs()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $emailAddress = new Email();
     $emailAddress->emailAddress = '*****@*****.**';
     Yii::app()->user->userModel->primaryEmail = $emailAddress;
     $saved = Yii::app()->user->userModel->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     $monitorJob = new MonitorJob();
     $this->assertEquals(0, JobInProcess::getCount());
     $this->assertEquals(0, StuckJob::getCount());
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     //Should make createdDateTime long enough in past to trigger as stuck.
     $createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     $sql = "Update item set createddatetime = '" . $createdDateTime . "' where id = " . $jobInProcess->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $jobInProcess->forget();
     $monitorJob->run();
     $this->assertEquals(0, JobInProcess::getCount());
     //should still be 0 but the quantity should increase
     $this->assertEquals(0, Notification::getCount());
     //There should now be one stuck job with quantity 1
     $stuckJobs = StuckJob::getAll();
     $this->assertEquals(1, count($stuckJobs));
     $this->assertEquals('Test', $stuckJobs[0]->type);
     $this->assertEquals(1, $stuckJobs[0]->quantity);
     //Now it should increase to 2
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     //Should make createdDateTime long enough in past to trigger as stuck.
     $createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     $sql = "Update item set createddatetime = '" . $createdDateTime . "' where id = " . $jobInProcess->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $jobInProcess->forget();
     $monitorJob->run();
     $this->assertEquals(0, JobInProcess::getCount());
     //should still be 0 but the quantity should increase
     $this->assertEquals(0, Notification::getCount());
     //There should now be one stuck job with quantity 1
     $stuckJobs = StuckJob::getAll();
     $this->assertEquals(1, count($stuckJobs));
     $this->assertEquals('Test', $stuckJobs[0]->type);
     $this->assertEquals(2, $stuckJobs[0]->quantity);
     //Set quantity to 3, then run monitor again and notification should go out.
     $stuckJobs[0]->quantity = 3;
     $this->assertTrue($stuckJobs[0]->save());
     $jobInProcess = new JobInProcess();
     $jobInProcess->type = 'Test';
     $this->assertTrue($jobInProcess->save());
     //Should make createdDateTime long enough in past to trigger as stuck.
     $createdDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 10000);
     $sql = "Update item set createddatetime = '" . $createdDateTime . "' where id = " . $jobInProcess->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $jobInProcess->forget();
     //Now the threshold of 4 should be reached and we should send a notification
     $monitorJob->run();
     ForgetAllCacheUtil::forgetAllCaches();
     $stuckJobs = StuckJob::getAll();
     $this->assertEquals(1, count($stuckJobs));
     $this->assertEquals('Test', $stuckJobs[0]->type);
     $this->assertEquals(4, $stuckJobs[0]->quantity);
     $this->assertEquals(1, Notification::getCount());
     //Confirm an email was sent
     $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(1, EmailMessage::getCount());
     $this->assertEquals(1, Yii::app()->emailHelper->getSentCount());
 }
 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);
 }
 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);
 }
 /**
  * @depends testCreateAndGetCampaignItemById
  */
 public function testDeleteCampaignItem()
 {
     $campaignItems = CampaignItem::getAll();
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(10, $campaignItems);
     $campaignItemActivity = new CampaignItemActivity();
     $campaignItemActivity->type = CampaignItemActivity::TYPE_CLICK;
     $campaignItemActivity->quantity = 1;
     $campaignItemActivity->campaignItem = $campaignItems[0];
     $campaignItemActivity->latestSourceIP = '121.212.122.112';
     $this->assertTrue($campaignItemActivity->save());
     $campaignItems[0]->emailMessage = $this->resolveEmailMessage();
     $this->assertTrue($campaignItems[0]->unrestrictedSave());
     $this->assertEquals(1, EmailMessage::getCount());
     $this->assertEquals(1, EmailMessageContent::getCount());
     $this->assertEquals(1, EmailMessageSender::getCount());
     $this->assertEquals(1, EmailMessageRecipient::getCount());
     $campaignItemActivities = CampaignItemActivity::getAll();
     $this->assertCount(1, $campaignItemActivities);
     $campaignItems[0]->delete();
     $campaignItems = CampaignItem::getAll();
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(9, $campaignItems);
     $campaignItemActivities = CampaignItemActivity::getAll();
     $this->assertCount(0, $campaignItemActivities);
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(0, EmailMessageContent::getCount());
     $this->assertEquals(0, EmailMessageSender::getCount());
     $this->assertEquals(0, EmailMessageRecipient::getCount());
 }
Esempio n. 24
0
 /**
  * @depends testRequiredAttributes
  */
 public function testDeleteCampaign()
 {
     $campaigns = Campaign::getAll();
     $this->assertEquals(4, count($campaigns));
     CampaignItemTestHelper::createCampaignItem(0, $campaigns[0]);
     $campaignItems = CampaignItem::getAll();
     $this->assertCount(1, $campaignItems);
     $campaignItemActivity = new CampaignItemActivity();
     $campaignItemActivity->type = CampaignItemActivity::TYPE_CLICK;
     $campaignItemActivity->quantity = 1;
     $campaignItemActivity->campaignItem = $campaignItems[0];
     $campaignItemActivity->latestSourceIP = '121.212.122.112';
     $this->assertTrue($campaignItemActivity->save());
     $emailMessage = EmailMessageTestHelper::createOutboxEmail(Yii::app()->user->userModel, 'subject', 'html', 'text', 'from', '*****@*****.**', 'to', '*****@*****.**');
     $campaignItems[0]->emailMessage = $emailMessage;
     $this->assertTrue($campaignItems[0]->unrestrictedSave());
     $this->assertEquals(1, CampaignItemActivity::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
     $campaigns[0]->delete();
     $this->assertEquals(3, Campaign::getCount());
     $this->assertEquals(0, CampaignItem::getCount());
     $this->assertEquals(0, CampaignItemActivity::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
 /**
  * @depends testRunInstallation
  */
 public function testRunAutoBuildFromUpdateSchemaCommand()
 {
     $this->runInstallation(true);
     $super = User::getByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($super->save());
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(1, Notification::getCount());
     $messageLogger = new MessageLogger();
     $messageLogger->addInfoMessage(Zurmo::t('InstallModule', 'Starting schema update process.'));
     $result = InstallUtil::runAutoBuildFromUpdateSchemaCommand($messageLogger);
     $messageLogger->addInfoMessage(Zurmo::t('InstallModule', 'Schema update complete.'));
     $this->assertTrue($result);
     //No email notification is sent since allowSendingEmail is false
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(2, Notification::getCount());
 }