setUpWebsitesAndGoals(); $this->trackVisits(); } public function tearDown() { // empty } private function setUpWebsitesAndGoals() { // tests run in UTC, the Tracker in UTC self::createWebsite($this->dateTime); } private function trackVisits() { $dateTime = $this->dateTime; $idSite = $this->idSite; $t = self::getTracker($idSite, $dateTime, $defaultInit = true); // First, some basic tests self::settingInvalidVisitorIdShouldThrow($t); // We create VISITOR A $t->setUrl('http://example.org/index.htm'); $t->setVisitorId(Piwik_Tracker_Visit::generateUniqueVisitorId()); self::checkResponse($t->doTrackPageView('incredible title!')); // VISITOR B: few minutes later, we trigger the same tracker but with a custom visitor ID, // => this will create a new visit B $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.05)->getDatetime()); $t->setUrl('http://example.org/index2.htm'); $t->setVisitorId(Piwik_Tracker_Visit::generateUniqueVisitorId()); self::checkResponse($t->doTrackPageView('incredible title!')); // This new visit B will have 2 page views $t->setForceVisitDateTime(Piwik_Date::factory($dateTime)->addHour(0.1)->getDatetime()); $t->setUrl('http://example.org/index3.htm'); self::checkResponse($t->doTrackPageView('incredible title!')); // total = 2 visitors, 3 page views } private static function settingInvalidVisitorIdShouldThrow(PiwikTracker $t) { try { $t->setVisitorId('test'); $this->fail('should throw'); } catch (Exception $e) { //OK } try { $t->setVisitorId('61e8'); $this->fail('should throw'); } catch (Exception $e) { //OK } try { $t->setVisitorId('61e8cc2d51fea26dabcabcabc'); $this->fail('should throw'); } catch (Exception $e) { //OK } } }