setUpWebsitesAndGoals(); $this->setMockLocationProvider(); $this->trackVisits(9, false); $this->setLocationProvider('GeoIP2-City.mmdb'); $this->trackVisits(2, true, $useLocal = false); $this->trackVisits(4, true, $useLocal = false, $doBulk = true); $this->setLocationProvider('GeoIP2-Country.mmdb'); $this->trackVisits(2, true); $this->trackOtherVisits(); $this->setLocationProvider('GeoIP2-City.mmdb'); } public function tearDown(): void { $this->unsetLocationProvider(); } private function setUpWebsitesAndGoals() { if (!self::siteCreated($this->idSite)) { self::createWebsite($this->dateTime, 0, "Site " . $this->idSite); } if (!self::goalExists($this->idSite, $idGoal = 1)) { $this->idGoal = API::getInstance()->addGoal($this->idSite, 'all', 'url', 'http', 'contains', false, 5); } if (!self::goalExists($this->idSite, $idGoal = 2)) { $this->idGoal2 = API::getInstance()->addGoal($this->idSite, 'two', 'url', 'xxxxxxxxxxxxx', 'contains', false, 5, false, 'twodesc'); } } protected $calledCounter = 0; private function trackVisits($visitorCount, $setIp = false, $useLocal = true, $doBulk = false) { $this->calledCounter++; $dateTime = $this->dateTime; $idSite = $this->idSite; if ($useLocal) { Cache::getTransientCache()->flushAll(); // make sure dimension cache is empty between local tracking runs Visit::$dimensions = null; } // use local tracker so mock location provider can be used $t = self::getTracker($idSite, $dateTime, $defaultInit = true, $useLocal); if ($doBulk) { $t->enableBulkTracking(); } $t->setTokenAuth(self::getTokenAuth()); for ($i = 0; $i != $visitorCount; ++$i) { $this->trackVisit($t, $this->calledCounter, $i, $doBulk, array('setIp' => $setIp)); } if ($doBulk) { self::checkBulkTrackingResponse($t->doBulkTrack()); } } /** * Insert a new visit into the database. * @param \MatomoTracker $t The tracker to record the visits on * @param int $fixtureCounter Number of times this fixture has been run * @param int $visitorCounter Visitor counter within this execution of the fixture * @param boolean $doBulk Should this visit be left for bulk insert later, or processed now? * @param array $params Other params as required to set up the visit */ protected function trackVisit(\MatomoTracker $t, $fixtureCounter, $visitorCounter, $doBulk, array $params) { $setIp = isset($params['setIp']) && $params['setIp']; // NOTE: floor() is so some visits share the same visit ID $t->setVisitorId( substr(md5(floor($visitorCounter / 2) + $fixtureCounter * 1000), 0, $t::LENGTH_VISITOR_ID)); $userAgent = null; if ($setIp) { $userAgent = current($this->userAgents); $t->setIp(current($this->ips)); $t->setUserAgent($userAgent); next($this->userAgents); next($this->ips); } else { $t->setIp("1.2.4.$visitorCounter"); } // first visit $date = Date::factory($this->dateTime)->addDay($visitorCounter); $t->setForceVisitDateTime($date->getDatetime()); $t->setUrl("http://piwik.net/grue/lair"); $t->setCustomVariable(1, 'Cvar 1 name', 'Cvar1 value is ' .$visitorCounter , 'visit'); $t->setCustomVariable(5, 'Cvar 5 name', 'Cvar5 value is ' .$visitorCounter , 'visit'); $t->setCustomVariable(2, 'Cvar 2 PAGE name', 'Cvar2 PAGE value is ' .$visitorCounter, 'page'); $t->setCustomVariable(5, 'Cvar 5 PAGE name', 'Cvar5 PAGE value is ' .$visitorCounter, 'page'); $r = $t->doTrackPageView('It\'s