Exemple #1
0
 public function test_main_shouldReturnErrorResponse_InCaseOfAnyError()
 {
     $requestSet = new RequestSet();
     $requestSet->enableThrowExceptionOnInit();
     $handler = $this->getHandler();
     $handler->setResponse(new Response());
     $response = $this->tracker->main($handler, $requestSet);
     $this->assertSame('{"status":"error","tracked":0,"invalid":0}', $response);
 }
 private function setDummyRequests($useTokenAuth = true)
 {
     if ($useTokenAuth) {
         $useTokenAuth = Fixture::getTokenAuth();
     }
     $this->requestSet->setRequests(array(array('idsite' => 1, 'url' => 'http://localhost/foo?bar', 'cip' => '192.168.33.11', 'token_auth' => $useTokenAuth), array('idsite' => 1, 'url' => 'http://localhost', 'cip' => '192.168.33.11', 'token_auth' => $useTokenAuth)));
 }
 public function test_process_ShouldTrackAllSetRequests()
 {
     $this->assertSame(0, $this->tracker->getCountOfLoggedRequests());
     $this->requestSet->setRequests(array(array('idsite' => 1, 'url' => 'http://localhost/foo?bar'), array('idsite' => 1, 'url' => 'http://localhost')));
     $this->handler->process($this->tracker, $this->requestSet);
     $this->assertSame(2, $this->tracker->getCountOfLoggedRequests());
 }
 public function test_track_shouldNotTrackAnything_IfNoRequestsAreSet()
 {
     $this->requestSet->setRequests(array());
     $this->tracker->track($this->handler, $this->requestSet);
     $this->assertFalse($this->handler->isOnStartTrackRequests);
     $this->assertFalse($this->handler->isProcessed);
     $this->assertFalse($this->handler->isOnAllRequestsTracked);
     $this->assertFalse($this->handler->isOnException);
 }
 protected function buildRequestSetContainingError($numberOfRequestSets, $indexThatShouldContainError, $useInvalidSiteError = false)
 {
     $requests = array();
     for ($i = 0; $i < $numberOfRequestSets; $i++) {
         if ($i === $indexThatShouldContainError) {
             if ($useInvalidSiteError) {
                 $requests[] = new Request(array('idsite' => '0', 'index' => $i));
             } else {
                 $requests[] = new Request(array('idsite' => '1', 'index' => $i, 'forceThrow' => 1));
             }
         } else {
             $requests[] = new Request(array('idsite' => '1', 'index' => $i));
         }
     }
     $set = new RequestSet();
     $set->setRequests($requests);
     return $set;
 }
Exemple #6
0
 public function test_main_shouldPostEndEvent_EvenIfThereIsAnException()
 {
     $called = false;
     Piwik::addAction('Tracker.end', function () use(&$called) {
         $called = true;
     });
     $handler = new Handler();
     $handler->enableTriggerExceptionInProcess();
     $requestSet = new RequestSet();
     $requestSet->setRequests(array($this->buildRequest(1), $this->buildRequest(1)));
     $this->tracker->main($handler, $requestSet);
     $this->assertTrue($handler->isOnException);
     $this->assertTrue($called);
 }