public function test_popAll_shouldRemoveAllProfiles() { $this->pushProfile('2014-01-01 00:01:02'); $this->pushProfile('2014-01-01 00:01:03', 'OtherCategory'); $this->pushProfile('2014-01-01 00:01:04', 'Category', 'otherName'); $this->assertCount(3, $this->profiles->popAll()); $this->assertSame(array(), $this->profiles->popAll()); }
/** * To test execute the following command: * `./console core:run-scheduled-tasks "Piwik\Plugins\AnonymousPiwikUsageMeasurement\Tasks.sendSystemReport"` * * @throws \Exception */ public function sendSystemReport() { $trackers = $this->trackers->makeTrackers(); $customVars = $this->customVars->getServerVisitCustomVariables(); $profiles = $this->profiles->popAll(); foreach ($trackers as $tracker) { $tracker->enableBulkTracking(); foreach ($customVars as $customVar) { $tracker->setCustomVariable($customVar['id'], $customVar['name'], $customVar['value'], 'visit'); } $tracker->setAnonymousUrl('/system-report'); $tracker->doTrackPageView('System-Report'); foreach ($profiles as $profile) { $countAppendix = ' (count)'; $tracker->doTrackEvent($profile['category'] . $countAppendix, $profile['action'] . $countAppendix, $profile['name'] . $countAppendix, $profile['count']); if ($profile['count'] > 0) { $speedAppendix = ' (speed)'; $wallTimeAvg = round($profile['wall_time'] / $profile['count'], 1); $tracker->doTrackEvent($profile['category'] . $speedAppendix, $profile['action'] . $speedAppendix, $profile['name'] . $speedAppendix, $wallTimeAvg); } } $tracker->doBulkTrack(); } }
public function test_shouldTrackApiCall() { Request::processRequest('API.getPiwikVersion'); Request::processRequest('API.getSettings'); Request::processRequest('UsersManager.getUsers'); Request::processRequest('API.getPiwikVersion'); $profiles = new Profiles(); $pushedProfiles = $profiles->popAll(); foreach ($pushedProfiles as &$pushedProfile) { $this->assertNotEmpty($pushedProfile['creation_date']); unset($pushedProfile['creation_date']); $this->assertGreaterThanOrEqual(1, $pushedProfile['wall_time']); unset($pushedProfile['wall_time']); } $expected = array(array('category' => 'API', 'name' => 'API', 'action' => 'API.getPiwikVersion', 'count' => '2'), array('category' => 'API', 'name' => 'API', 'action' => 'API.getSettings', 'count' => '1'), array('category' => 'API', 'name' => 'UsersManager', 'action' => 'UsersManager.getUsers', 'count' => '1')); $this->assertEquals($expected, $pushedProfiles); }