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);
 }
 /**
  * @expectedException NotSupportedException
  */
 public function testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionWhenNoIdInQueryString()
 {
     CampaignItemActivityUtil::resolveQueryStringFromUrlAndCreateOrUpdateActivity();
 }