public function test_getNumUsableCustomVariables_ShouldReturnMinVariables_IfOneTableHasLessEntriesThanOthers() { $this->assertEquals(5, CustomVariables::getNumUsableCustomVariables()); $scopes = Model::getScopes(); // removing custom vars step by step... as soon as one custom var is removed, // it should return the min count of available variables for ($i = 4; $i != -1; $i--) { foreach ($scopes as $scope) { $this->dropCustomVar($scope); $this->assertSame($i, CustomVariables::getNumUsableCustomVariables()); } } $this->assertEquals(0, CustomVariables::getNumUsableCustomVariables()); // add custom var, only once all custom vars are written it should write return a higher custom var number for ($i = 1; $i != 7; $i++) { foreach ($scopes as $index => $scope) { $isLastIndex = $index === count($scopes) - 1; $this->addCustomVar($scope); if ($isLastIndex) { $this->assertSame($i, CustomVariables::getNumUsableCustomVariables()); // all scopes have been added, it should consider all custom var counts } else { $this->assertSame($i - 1, CustomVariables::getNumUsableCustomVariables()); // at least one scope is not added and should therefore return the old custom var count until all // tables have been updated } } } $this->assertEquals(6, CustomVariables::getNumUsableCustomVariables()); }
private function setUpCustomVars() { foreach (Model::getScopes() as $scope) { $model = new Model($scope); $model->addCustomVariable(); $model->addCustomVariable(); $model->addCustomVariable(); } }
private function hasEverywhereSameAmountOfVariables() { $indexesBefore = null; foreach (Model::getScopes() as $scope) { $model = new Model($scope); $indexes = $model->getCustomVarIndexes(); if (is_null($indexesBefore)) { $indexesBefore = $indexes; } elseif ($indexes != $indexesBefore) { return false; } } return true; }
public static function getMaxCustomVariables() { $cache = Cache::getCacheGeneral(); $cacheKey = 'CustomVariables.MaxNumCustomVariables'; if (!array_key_exists($cacheKey, $cache)) { $maxCustomVar = 0; foreach (Model::getScopes() as $scope) { $model = new Model($scope); $highestIndex = $model->getHighestCustomVarIndex(); if ($highestIndex > $maxCustomVar) { $maxCustomVar = $highestIndex; } } $cache[$cacheKey] = $maxCustomVar; Cache::setCacheGeneral($cache); } return $cache[$cacheKey]; }
/** * Returns the number of available custom variables that can be used. * * "Can be used" is identifed by the minimum number of available custom variables across all relevant tables. Eg * if there are 6 custom variables installed in log_visit but only 5 in log_conversion, we consider only 5 custom * variables as usable. * @return int */ public static function getNumUsableCustomVariables() { $cache = Cache::getCacheGeneral(); $cacheKey = 'CustomVariables.NumUsableCustomVariables'; if (!array_key_exists($cacheKey, $cache)) { $minCustomVar = null; foreach (Model::getScopes() as $scope) { $model = new Model($scope); $highestIndex = $model->getHighestCustomVarIndex(); if (!isset($minCustomVar)) { $minCustomVar = $highestIndex; } if ($highestIndex < $minCustomVar) { $minCustomVar = $highestIndex; } } if (!isset($minCustomVar)) { $minCustomVar = 0; } $cache[$cacheKey] = $minCustomVar; Cache::setCacheGeneral($cache); } return $cache[$cacheKey]; }
public function testGetAllScopes() { $this->assertEquals(self::$cvarScopes, Model::getScopes()); }
private function getNumberOfChangesToPerform($numVarsToSet) { $numChangesToPerform = 0; foreach (Model::getScopes() as $scope) { $model = new Model($scope); $numCurrentCustomVars = $model->getCurrentNumCustomVars(); $numChangesToPerform += $this->getAbsoluteDifference($numCurrentCustomVars, $numVarsToSet); } return $numChangesToPerform; }
public function testGetAllScopes() { $this->assertEquals(array('log_link_visit_action', 'log_visit', 'log_conversion'), Model::getScopes()); }