/**
  * @depends testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForInvalidPersonIdForUrlClickTracking
  * @expectedException NotSupportedException
  */
 public function testResolveQueryStringFromUrlAndCreateOrUpdateActivityThrowsExceptionForDuplicateActivityForUrlClickTracking()
 {
     // setup pre-req data
     $campaignItemActivities = CampaignItemActivity::getByType(CampaignItemActivity::TYPE_CLICK);
     $this->assertNotEmpty($campaignItemActivities);
     $campaignActivity = new CampaignItemActivity();
     $campaignActivity->quantity = $campaignItemActivities[0]->quantity;
     $campaignActivity->type = $campaignItemActivities[0]->type;
     $campaignActivity->campaignItem = $campaignItemActivities[0]->campaignItem;
     $campaignActivity->person = $campaignItemActivities[0]->person;
     $campaignActivity->emailMessageUrl = $campaignItemActivities[0]->emailMessageUrl;
     $this->assertTrue($campaignActivity->save());
     $modelId = $campaignItemActivities[0]->campaignItem->id;
     $modelType = get_class($campaignItemActivities[0]->campaignItem);
     $personId = $campaignItemActivities[0]->person->id;
     // 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(2, $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();
 }
 public static function resolveHashByArray(array $queryStringArray)
 {
     if (!static::isValidQueryStringArray($queryStringArray)) {
         throw new NotSupportedException();
     }
     unset($queryStringArray['preview']);
     unset($queryStringArray['isHtmlContent']);
     ArrayUtil::setToDefaultValueIfMissing($queryStringArray, 'createNewActivity', false);
     return StringUtil::resolveHashForQueryStringArray($queryStringArray);
 }
 /**
  * @depends testTrackActionDoesNotComplainForMissingUrlParameterForCampaignItem
  */
 public function testTrackActionThrowsRedirectExceptionForUrlParameterForCampaignItem()
 {
     $queryStringArray = array('modelId' => static::$campaignItemId, 'modelType' => 'CampaignItem', 'personId' => static::$personId, 'url' => 'http://www.zurmo.com');
     $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
     $this->setGetArray(array('id' => $hash));
     $url = $this->runControllerWithRedirectExceptionAndGetUrl(static::TRACK_ROUTE);
     $this->assertEquals($queryStringArray['url'], $url);
     $campaignItemActivity = CampaignItemActivity::getByTypeAndModelIdAndPersonIdAndUrl(CampaignItemActivity::TYPE_CLICK, static::$campaignItemId, static::$personId, $queryStringArray['url']);
     $this->assertNotEmpty($campaignItemActivity);
     $this->assertCount(1, $campaignItemActivity);
     $this->assertEquals(1, $campaignItemActivity[0]->quantity);
 }
 protected static function resolveTrackingUrlForLink($link)
 {
     if (!static::isMarketingExternalUrl($link)) {
         $queryStringArray = static::$baseQueryStringArray;
         $queryStringArray['url'] = StringUtil::addSchemeIfMissing($link);
         $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
         $link = static::resolveAbsoluteTrackingUrlByHash($hash);
     }
     return $link;
 }
 public function testResolveQueryStringArrayForHashWithAndWithoutUrlInQueryString()
 {
     // test without url
     $modelId = 1;
     $modelType = 'AutoresponderItem';
     $personId = 10;
     $className = 'EmailMessageActivityUtil';
     $resolveBaseQueryStringArrayFunction = static::getProtectedMethod('ContentTrackingUtil', 'resolveBaseQueryStringArray');
     $withoutUrlQueryStringArray = $resolveBaseQueryStringArrayFunction->invokeArgs(null, array($modelId, $modelType, $personId));
     $this->assertNotEmpty($withoutUrlQueryStringArray);
     $this->assertCount(3, $withoutUrlQueryStringArray);
     $this->assertArrayHasKey('modelId', $withoutUrlQueryStringArray);
     $this->assertArrayHasKey('modelType', $withoutUrlQueryStringArray);
     $this->assertArrayHasKey('personId', $withoutUrlQueryStringArray);
     $withoutUrlQueryStringArrayHash = StringUtil::resolveHashForQueryStringArray($withoutUrlQueryStringArray);
     $withoutUrlQueryStringArrayDecoded = $className::resolveQueryStringArrayForHash($withoutUrlQueryStringArrayHash);
     $this->assertTrue(is_array($withoutUrlQueryStringArrayDecoded));
     $this->assertCount(5, $withoutUrlQueryStringArrayDecoded);
     $this->assertArrayHasKey('modelId', $withoutUrlQueryStringArrayDecoded);
     $this->assertArrayHasKey('modelType', $withoutUrlQueryStringArrayDecoded);
     $this->assertArrayHasKey('personId', $withoutUrlQueryStringArrayDecoded);
     $this->assertArrayHasKey('url', $withoutUrlQueryStringArrayDecoded);
     $this->assertArrayHasKey('type', $withoutUrlQueryStringArrayDecoded);
     $this->assertEquals($withoutUrlQueryStringArray['modelId'], $withoutUrlQueryStringArrayDecoded['modelId']);
     $this->assertEquals($withoutUrlQueryStringArray['modelType'], $withoutUrlQueryStringArrayDecoded['modelType']);
     $this->assertEquals($withoutUrlQueryStringArray['personId'], $withoutUrlQueryStringArrayDecoded['personId']);
     $this->assertNull($withoutUrlQueryStringArrayDecoded['url']);
     $this->assertNull($withoutUrlQueryStringArrayDecoded['type']);
     // try same thing with url in the query string array.
     $withUrlQueryStringArray = CMap::mergeArray($withoutUrlQueryStringArray, array('url' => 'http://www.zurmo.com', 'type' => null));
     $withUrlQueryStringArrayHash = StringUtil::resolveHashForQueryStringArray($withUrlQueryStringArray);
     $withUrlQueryStringArrayDecoded = $className::resolveQueryStringArrayForHash($withUrlQueryStringArrayHash);
     $this->assertEquals($withUrlQueryStringArray, $withUrlQueryStringArrayDecoded);
 }
 /**
  * @depends testOptOutActionThrowNotSupportedExceptionForDecipherableHexadecimalHashWithMissingParameters
  * @expectedException NotSupportedException
  */
 public function testManageSubscriptionsActionThrowNotSupportedExceptionForDecipherableHexadecimalHashWithMissingParameters()
 {
     $queryStringArray = array('keyOne' => 'valueOne', 'keyTwo' => 'valueTwo', 'keyThree' => 'ValueThree');
     $hash = StringUtil::resolveHashForQueryStringArray($queryStringArray);
     $this->setGetArray(array('hash' => $hash));
     $this->runControllerWithNoExceptionsAndGetContent($this->manageSubscriptionsUrl);
 }