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 static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $super = SecurityTestHelper::createSuperAdmin();
     self::$emailMessage = EmailMessageTestHelper::createDraftSystemEmail('a test message', $super);
     SecurityTestHelper::createUsers();
     SecurityTestHelper::createGroups();
     SecurityTestHelper::createRoles();
     RedBeanModel::forgetAll();
     //do the rebuild to ensure the tables get created properly.
     ReadPermissionsOptimizationUtil::rebuild();
 }
 public function testDeletingSenderAndRecipientsPersonsOrAccountsItems()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('test crud relations', $super);
     $contact = ContactTestHelper::createContactByNameForOwner('samson', $super);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagerecipient_item');
     $this->assertEquals(0, $count['count']);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagesender_item');
     $this->assertEquals(0, $count['count']);
     //Add contact as sender personOrAccounts
     $emailMessageSender = new EmailMessageSender();
     $emailMessageSender->fromAddress = '*****@*****.**';
     $emailMessageSender->fromName = 'system name';
     $emailMessageSender->personsOrAccounts->add($contact);
     $emailMessage->sender = $emailMessageSender;
     //Add also as recipient personOrAccounts
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Sam Sammy';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($contact);
     $emailMessage->recipients->add($recipient);
     //Save emailMessage
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagerecipient_item');
     $this->assertEquals(1, $count['count']);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagesender_item');
     $this->assertEquals(1, $count['count']);
     $emailMessage->forget();
     //Now delete the contact and try to retrieve the email message
     $deleted = $contact->delete();
     $this->assertTrue($deleted);
     //Now make sure the intermediate join table rows are removed
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagerecipient_item');
     $this->assertEquals(0, $count['count']);
     $count = ZurmoRedBean::getRow('select count(*) count from emailmessagesender_item');
     $this->assertEquals(0, $count['count']);
 }
Ejemplo n.º 5
0
 /**
  * @depends testSendRealEmail
  */
 public function testTooManySendAttemptsResultingInFailure()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     if (EmailMessageTestHelper::isSetEmailAccountsTestConfiguration()) {
         //add a message in the outbox_error folder.
         $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('a test email 2', $this->user);
         $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
         $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX_ERROR);
         $emailMessage->sendAttempts = 5;
         $emailMessage->save();
         $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
         $this->assertEquals(7, Yii::app()->emailHelper->getSentCount());
         Yii::app()->emailHelper->sendQueued();
         $this->assertEquals(0, Yii::app()->emailHelper->getQueuedCount());
         $this->assertEquals(7, Yii::app()->emailHelper->getSentCount());
         $this->assertTrue($emailMessage->folder->isSame(EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX_FAILURE)));
     } else {
         $this->markTestSkipped();
     }
 }
 public function testUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived()
 {
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('subject 1', Yii::app()->user->userModel);
     $account3 = AccountTestHelper::createAccountByNameForOwner('account3', Yii::app()->user->userModel);
     $account4 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
     $account5 = AccountTestHelper::createAccountByNameForOwner('account4', Yii::app()->user->userModel);
     $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $account5->setLatestActivityDateTime($dateTime);
     $this->assertTrue($account5->save());
     $account3Id = $account3->id;
     $account4Id = $account4->id;
     $account5Id = $account5->id;
     $this->assertNull($account3->latestActivityDateTime);
     $this->assertNull($account4->latestActivityDateTime);
     $this->assertEquals($dateTime, $account5->latestActivityDateTime);
     $emailMessage->sender->personsOrAccounts->add($account3);
     $emailMessage->recipients[0]->personsOrAccounts->add($account4);
     $emailMessage->recipients[0]->personsOrAccounts->add($account5);
     $this->assertTrue($emailMessage->save());
     $this->assertNull($account3->latestActivityDateTime);
     $this->assertNull($account4->latestActivityDateTime);
     $this->assertEquals($dateTime, $account5->latestActivityDateTime);
     $emailMessageId = $emailMessage->id;
     $emailMessage->forget();
     $account3->forget();
     $account4->forget();
     $account5->forget();
     //Retrieve email message and set sentDateTime, at this point the accounts should update with this value
     $sentDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 86400);
     $emailMessage = EmailMessage::getById($emailMessageId);
     $emailMessage->sentDateTime = $sentDateTime;
     $this->assertTrue($emailMessage->save());
     $account3 = Account::getById($account3Id);
     $account4 = Account::getById($account4Id);
     $account5 = Account::getById($account5Id);
     $this->assertEquals($sentDateTime, $account3->latestActivityDateTime);
     $this->assertEquals($sentDateTime, $account4->latestActivityDateTime);
     $this->assertEquals($dateTime, $account5->latestActivityDateTime);
 }
Ejemplo n.º 7
0
 public function testCrudForHasOneAndHasManyEmailAccountRelations()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $emailAccount = EmailAccount::resolveAndGetByUserAndName($super);
     $emailAccountId = $emailAccount->id;
     $emailAccount->forgetAll();
     //Check read hasOne relation
     $emailAccount = EmailAccount::getById($emailAccountId);
     $user = $emailAccount->user;
     $this->assertEquals($super->username, $user->username);
     //Check update hasOne relation
     $user = User::getByUsername('billy');
     $emailAccount->user = $user;
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertEquals('billy', $emailAccount->user->username);
     //Check delete hasOne relation
     $emailAccount->user = null;
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertLessThan(0, $emailAccount->user->id);
     //Check create and read hasMany relation model
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('first test email', $user);
     $emailAccount->messages->add($emailMessage);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(1, $emailAccount->messages);
     $this->assertEquals('first test email', $emailAccount->messages[0]->subject);
     //Check update hasMany relation
     $emailMessage = $emailAccount->messages[0];
     $emailMessage->subject = 'first test email modified';
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(1, $emailAccount->messages);
     $this->assertEquals($emailMessage->subject, $emailAccount->messages[0]->subject);
     //Check add and read another hasMany relation model
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('second test email', $user);
     $emailAccount->messages->add($emailMessage2);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(2, $emailAccount->messages);
     $this->assertEquals($emailMessage2->subject, $emailAccount->messages[1]->subject);
     //Check delete hasMany relation first model
     $emailAccount->messages->remove($emailMessage);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(1, $emailAccount->messages);
     $this->assertEquals($emailMessage2->subject, $emailAccount->messages[0]->subject);
     //Check delete last hasMany relation model
     $emailAccount->messages->remove($emailMessage2);
     $this->assertTrue($emailAccount->save());
     $emailAccount->forgetAll();
     $emailAccount = EmailAccount::getById($emailAccountId);
     $this->assertCount(0, $emailAccount->messages);
 }
 public function testEmailCopyActivity()
 {
     $this->markTestSkipped();
     Yii::app()->user->userModel = User::getByUsername('super');
     $this->setFirstModel();
     $this->setSecondModel();
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('Subject 1', Yii::app()->user->userModel);
     $this->assertTrue($emailMessage->save());
     $emailMessageId = $emailMessage->id;
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $newSender = new EmailMessageSender();
     $newSender->fromAddress = $this->selectedModels[1]->primaryEmail->emailAddress;
     $newSender->fromName = strval($this->selectedModels[1]);
     $newSender->personsOrAccounts->add($this->selectedModels[1]);
     $emailMessage->sender = $newSender;
     $emailMessage->save();
     ListViewMergeUtil::processCopyEmailActivity($this->selectedModels[0], $this->selectedModels[1]);
     $emailMessage = EmailMessage::getById($emailMessageId);
     $this->assertEquals(strval($this->selectedModels[0]), $emailMessage->sender->fromName);
     $this->assertEquals('*****@*****.**', $emailMessage->sender->fromAddress);
     //For recipient
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('Subject 2', Yii::app()->user->userModel);
     $this->assertTrue($emailMessage->save());
     $emailMessageId = $emailMessage->id;
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = $this->selectedModels[1]->primaryEmail->emailAddress;
     $recipient->toName = strval($this->selectedModels[1]);
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($this->selectedModels[1]);
     $emailMessage->recipients->add($recipient);
     $this->assertTrue($emailMessage->save());
     ListViewMergeUtil::processCopyEmailActivity($this->selectedModels[0], $this->selectedModels[1]);
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipients = $emailMessage->recipients;
     $this->assertCount(2, $recipients);
     $this->assertEquals(strval($this->selectedModels[0]), $recipients[1]->toName);
     $this->assertEquals('*****@*****.**', $recipients[1]->toAddress);
     $this->assertCount(1, $recipients[1]->personsOrAccounts);
 }
 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;
 }
Ejemplo n.º 10
0
 public function testCrudForHasOneAndHasManyEmailMessageRelations()
 {
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('test crud relations', $this->user);
     $this->assertTrue($emailMessage->save());
     $emailMessageId = $emailMessage->id;
     $emailMessage->forgetAll();
     //Check read hasOne relation
     $emailMessage = EmailMessage::getById($emailMessageId);
     $emailMessageSender = $emailMessage->sender;
     $this->assertEquals('*****@*****.**', $emailMessageSender->fromAddress);
     //Check update hasOne relation
     $emailMessageSender->fromAddress = '*****@*****.**';
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $emailMessageSender = $emailMessage->sender;
     $this->assertEquals('*****@*****.**', $emailMessageSender->fromAddress);
     //Check delete hasOne relation
     $emailMessageSender2 = new EmailMessageSender();
     $emailMessageSender2->fromAddress = '*****@*****.**';
     $emailMessageSender2->fromName = 'system name';
     $emailMessage->sender = $emailMessageSender2;
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $found = true;
     try {
         EmailMessageSender::getById($emailMessageSender->id);
     } catch (NotFoundException $exception) {
         $found = false;
     }
     $this->assertFalse($found);
     //Check read hasMany relation
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipients = $emailMessage->recipients;
     $recipient = $recipients[0];
     $this->assertCount(1, $recipients);
     $this->assertEquals('*****@*****.**', $recipient->toAddress);
     //Check update hasMany relation
     $recipient->toAddress = '*****@*****.**';
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = $emailMessage->recipients[0];
     $this->assertEquals('*****@*****.**', $recipient->toAddress);
     //Check add hasMany relation
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Anne Frank';
     $recipient->type = EmailMessageRecipient::TYPE_BCC;
     $emailMessage->recipients->add($recipient);
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipients = $emailMessage->recipients;
     $recipient = $recipients[1];
     $this->assertCount(2, $recipients);
     //Check update hasMany relation with more than one model set
     $recipient->toAddress = '*****@*****.**';
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = $emailMessage->recipients[1];
     $this->assertEquals('*****@*****.**', $recipient->toAddress);
     //Check delete hasMany relation
     $emailMessage->recipients->remove($recipient);
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $found = true;
     try {
         EmailMessageRecipient::getById($recipient->id);
     } catch (NotFoundException $exception) {
         $found = false;
     }
     $this->assertFalse($found);
     //Check delete last hasMany relation model
     $emailMessage = EmailMessage::getById($emailMessageId);
     $recipient = $emailMessage->recipients[0];
     $emailMessage->recipients->remove($recipient);
     $this->assertTrue($emailMessage->save());
     $emailMessage->forgetAll();
     $found = true;
     try {
         EmailMessageRecipient::getById($recipient->id);
     } catch (NotFoundException $exception) {
         $found = false;
     }
     $this->assertFalse($found);
     $this->assertCount(0, $emailMessage->recipients);
 }
Ejemplo n.º 11
0
 public function testSavePurgesUnsetCampaignItemsForPausedToActiveStatusChangeIfNeeded()
 {
     $campaign = CampaignTestHelper::createCampaign('afterSaveDeleteUnsetCampaignItemsTest', 'subject', 'text');
     // 3 items, 1 unprocessed, 1 processed with email in outbox, 1 processed with email in sent.
     $campaignItem = CampaignItemTestHelper::createCampaignItem(1, $campaign);
     $emailMessage = EmailMessageTestHelper::createOutboxEmail(Yii::app()->user->userModel, 'subject', 'html', 'text', 'from', '*****@*****.**', 'to', '*****@*****.**');
     $campaignItem->emailMessage = $emailMessage;
     $this->assertTrue($campaignItem->unrestrictedSave());
     $campaignItem2 = CampaignItemTestHelper::createCampaignItem(1, $campaign);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('subject2', Yii::app()->user->userModel);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage2->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $this->assertTrue($emailMessage2->save());
     $campaignItem2->emailMessage = $emailMessage2;
     $this->assertTrue($campaignItem2->unrestrictedSave());
     CampaignItemTestHelper::createCampaignItem(0, $campaign);
     $this->assertCount(2, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
     // set initial status
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     $this->assertCount(2, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
     // change a non-dependent property, no change in campaign items
     $campaign->status = Campaign::STATUS_ACTIVE;
     $campaign->name = $campaign->name . 'modified';
     $this->assertCount(2, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
     // reset status
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     // change a dependent property, unset should be deleted.
     $campaign->status = Campaign::STATUS_ACTIVE;
     $campaign->subject = $campaign->subject . 'modified';
     $this->assertTrue($campaign->save());
     // deleted: 1 processed with email in outbox, 1 unprocessed.
     $this->assertCount(1, CampaignItem::getByProcessedAndCampaignId(1, $campaign->id));
     $this->assertCount(0, CampaignItem::getByProcessedAndCampaignId(0, $campaign->id));
     $this->assertCount(0, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_OUTBOX, $campaign->id));
     $this->assertCount(1, EmailMessage::getByFolderTypeAndCampaignId(EmailFolder::TYPE_SENT, $campaign->id));
 }