public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     SecurityTestHelper::createUsers();
     $super = User::getByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $saved = $super->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     MarketingListTestHelper::createMarketingListByName('testMarketingList');
     $campaign = CampaignTestHelper::createCampaign('testCampaign', 'testSubject', 'testContent', 'testHtmlContent');
     $contact = ContactTestHelper::createContactByNameForOwner('test', $super);
     $emailMessage = EmailMessageTestHelper::createArchivedUnmatchedSentMessage($super);
     $campaignItem = new CampaignItem();
     $campaignItem->contact = $contact;
     $campaignItem->processed = true;
     $campaignItem->campaign = $campaign;
     $campaignItem->emailMessage = $emailMessage;
     $campaignItem->unrestrictedSave();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
     AllPermissionsOptimizationUtil::rebuild();
 }
 public function setUp()
 {
     parent::setUp();
     Yii::app()->user->userModel = User::getByUsername('super');
     $emailBoxes = EmailBox::getAll();
     $this->emailBox = $emailBoxes[0];
     $this->marketingList = MarketingListTestHelper::createMarketingListByName('Test Marketing List');
     $this->campaign = CampaignTestHelper::createCampaign('Test Campaing 01', 'text', 'text exemple');
     $this->autoresponder = AutoresponderTestHelper::createAutoresponder('Test Autoresponder 01', 'text', 'html', 60, Autoresponder::OPERATION_SUBSCRIBE, true);
 }
 public function testRegularUserAllDefaultControllerActions()
 {
     MarketingListTestHelper::createMarketingListByName('MarketingListName02', 'MarketingList Description', 'first', '*****@*****.**');
     $campaign = CampaignTestHelper::createCampaign('campaign02', 'campaign subject 02', 'text content for campaign 02', 'html content for campaign 02', 'fromCampaign', '*****@*****.**');
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default');
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/index');
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/list');
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/create');
     $this->setGetArray(array('id' => $campaign->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/edit');
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/details');
     $this->resetGetArray();
     $this->user->setRight('CampaignsModule', CampaignsModule::getAccessRight());
     $this->assertTrue($this->user->save());
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default');
     $this->assertContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $this->user->setRight('MarketingListsModule', MarketingListsModule::getAccessRight());
     $this->user->setRight('EmailTemplatesModule', EmailTemplatesModule::getAccessRight());
     $this->assertTrue($this->user->save());
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/index');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/list');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $this->setGetArray(array('id' => $campaign->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/details');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/details');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $this->resetGetArray();
     $this->user->setRight('CampaignsModule', CampaignsModule::getCreateRight());
     $this->assertTrue($this->user->save());
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/create');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $this->setGetArray(array('id' => $campaign->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/details');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $this->resetGetArray();
     $this->user->setRight('CampaignsModule', CampaignsModule::getCreateRight());
     $this->assertTrue($this->user->save());
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/create');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $this->setGetArray(array('id' => $campaign->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/edit');
     $this->assertNotContains('<p>To manage campaigns you must have access to email templates and ' . 'marketing lists. Contact the CRM administrator about this issue.</p>', $content);
     $this->user->setRight('CampaignsModule', CampaignsModule::getDeleteRight());
     $this->assertTrue($this->user->save());
     $this->runControllerWithRedirectExceptionAndGetUrl('campaigns/default/delete');
     $this->setGetArray(array('id' => static::$campaignOwnedBySuper->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/edit');
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/details');
     $this->runControllerShouldResultInAccessFailureAndGetContent('campaigns/default/delete');
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     EmailTemplateTestHelper::createEmailTemplateByName(EmailTemplate::TYPE_CONTACT, 'Subject 01', 'Contact', 'EmailTemplate 01', 'html', 'text');
     EmailTemplateTestHelper::createEmailTemplateByName(EmailTemplate::TYPE_CONTACT, 'Subject 02', 'Contact', 'EmailTemplate 02', 'html', 'text');
     EmailTemplateTestHelper::createEmailTemplateByName(EmailTemplate::TYPE_CONTACT, 'Subject 03', 'Contact', 'EmailTemplate 03', 'html', 'text');
     MarketingListTestHelper::createMarketingListByName('MarketingListName', 'MarketingList Description', 'first', '*****@*****.**');
     CampaignTestHelper::createCampaign('campaign01', 'campaign subject 01', 'text content for campaign 01', 'html content for campaign 01', 'fromCampaign', '*****@*****.**');
     CampaignTestHelper::createCampaign('campaign02', 'campaign subject 02', 'text content for campaign 02', 'html content for campaign 02', 'fromCampaign2', '*****@*****.**');
 }
 public function testSuperUserAllDefaultControllerActions()
 {
     // Test all default controller actions that do not require any POST/GET variables to be passed.
     $this->runControllerWithNoExceptionsAndGetContent('campaigns/default');
     $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/index');
     $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/list');
     CampaignTestHelper::createCampaign('campaign01', 'campaign subject 01', 'text content for campaign 01', 'html content for campaign 01', 'fromCampaign', '*****@*****.**');
     CampaignTestHelper::createCampaign('campaign02', 'campaign subject 02', 'text content for campaign 02', 'html content for campaign 02', 'fromCampaign2', '*****@*****.**');
     $this->runControllerWithNoExceptionsAndGetContent('campaigns/default');
     $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/index');
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/list');
     $compareContent = 'Campaigns will not run properly until scheduled jobs are set up. Contact your administrator.';
     $this->assertNotContains($compareContent, $content);
     $content = $this->runControllerWithNoExceptionsAndGetContent('campaigns/default/create');
     $compareContent = 'Campaigns will not run properly until scheduled jobs are set up. Contact your administrator.';
     $this->assertContains($compareContent, $content);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     static::$user = User::getByUsername('super');
     Yii::app()->user->userModel = static::$user;
     $contact = ContactTestHelper::createContactByNameForOwner('contact 01', static::$user);
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01', 'description 01', 'fromName 01', '*****@*****.**');
     $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 01', 'textContent 01', 'htmlContent 01', 10, Autoresponder::OPERATION_SUBSCRIBE, 1, $marketingList);
     $processed = 0;
     $processDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 100);
     $autoresponderItem = AutoresponderItemTestHelper::createAutoresponderItem($processed, $processDateTime, $autoresponder, $contact);
     static::$personId = $contact->getClassId('Person');
     static::$autoresponderItemId = $autoresponderItem->id;
     $campaign = CampaignTestHelper::createCampaign('campaign 01', 'subject 01', 'text Content 01', 'html Content 01', 'fromName 01', '*****@*****.**', null, Campaign::STATUS_ACTIVE, null, null, $marketingList);
     $processed = 0;
     $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     static::$campaignItemId = $campaignItem->id;
     AllPermissionsOptimizationUtil::rebuild();
 }
コード例 #7
0
 public function testCreateAndGetCampaignItemActivityWithCampaignItemById()
 {
     $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01');
     $campaign = CampaignTestHelper::createCampaign('campaign 01', 'subject 01', 'text Content 01', 'html Content 01', 'fromName 01', '*****@*****.**', null, null, null, null, $marketingList);
     $processed = 0;
     $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     $campaignItemActivity = new CampaignItemActivity();
     $campaignItemActivity->type = CampaignItemActivity::TYPE_CLICK;
     $campaignItemActivity->quantity = 1;
     $campaignItemActivity->campaignItem = $campaignItem;
     $campaignItemActivity->latestSourceIP = '121.212.122.112';
     $this->assertTrue($campaignItemActivity->save());
     $id = $campaignItemActivity->id;
     unset($campaignItemActivity);
     $campaignItemActivity = CampaignItemActivity::getById($id);
     $this->assertEquals(CampaignItemActivity::TYPE_CLICK, $campaignItemActivity->type);
     $this->assertEquals(1, $campaignItemActivity->quantity);
     $this->assertEquals($campaignItem, $campaignItemActivity->campaignItem);
     $this->assertEquals('121.212.122.112', $campaignItemActivity->latestSourceIP);
 }
 public function testGetCountByTypeAndEmailMessageActivity()
 {
     // setup pre-req data
     $contact = ContactTestHelper::createContactByNameForOwner('contact 01', $this->user);
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 01', 'description 01', 'fromName 01', '*****@*****.**');
     $campaign = CampaignTestHelper::createCampaign('campaign 01', 'subject 01', 'text Content 01', 'html Content 01', 'fromName 01', '*****@*****.**', null, null, null, null, $marketingList);
     $processed = 0;
     $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     $modelId = $campaignItem->id;
     $modelType = get_class($campaignItem);
     $personId = $contact->getClassId('Person');
     $this->assertNotNull($personId);
     $activityData = array('modelId' => $campaignItem->id, 'modelType' => 'CampaignItem', 'personId' => $personId, 'url' => null, 'type' => CampaignItemActivity::TYPE_OPEN);
     $activityCreatedOrUpdated = CampaignItemActivityUtil::createOrUpdateActivity($activityData);
     $emailMessageActivities = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(CampaignItemActivity::TYPE_OPEN, $campaignItem->id, $personId, null);
     $externalMessageActivityCount = ExternalApiEmailMessageActivity::getByTypeAndEmailMessageActivity(CampaignItemActivity::TYPE_OPEN, $emailMessageActivities[0], "sendgrid");
     $this->assertEquals(0, $externalMessageActivityCount);
     $externalApiEmailMessageActivity = new ExternalApiEmailMessageActivity();
     $externalApiEmailMessageActivity->emailMessageActivity = $emailMessageActivities[0];
     $externalApiEmailMessageActivity->api = 'sendgrid';
     $externalApiEmailMessageActivity->type = CampaignItemActivity::TYPE_OPEN;
     $externalApiEmailMessageActivity->reason = 'Test reason';
     $externalApiEmailMessageActivity->emailAddress = '*****@*****.**';
     $externalApiEmailMessageActivity->itemClass = 'CampaignItem';
     $externalApiEmailMessageActivity->itemId = $campaignItem->id;
     $this->assertTrue($externalApiEmailMessageActivity->save());
     $id = $externalApiEmailMessageActivity->id;
     $externalMessageActivityCount = ExternalApiEmailMessageActivity::getByTypeAndEmailMessageActivity(CampaignItemActivity::TYPE_OPEN, $emailMessageActivities[0], "sendgrid");
     $this->assertEquals(1, $externalMessageActivityCount);
     $externalApiActivity = ExternalApiEmailMessageActivity::getById($id);
     $externalApiActivity->reason = 'New reason 1';
     $this->assertTrue($externalApiActivity->save());
     $externalApiActivity = ExternalApiEmailMessageActivity::getById($id);
     $this->assertEquals('New reason 1', $externalApiActivity->reason);
     $activities = ExternalApiEmailMessageActivity::getByEmailAddress('*****@*****.**', "sendgrid", false);
     $this->assertEquals(1, count($activities));
     $this->assertEquals('New reason 1', $activities[0]->reason);
 }
コード例 #9
0
 /**
  * @depends testRunWithDueActiveCampaignsWithMembers
  */
 public function testRunWithDueActiveCampaignsWithCustomBatchSize()
 {
     $this->purgeAllCampaigns();
     $contactIds = array();
     $marketingListIds = array();
     $campaignIds = array();
     for ($index = 6; $index < 9; $index++) {
         $contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $index, $this->user);
         $contactIds[] = $contact->id;
         $contact->forgetAll();
     }
     for ($index = 5; $index < 10; $index++) {
         $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 0' . $index);
         $marketingListId = $marketingList->id;
         $marketingListIds[] = $marketingListId;
         foreach ($contactIds as $contactId) {
             $contact = Contact::getById($contactId);
             $unsubscribed = rand(10, 20) % 2;
             MarketingListMemberTestHelper::createMarketingListMember($unsubscribed, $marketingList, $contact);
         }
         $marketingList->forgetAll();
         $marketingList = MarketingList::getById($marketingListId);
         $campaignSuffix = substr($marketingList->name, -2);
         $campaign = CampaignTestHelper::createCampaign('campaign ' . $campaignSuffix, 'subject ' . $campaignSuffix, 'text ' . $campaignSuffix, 'html ' . $campaignSuffix, null, null, null, null, null, null, $marketingList);
         $this->assertNotNull($campaign);
         $campaignIds[] = $campaign->id;
         $campaign->forgetAll();
     }
     foreach ($campaignIds as $campaignId) {
         $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
         $this->assertEmpty($campaignItems);
     }
     AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize(10);
     $job = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($job->run());
     foreach ($campaignIds as $index => $campaignId) {
         $campaign = Campaign::getById($campaignId);
         $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
         if ($index === 0) {
             $expectedCount = AutoresponderOrCampaignBatchSizeConfigUtil::getBatchSize();
             $memberCount = count($campaign->marketingList->marketingListMembers);
             if ($memberCount < $expectedCount) {
                 $expectedCount = $memberCount;
             }
             $this->assertNotEmpty($campaignItems);
             $this->assertCount($expectedCount, $campaignItems);
             $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
         } else {
             $this->assertEmpty($campaignItems);
             $this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status);
         }
     }
     AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize(null);
     $this->assertTrue($job->run());
     foreach ($campaignIds as $index => $campaignId) {
         $campaign = Campaign::getById($campaignId);
         $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
         if ($index < 2) {
             $expectedCount = AutoresponderOrCampaignBatchSizeConfigUtil::getBatchSize();
             $memberCount = count($campaign->marketingList->marketingListMembers);
             if ($memberCount < $expectedCount) {
                 $expectedCount = $memberCount;
             }
             $this->assertNotEmpty($campaignItems);
             $this->assertCount($expectedCount, $campaignItems);
             $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
         } else {
             $this->assertEmpty($campaignItems);
             $this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status);
         }
     }
     // TODO: @Shoaibi: Medium: Add tests for the other campaign type.
 }
コード例 #10
0
 /**
  * @depends testMarkProcessedCampaignsAsCompleted
  */
 public function testMarkProcessedCampaignsAsCompletedWithCustomPageSize()
 {
     Campaign::deleteAll();
     $contact = ContactTestHelper::createContactByNameForOwner('contact 02', $this->user);
     $marketingList = MarketingListTestHelper::populateMarketingListByName('marketingList 02');
     $campaign01 = CampaignTestHelper::createCampaign('campaign 01', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
     $this->assertNotNull($campaign01);
     $campaign01Id = $campaign01->id;
     CampaignItemTestHelper::createCampaignItem(1, $campaign01, $contact);
     $campaign02 = CampaignTestHelper::createCampaign('campaign 02', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
     $this->assertNotNull($campaign02);
     $campaign02Id = $campaign02->id;
     CampaignItemTestHelper::createCampaignItem(1, $campaign02, $contact);
     $campaign03 = CampaignTestHelper::createCampaign('campaign 03', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
     $this->assertNotNull($campaign03);
     $campaign03Id = $campaign03->id;
     $campaign01->forgetAll();
     $campaign02->forgetAll();
     $campaign03->forgetAll();
     Yii::app()->jobQueue->deleteAll();
     $jobs = Yii::app()->jobQueue->getAll();
     $this->assertCount(0, $jobs);
     $this->assertTrue(CampaignsUtil::markProcessedCampaignsAsCompleted(1));
     $jobs = Yii::app()->jobQueue->getAll();
     $this->assertCount(1, $jobs);
     $this->assertEquals('CampaignMarkCompleted', $jobs[5][0]['jobType']);
     $campaign01 = Campaign::getById($campaign01Id);
     $this->assertNotNull($campaign01);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
     $campaign02 = Campaign::getById($campaign02Id);
     $this->assertNotNull($campaign02);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign02->status);
     $campaign03 = Campaign::getById($campaign03Id);
     $this->assertNotNull($campaign03);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign03->status);
     $campaign01->forgetAll();
     $campaign02->forgetAll();
     $campaign03->forgetAll();
     Yii::app()->jobQueue->deleteAll();
     $jobs = Yii::app()->jobQueue->getAll();
     $this->assertCount(0, $jobs);
     $this->assertTrue(CampaignsUtil::markProcessedCampaignsAsCompleted());
     $jobs = Yii::app()->jobQueue->getAll();
     $this->assertCount(0, $jobs);
     $campaign01 = Campaign::getById($campaign01Id);
     $this->assertNotNull($campaign01);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
     $campaign02 = Campaign::getById($campaign02Id);
     $this->assertNotNull($campaign02);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign02->status);
     $campaign03 = Campaign::getById($campaign03Id);
     $this->assertNotNull($campaign03);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign03->status);
 }
コード例 #11
0
 /**
  * @depends testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForInvalidCampaignItemIdForUrlClickTracking
  * @expectedException NotFoundException
  */
 public function testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForInvalidPersonIdForUrlClickTracking()
 {
     // setup pre-req data
     $contact = ContactTestHelper::createContactByNameForOwner('contact 06', $this->user);
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 06', 'description 06', 'fromName 06', '*****@*****.**');
     $campaign = CampaignTestHelper::createCampaign('campaign 06', 'subject 06', 'text Content 06', 'html Content 06', 'fromName 06', '*****@*****.**', null, null, null, null, $marketingList);
     $processed = 0;
     $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     $modelId = $campaignItem->id;
     $modelType = get_class($campaignItem);
     $personId = $contact->getClassId('Person');
     $this->assertNotNull($personId);
     $personId = $personId + 200;
     // get the modelClassName to use for activity object tests
     $className = 'CampaignItemActivityUtil';
     $resolveModelClassNameByModelTypeFunction = static::getProtectedMethod($className, 'resolveModelClassNameByModelType');
     $modelClassName = $resolveModelClassNameByModelTypeFunction->invokeArgs(null, array($modelType));
     $type = $modelClassName::TYPE_CLICK;
     $existingActivities = $modelClassName::getByType($type);
     $this->assertCount(1, $existingActivities);
     // get base query string
     $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil', 'resolveBaseQueryStringArray');
     $queryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array($modelId, $modelType, $personId));
     $this->assertNotEmpty($queryStringArray);
     $this->assertCount(3, $queryStringArray);
     $this->assertArrayHasKey('modelId', $queryStringArray);
     $this->assertArrayHasKey('modelType', $queryStringArray);
     $this->assertArrayHasKey('personId', $queryStringArray);
     $queryStringArray['url'] = 'http://www.zurmo.com';
     // get hash for query string and ensure its what we expect it to be.
     $queryStringArrayHash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
     $queryStringArrayDecoded = $className::resolveQueryStringArrayForHash($queryStringArrayHash);
     $this->assertNotEmpty($queryStringArrayDecoded);
     $this->assertCount(5, $queryStringArrayDecoded);
     $this->assertArrayHasKey('modelId', $queryStringArrayDecoded);
     $this->assertArrayHasKey('modelType', $queryStringArrayDecoded);
     $this->assertArrayHasKey('personId', $queryStringArrayDecoded);
     $this->assertArrayHasKey('url', $queryStringArrayDecoded);
     $this->assertArrayHasKey('type', $queryStringArrayDecoded);
     $this->assertEquals($queryStringArray['modelId'], $queryStringArrayDecoded['modelId']);
     $this->assertEquals($queryStringArray['modelType'], $queryStringArrayDecoded['modelType']);
     $this->assertEquals($queryStringArray['personId'], $queryStringArrayDecoded['personId']);
     $this->assertEquals($queryStringArray['url'], $queryStringArrayDecoded['url']);
     $this->assertNull($queryStringArrayDecoded['type']);
     // do the magic, confirm magic worked by checking return value.
     $_GET['id'] = $queryStringArrayHash;
     $result = $className::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
 }
コード例 #12
0
 /**
  * @depends testSendQueued
  */
 public function testSendQueuedSkipsPausedCampaignMessages()
 {
     EmailMessage::deleteAll();
     $job = new CampaignQueueMessagesInOutboxJob();
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact = ContactTestHelper::createContactByNameForOwner('contact', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList');
     MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
     $campaign = CampaignTestHelper::createCampaign('campaign', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, 0, $marketingList);
     $processed = 0;
     CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     $this->assertTrue($job->run());
     $campaignItems = CampaignItem::getAll();
     $this->assertCount(1, $campaignItems);
     $campaignItemsProcessed = CampaignItem::getByProcessedAndCampaignId(1, $campaign->id);
     $this->assertCount(1, $campaignItemsProcessed);
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
     Yii::app()->emailHelper->sendQueued();
     $this->assertEquals(1, Yii::app()->emailHelper->getQueuedCount());
     $this->assertEquals(0, Yii::app()->emailHelper->getSentCount());
 }
コード例 #13
0
 public function testSkipMessage()
 {
     // Tests with Autoresponder
     $contact = ContactTestHelper::createContactByNameForOwner('contact 15', $this->user);
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 15');
     $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 15', 'text content', 'html content', 1, Autoresponder::OPERATION_UNSUBSCRIBE, false, $marketingList);
     $autoresponderItemsUtil = new AutoresponderItemsUtil();
     // Test when the contact isn't in the marketing list at all, same as it was deleted
     $this->assertTrue($autoresponderItemsUtil->skipMessage($contact, $autoresponder));
     // Test when the contact is subscribed but the operation is OPERATION_UNSUBSCRIBE
     $marketingListMember = MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
     $this->assertTrue($autoresponderItemsUtil->skipMessage($contact, $autoresponder));
     // Test when the contact is unsubscribed, so skipMessage return false
     $marketingListMember->unsubscribed = true;
     $this->assertTrue($marketingListMember->unrestrictedSave());
     $this->assertFalse($autoresponderItemsUtil->skipMessage($contact, $autoresponder));
     $contact = ContactTestHelper::createContactByNameForOwner('contact 16', $this->user);
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 16');
     $autoresponder = AutoresponderTestHelper::createAutoresponder('subject 16', 'text content', 'html content', 1, Autoresponder::OPERATION_SUBSCRIBE, false, $marketingList);
     // Test when the contact isn't in the marketing list at all, same as it was deleted
     $this->assertTrue($autoresponderItemsUtil->skipMessage($contact, $autoresponder));
     // Test when the contact is unsubscribed but the operation is OPERATION_SUBSCRIBE
     $marketingListMember = MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList, $contact);
     $this->assertTrue($autoresponderItemsUtil->skipMessage($contact, $autoresponder));
     // Test when the contact is subscribed, so skipMessage return false
     $marketingListMember->unsubscribed = false;
     $this->assertTrue($marketingListMember->unrestrictedSave());
     $this->assertFalse($autoresponderItemsUtil->skipMessage($contact, $autoresponder));
     //Tests with Campaign
     $contact = ContactTestHelper::createContactByNameForOwner('contact 17', $this->user);
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 17');
     $campaign = CampaignTestHelper::createCampaign('campaign 01', 'subject 01', 'text 01', 'html 01', null, null, null, null, null, null, $marketingList);
     $this->assertNotNull($campaign);
     // Test when the contact isn't in the marketing list at all, same as it was deleted
     $this->assertTrue($autoresponderItemsUtil->skipMessage($contact, $campaign));
     // Test when the contact is unsubscribed
     $marketingListMember = MarketingListMemberTestHelper::createMarketingListMember(1, $marketingList, $contact);
     $this->assertTrue($autoresponderItemsUtil->skipMessage($contact, $campaign));
     // Test when the contact is subscribed, so skipMessage return false
     $marketingListMember->unsubscribed = false;
     $this->assertTrue($marketingListMember->unrestrictedSave());
     $this->assertFalse($autoresponderItemsUtil->skipMessage($contact, $campaign));
 }
コード例 #14
0
 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);
 }
    public function generateAndProcessCampaignItems($count)
    {
        $contacts = array();
        $emails = array();
        for ($i = 0; $i < $count; $i++) {
            $emails[$i] = new Email();
            $emails[$i]->emailAddress = "demo{$i}@zurmo.com";
            $account = AccountTestHelper::createAccountByNameForOwner('account ' . $i, $this->user);
            $contact = ContactTestHelper::createContactWithAccountByNameForOwner('contact ' . $i, $this->user, $account);
            $contact->primaryEmail = $emails[$i];
            $this->assertTrue($contact->save());
            $contacts[$i] = $contact;
        }
        $content = <<<MTG
[[COMPANY^NAME]]
[[CREATED^DATE^TIME]]
[[DEPARTMENT]]
[[DESCRIPTION]]
[[FIRST^NAME]]
[[GOOGLE^WEB^TRACKING^ID]]
[[INDUSTRY]]
[[JOB^TITLE]]
[[LAST^NAME]]
[[LATEST^ACTIVITY^DATE^TIME]]
[[MOBILE^PHONE]]
[[MODIFIED^DATE^TIME]]
[[OFFICE^FAX]]
[[OFFICE^PHONE]]
[[TITLE]]
[[SOURCE]]
[[STATE]]
[[WEBSITE]]
[[MODEL^URL]]
[[BASE^URL]]
[[APPLICATION^NAME]]
[[CURRENT^YEAR]]
[[LAST^YEAR]]
[[OWNERS^AVATAR^SMALL]]
[[OWNERS^AVATAR^MEDIUM]]
[[OWNERS^AVATAR^LARGE]]
[[OWNERS^EMAIL^SIGNATURE]]
[[UNSUBSCRIBE^URL]]
[[MANAGE^SUBSCRIPTIONS^URL]]
[[PRIMARY^EMAIL__EMAIL^ADDRESS]]
[[PRIMARY^EMAIL__EMAIL^ADDRESS]]
[[SECONDARY^ADDRESS__CITY]]
[[SECONDARY^ADDRESS__COUNTRY]]
[[SECONDARY^ADDRESS__INVALID]]
[[SECONDARY^ADDRESS__LATITUDE]]
[[SECONDARY^ADDRESS__LONGITUDE]]
[[SECONDARY^ADDRESS__POSTAL^CODE]]
[[SECONDARY^ADDRESS__STATE]]
[[SECONDARY^ADDRESS__STREET1]]
[[SECONDARY^ADDRESS__STREET2]]
[[OWNER__DEPARTMENT]]
[[OWNER__FIRST^NAME]]
[[OWNER__IS^ACTIVE]]
[[OWNER__MOBILE^PHONE]]
[[OWNER__LAST^LOGIN^DATE^TIME]]
[[OWNER__LAST^NAME]]
[[CREATED^BY^USER__FIRST^NAME]]
[[CREATED^BY^USER__LAST^NAME]]
[[CREATED^BY^USER__MOBILE^PHONE]]
[[CREATED^BY^USER__TITLE]]
[[CREATED^BY^USER__USERNAME]]
[[ACCOUNT__ANNUAL^REVENUE]]
[[ACCOUNT__INDUSTRY]]
[[ACCOUNT__NAME]]
[[ACCOUNT__WEBSITE]]
[[ACCOUNT__BILLING^ADDRESS__COUNTRY]]
[[ACCOUNT__BILLING^ADDRESS__CITY]]
[[ACCOUNT__OWNER__FIRST^NAME]]
 ' " ` " '
MTG;
        $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList Test', 'description goes here', 'fromName', '*****@*****.**');
        $campaign = CampaignTestHelper::createCampaign('campaign Test', 'subject', $content, $content, null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList, false);
        $fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
        $files = array();
        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;
            $campaign->files->add($file);
        }
        $this->assertTrue($campaign->save(false));
        $processed = 0;
        foreach ($contacts as $contact) {
            MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
            CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
        }
        AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize($count);
        Yii::app()->jobQueue->deleteAll();
        ForgetAllCacheUtil::forgetAllCaches();
        $job = new CampaignQueueMessagesInOutboxJob();
        $this->assertCount(0, Yii::app()->jobQueue->getAll());
        $startedAt = microtime(true);
        $this->assertTrue($job->run());
        $timeTaken = microtime(true) - $startedAt;
        ForgetAllCacheUtil::forgetAllCaches();
        $campaignItemsCountExpected = $count;
        $campaignItemsCountAfter = CampaignItem::getCount();
        $this->assertEquals($campaignItemsCountExpected, $campaignItemsCountAfter);
        $campaignItemsProcessed = CampaignItem::getByProcessedAndCampaignId(1, $campaign->id);
        $this->assertCount($count, $campaignItemsProcessed);
        foreach ($campaignItemsProcessed as $i => $campaignItem) {
            $contact = $contacts[$i];
            $email = $emails[$i];
            $emailMessage = $campaignItem->emailMessage;
            $this->assertEquals($marketingList->owner->id, $emailMessage->owner->id);
            $marketingListPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($marketingList);
            $emailMessagePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($emailMessage);
            $this->assertEquals($marketingListPermissions, $emailMessagePermissions);
            $this->assertEquals($campaign->subject, $emailMessage->subject);
            $this->assertNotEquals($campaign->textContent, $emailMessage->content->textContent);
            $this->assertNotEquals($campaign->htmlContent, $emailMessage->content->htmlContent);
            $this->assertEquals(2, substr_count($emailMessage->content->textContent, '/marketingLists/external/'));
            $this->assertContains('/marketingLists/external/', $emailMessage->content->htmlContent);
            $this->assertEquals(2, substr_count($emailMessage->content->htmlContent, '/marketingLists/external/'));
            $this->assertEquals('*****@*****.**', $emailMessage->sender->fromAddress);
            $this->assertEquals('Support Team', $emailMessage->sender->fromName);
            $this->assertEquals(1, $emailMessage->recipients->count());
            $recipients = $emailMessage->recipients;
            $this->assertEquals(strval($contact), $recipients[0]->toName);
            $this->assertEquals($email->emailAddress, $recipients[0]->toAddress);
            $this->assertEquals(EmailMessageRecipient::TYPE_TO, $recipients[0]->type);
            $this->assertNotEmpty($emailMessage->files);
            $this->assertCount(count($files), $emailMessage->files);
            foreach ($campaign->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);
                //CampaingItem should share the Attachments content from Campaign
                $this->assertEquals($file->fileContent->content, $emailMessage->files[$index]->fileContent->content);
                $this->assertEquals($file->fileContent->id, $emailMessage->files[$index]->fileContent->id);
            }
            $headersArray = array('zurmoItemId' => $campaignItem->id, 'zurmoItemClass' => get_class($campaignItem), 'zurmoPersonId' => $contact->getClassId('Person'));
            $expectedHeaders = serialize($headersArray);
            $this->assertEquals($expectedHeaders, $emailMessage->headers);
        }
        return $timeTaken;
    }
コード例 #16
0
 /**
  * @depends testHasAtLeastOneUnsubscribeActivity
  */
 public function testHasAtLeastOneBounceActivity()
 {
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 13');
     $campaign = CampaignTestHelper::createCampaign('campaign 12', 'subject 12', 'text 12', 'html 12', null, null, null, null, null, null, $marketingList);
     $this->assertNotNull($campaign);
     $contact = ContactTestHelper::createContactByNameForOwner('campaignContact 13', Yii::app()->user->userModel);
     $campaignItem = CampaignItemTestHelper::createCampaignItem(0, $campaign, $contact);
     $this->assertNotNull($campaignItem);
     $this->assertFalse($campaignItem->hasAtLeastOneBounceActivity());
     CampaignItemActivity::createNewActivity(CampaignItemActivity::TYPE_OPEN, $campaignItem->id, $contact->getClassId('Person'), null, null, $campaignItem);
     $this->assertFalse($campaignItem->hasAtLeastOneBounceActivity());
     CampaignItemActivity::createNewActivity(CampaignItemActivity::TYPE_BOUNCE, $campaignItem->id, $contact->getClassId('Person'), null, null, $campaignItem);
     $this->assertTrue($campaignItem->hasAtLeastOneBounceActivity());
     CampaignItemActivity::createNewActivity(CampaignItemActivity::TYPE_BOUNCE, $campaignItem->id, $contact->getClassId('Person'), null, null, $campaignItem);
     $this->assertTrue($campaignItem->hasAtLeastOneBounceActivity());
 }
 /**
  * @depends testRunWithJustDueActiveCampaignsWithMembers
  */
 public function testRunJobDoesNotRegenerateExistingItems()
 {
     $data = array('old' => array('subject' => 'Old Subject', 'fromName' => 'Old From Name', 'fromAddress' => '*****@*****.**', 'textContent' => 'Old Text Content', 'htmlContent' => 'Old Html Content'), 'new' => array('subject' => 'New Subject', 'fromName' => 'New From Name', 'fromAddress' => '*****@*****.**', 'textContent' => 'New Text Content', 'htmlContent' => 'New Html Content'));
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 06');
     $marketingListId = $marketingList->id;
     $processed = 0;
     for ($i = 11; $i <= 15; $i++) {
         $email = new Email();
         $email->emailAddress = "demo{$i}@zurmo.com";
         $contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $i, $this->user);
         $contact->primaryEmail = $email;
         $this->assertTrue($contact->save());
         MarketingListMemberTestHelper::createMarketingListMember($processed, $marketingList, $contact);
     }
     $marketingList->forgetAll();
     $marketingList = MarketingList::getById($marketingListId);
     $nowDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $campaign = CampaignTestHelper::createCampaign('campaign', $data['old']['subject'], $data['old']['textContent'], $data['old']['htmlContent'], $data['old']['fromName'], $data['old']['fromAddress'], null, Campaign::STATUS_ACTIVE, $nowDateTime, null, $marketingList);
     $campaignId = $campaign->id;
     // we have to do this to ensure when we retrieve the data status is updated from db.
     $campaign->forgetAll();
     $this->assertEmpty(CampaignItem::getAll());
     // sleep 1 second to ensure we are giving ample time difference between creating the campaign and calling the job
     sleep(1);
     $campaignGenerateDueCampaignItemsJob = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($campaignGenerateDueCampaignItemsJob->run());
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     $allCampaignItems = CampaignItem::getAll();
     $this->assertNotEmpty($allCampaignItems);
     $this->assertCount(5, $allCampaignItems);
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     $campaignQueueMessagesInOutboxJob = new CampaignQueueMessagesInOutboxJob();
     $this->assertTrue($campaignQueueMessagesInOutboxJob->run());
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     $oldCampaignItemIds = array();
     foreach ($campaignItems as $ci) {
         $this->assertNotEmpty($ci->id);
         $this->assertEquals(1, $ci->processed);
         $this->assertNotEmpty($ci->emailMessage->id);
         $this->assertNotEmpty($ci->emailMessage->sender->id);
         $this->assertNotEmpty($ci->emailMessage->content->id);
         $this->assertNotEmpty($ci->contact->id);
         $this->assertEquals($data['old']['subject'], $ci->emailMessage->subject);
         $this->assertEquals($data['old']['fromName'], $ci->emailMessage->sender->fromName);
         $this->assertEquals($data['old']['fromAddress'], $ci->emailMessage->sender->fromAddress);
         $this->assertContains($data['old']['textContent'], $ci->emailMessage->content->textContent);
         $this->assertContains($data['old']['htmlContent'], $ci->emailMessage->content->htmlContent);
         $oldCampaignItemIds[] = $ci->id;
     }
     $campaignItems[count($campaignItems) - 1]->delete();
     array_pop($oldCampaignItemIds);
     $campaign->status = Campaign::STATUS_ACTIVE;
     foreach ($data['new'] as $property => $value) {
         $campaign->{$property} = $value;
     }
     $this->assertTrue($campaign->save());
     $campaign->forgetAll();
     $campaignGenerateDueCampaignItemsJob = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($campaignGenerateDueCampaignItemsJob->run());
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     $allCampaignItems = CampaignItem::getAll();
     $this->assertNotEmpty($allCampaignItems);
     $this->assertCount(5, $allCampaignItems);
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(1, $campaignItems);
     $campaignQueueMessagesInOutboxJob = new CampaignQueueMessagesInOutboxJob();
     $this->assertTrue($campaignQueueMessagesInOutboxJob->run());
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     $oldCounter = 0;
     $newCounter = 0;
     foreach ($campaignItems as $ci) {
         $this->assertNotEmpty($ci->id);
         $this->assertEquals(1, $ci->processed);
         $this->assertNotEmpty($ci->emailMessage->id);
         $this->assertNotEmpty($ci->emailMessage->sender->id);
         $this->assertNotEmpty($ci->emailMessage->content->id);
         $this->assertNotEmpty($ci->contact->id);
         $dataIndex = in_array($ci->id, $oldCampaignItemIds) ? 'old' : 'new';
         if ($dataIndex == 'old') {
             $oldCounter++;
         } else {
             $newCounter++;
         }
         $this->assertEquals($data[$dataIndex]['subject'], $ci->emailMessage->subject);
         $this->assertEquals($data[$dataIndex]['fromName'], $ci->emailMessage->sender->fromName);
         $this->assertEquals($data[$dataIndex]['fromAddress'], $ci->emailMessage->sender->fromAddress);
         $this->assertContains($data[$dataIndex]['textContent'], $ci->emailMessage->content->textContent);
         $this->assertContains($data[$dataIndex]['htmlContent'], $ci->emailMessage->content->htmlContent);
     }
     $this->assertEquals(count($oldCampaignItemIds), $oldCounter);
     $this->assertEquals(count($campaignItems) - count($oldCampaignItemIds), $newCounter);
 }
 /**
  * @depends testRunWithMultipleRecipientsWithAttachments
  */
 public function testRunWithSubscribedAndUnsubscribedMembers()
 {
     $campaignItemsCountBefore = CampaignItem::getCount();
     $job = new CampaignQueueMessagesInOutboxJob();
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 10');
     $marketingListId = $marketingList->id;
     $contacts = array();
     for ($i = 0; $i < 5; $i++) {
         $email = new Email();
         $email->emailAddress = "demo{$i}@zurmo.com";
         $contact = ContactTestHelper::createContactByNameForOwner('contact 0' . ($i + 14), $this->user);
         $contact->primaryEmail = $email;
         $this->assertTrue($contact->save());
         $contacts[] = $contact;
         MarketingListMemberTestHelper::createMarketingListMember($i % 2, $marketingList, $contact);
     }
     $marketingList->forgetAll();
     $marketingList = MarketingList::getById($marketingListId);
     $campaign = CampaignTestHelper::createCampaign('campaign 10', 'subject 10', '[[FIRST^NAME]]', '[[LAST^NAME]]', null, null, null, Campaign::STATUS_PROCESSING, null, 0, $marketingList);
     $this->assertNotNull($campaign);
     $campaignId = $campaign->id;
     foreach ($contacts as $contact) {
         CampaignItemTestHelper::createCampaignItem(0, $campaign, $contact);
     }
     $this->assertTrue($job->run());
     $campaign = Campaign::getById($campaignId);
     $campaignItemsCountExpected = $campaignItemsCountBefore + 5;
     $campaignItemsCountAfter = CampaignItem::getCount();
     $this->assertEquals($campaignItemsCountExpected, $campaignItemsCountAfter);
     $campaignItemsProcessed = CampaignItem::getByProcessedAndCampaignId(1, $campaign->id);
     $this->assertCount(5, $campaignItemsProcessed);
     $skippedCount = 0;
     foreach ($campaignItemsProcessed as $campaignItem) {
         $contact = $campaignItem->contact;
         $member = MarketingListMember::getByMarketingListIdContactIdAndUnsubscribed($campaign->marketingList->id, $contact->id, true);
         if ($member) {
             $personId = $campaignItem->contact->getClassId('Person');
             $type = CampaignItemActivity::TYPE_SKIP;
             $activity = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl($type, $campaignItem->id, $personId);
             $this->assertNotNull($activity);
             $this->assertNotEmpty($activity);
             $this->assertCount(1, $activity);
             $skippedCount++;
         } else {
             $this->assertNotEmpty($campaignItem->emailMessage);
             $this->assertContains($contact->firstName, $campaignItem->emailMessage->content->textContent);
             $this->assertContains($contact->lastName, $campaignItem->emailMessage->content->htmlContent);
         }
     }
     $this->assertEquals(2, $skippedCount);
 }
コード例 #19
0
 public function testProcessDueCampaignItemContactUnsubscribed()
 {
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $email->optOut = false;
     $contact = ContactTestHelper::createContactByNameForOwner('contact 17', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 17', 'description', 'CustomFromName', '*****@*****.**');
     MarketingListMemberTestHelper::createMarketingListMember(true, $marketingList, $contact);
     $campaign = CampaignTestHelper::createCampaign('campaign 17', 'subject 17', 'Dear. Sir', 'Dear. Sir', null, null, null, null, null, null, $marketingList);
     $processed = 0;
     $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     CampaignItemsUtil::processDueItem($campaignItem);
     $this->assertEquals(1, $campaignItem->processed);
     $personId = $contact->getClassId('Person');
     $activities = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(CampaignItemActivity::TYPE_SKIP, $campaignItem->id, $personId);
     $this->assertNotEmpty($activities);
     $this->assertCount(1, $activities);
 }
 /**
  * @depends testRunWithDueActiveCampaignsWithMembers
  */
 public function testRunWithJustDueActiveCampaignsWithMembers()
 {
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05');
     $marketingListId = $marketingList->id;
     $processed = 0;
     for ($i = 6; $i <= 10; $i++) {
         $contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $i, $this->user);
         MarketingListMemberTestHelper::createMarketingListMember($processed, $marketingList, $contact);
     }
     $marketingList->forgetAll();
     $marketingList = MarketingList::getById($marketingListId);
     $nowDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $campaign = CampaignTestHelper::createCampaign('Active, Just Due With Members', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_ACTIVE, $nowDateTime, null, $marketingList);
     // we have to do this to ensure when we retrieve the data status is updated from db.
     $campaign->forgetAll();
     $this->assertEmpty(CampaignItem::getAll());
     // sleep 1 second to ensure we are giving ample time difference between creating the campaign and calling the job
     sleep(1);
     $job = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($job->run());
     $campaign = Campaign::getByName('Active, just Due With Members');
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign[0]->status);
     $allCampaignItems = CampaignItem::getAll();
     $this->assertNotEmpty($allCampaignItems);
     $this->assertCount(5, $allCampaignItems);
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaign[0]->id);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
 }
コード例 #21
0
 /**
  * @depends testRunWithCustomBatchSize
  */
 public function testRunWithContactContainingPrimaryEmailOptedOut()
 {
     $unprocessedItems = CampaignItem::getByProcessed(0);
     $this->assertCount(1, $unprocessedItems);
     $job = new CampaignQueueMessagesInOutboxJob();
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     $email->optOut = true;
     $contact = ContactTestHelper::createContactByNameForOwner('contact 07', $this->user);
     $contact->primaryEmail = $email;
     $this->assertTrue($contact->save());
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 08', 'description goes here', 'fromName', '*****@*****.**');
     $campaign = CampaignTestHelper::createCampaign('campaign 08', 'subject', '[[FIRST^NAME]]', '[[LAST^NAME]]', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
     $processed = 0;
     $campaignItem = CampaignItemTestHelper::createCampaignItem($processed, $campaign, $contact);
     $unprocessedItems = CampaignItem::getByProcessedAndCampaignId($processed, $campaign->id);
     $this->assertCount(1, $unprocessedItems);
     $this->assertTrue($job->run());
     $unprocessedItems = CampaignItem::getByProcessedAndCampaignId($processed, $campaign->id);
     $this->assertCount(0, $unprocessedItems);
     $personId = $contact->getClassId('Person');
     $activities = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(CampaignItemActivity::TYPE_SKIP, $campaignItem->id, $personId);
     $this->assertNotEmpty($activities);
     $this->assertCount(1, $activities);
 }
コード例 #22
0
 /**
  * @depends testRunWithCampaignWithProcessingStatusAndProcessedItems
  */
 public function testRunWithCustomBatchSize()
 {
     $this->purgeAllCampaigns();
     $contact = ContactTestHelper::createContactByNameForOwner('contact 03', $this->user);
     $marketingList = MarketingListTestHelper::populateMarketingListByName('marketingList 04');
     $campaign01 = CampaignTestHelper::createCampaign('campaign 01', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
     $this->assertNotNull($campaign01);
     $campaign01Id = $campaign01->id;
     CampaignItemTestHelper::createCampaignItem(1, $campaign01, $contact);
     $campaign02 = CampaignTestHelper::createCampaign('campaign 02', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
     $this->assertNotNull($campaign02);
     $campaign02Id = $campaign02->id;
     CampaignItemTestHelper::createCampaignItem(1, $campaign02, $contact);
     $campaign03 = CampaignTestHelper::createCampaign('campaign 03', 'subject', 'text Content', 'Html Content', null, null, null, Campaign::STATUS_PROCESSING, null, null, $marketingList);
     $this->assertNotNull($campaign03);
     $campaign03Id = $campaign03->id;
     $campaign01->forgetAll();
     $campaign02->forgetAll();
     $campaign03->forgetAll();
     $job = new CampaignMarkCompletedJob();
     AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize(1);
     $this->assertTrue($job->run());
     $campaign01 = Campaign::getById($campaign01Id);
     $this->assertNotNull($campaign01);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
     $campaign02 = Campaign::getById($campaign02Id);
     $this->assertNotNull($campaign02);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign02->status);
     $campaign03 = Campaign::getById($campaign03Id);
     $this->assertNotNull($campaign03);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign03->status);
     $campaign01->forgetAll();
     $campaign02->forgetAll();
     $campaign03->forgetAll();
     AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize(null);
     $this->assertTrue($job->run());
     $campaign01 = Campaign::getById($campaign01Id);
     $this->assertNotNull($campaign01);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign01->status);
     $campaign02 = Campaign::getById($campaign02Id);
     $this->assertNotNull($campaign02);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign02->status);
     $campaign03 = Campaign::getById($campaign03Id);
     $this->assertNotNull($campaign03);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign03->status);
 }
    public function generateCampaignItemsForDueCampaigns($count)
    {
        $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList Test', 'description goes here', 'fromName', '*****@*****.**');
        $marketingListId = $marketingList->id;
        $contacts = array();
        $emails = array();
        for ($i = 0; $i < $count; $i++) {
            $emails[$i] = new Email();
            $emails[$i]->emailAddress = "demo{$i}@zurmo.com";
            $account = AccountTestHelper::createAccountByNameForOwner('account ' . $i, $this->user);
            $contact = ContactTestHelper::createContactWithAccountByNameForOwner('contact ' . $i, $this->user, $account);
            $contact->primaryEmail = $emails[$i];
            $this->assertTrue($contact->save());
            $contacts[$i] = $contact;
            MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
        }
        $marketingList->forgetAll();
        $marketingList = MarketingList::getById($marketingListId);
        $content = <<<MTG
[[COMPANY^NAME]]
[[CREATED^DATE^TIME]]
[[DEPARTMENT]]
[[DESCRIPTION]]
[[FIRST^NAME]]
[[GOOGLE^WEB^TRACKING^ID]]
[[INDUSTRY]]
[[JOB^TITLE]]
[[LAST^NAME]]
[[LATEST^ACTIVITY^DATE^TIME]]
[[MOBILE^PHONE]]
[[MODIFIED^DATE^TIME]]
[[OFFICE^FAX]]
[[OFFICE^PHONE]]
[[TITLE]]
[[SOURCE]]
[[STATE]]
[[WEBSITE]]
[[MODEL^URL]]
[[BASE^URL]]
[[APPLICATION^NAME]]
[[CURRENT^YEAR]]
[[LAST^YEAR]]
[[OWNERS^AVATAR^SMALL]]
[[OWNERS^AVATAR^MEDIUM]]
[[OWNERS^AVATAR^LARGE]]
[[OWNERS^EMAIL^SIGNATURE]]
[[UNSUBSCRIBE^URL]]
[[MANAGE^SUBSCRIPTIONS^URL]]
[[PRIMARY^EMAIL__EMAIL^ADDRESS]]
[[PRIMARY^EMAIL__EMAIL^ADDRESS]]
[[SECONDARY^ADDRESS__CITY]]
[[SECONDARY^ADDRESS__COUNTRY]]
[[SECONDARY^ADDRESS__INVALID]]
[[SECONDARY^ADDRESS__LATITUDE]]
[[SECONDARY^ADDRESS__LONGITUDE]]
[[SECONDARY^ADDRESS__POSTAL^CODE]]
[[SECONDARY^ADDRESS__STATE]]
[[SECONDARY^ADDRESS__STREET1]]
[[SECONDARY^ADDRESS__STREET2]]
[[OWNER__DEPARTMENT]]
[[OWNER__FIRST^NAME]]
[[OWNER__IS^ACTIVE]]
[[OWNER__MOBILE^PHONE]]
[[OWNER__LAST^LOGIN^DATE^TIME]]
[[OWNER__LAST^NAME]]
[[CREATED^BY^USER__FIRST^NAME]]
[[CREATED^BY^USER__LAST^NAME]]
[[CREATED^BY^USER__MOBILE^PHONE]]
[[CREATED^BY^USER__TITLE]]
[[CREATED^BY^USER__USERNAME]]
[[ACCOUNT__ANNUAL^REVENUE]]
[[ACCOUNT__INDUSTRY]]
[[ACCOUNT__NAME]]
[[ACCOUNT__WEBSITE]]
[[ACCOUNT__BILLING^ADDRESS__COUNTRY]]
[[ACCOUNT__BILLING^ADDRESS__CITY]]
[[ACCOUNT__OWNER__FIRST^NAME]]
 ' " ` " '
MTG;
        $sendOnDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 600);
        $campaign = CampaignTestHelper::createCampaign('campaign Test', 'subject', $content, $content, null, null, null, Campaign::STATUS_ACTIVE, $sendOnDateTime, null, $marketingList, false);
        $fileNames = array('testImage.png', 'testZip.zip', 'testPDF.pdf');
        $files = array();
        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;
            $campaign->files->add($file);
        }
        $this->assertTrue($campaign->save(false));
        $campaignId = $campaign->id;
        $campaign->forgetAll();
        $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
        $this->assertEmpty($campaignItems);
        //Process open campaigns.
        Yii::app()->jobQueue->deleteAll();
        AutoresponderOrCampaignBatchSizeConfigUtil::setBatchSize($count);
        Yii::app()->jobQueue->deleteAll();
        $this->assertCount(0, Yii::app()->jobQueue->getAll());
        ForgetAllCacheUtil::forgetAllCaches();
        $job = new CampaignGenerateDueCampaignItemsJob();
        $startedAt = microtime(true);
        $this->assertTrue($job->run());
        $timeTaken = microtime(true) - $startedAt;
        ForgetAllCacheUtil::forgetAllCaches();
        $campaign->forgetAll();
        unset($campaign);
        $campaign = Campaign::getById($campaignId);
        $this->assertNotNull($campaign);
        $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
        $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
        $this->assertNotEmpty($campaignItems);
        $this->assertCount($count, $campaignItems);
        return $timeTaken;
    }
コード例 #24
0
 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
 }
コード例 #25
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));
 }