Esempio n. 1
0
 public function testWebArchiving()
 {
     if (self::isMysqli() && self::isTravisCI()) {
         $this->markTestSkipped('Skipping on Mysqli as it randomly fails.');
     }
     self::$fixture->setUp();
     self::deleteArchiveTables();
     $host = Fixture::getRootUrl();
     $token = Fixture::getTokenAuth();
     $urlTmp = Option::get('piwikUrl');
     Option::set('piwikUrl', $host . 'tests/PHPUnit/proxy/index.php');
     $streamContext = stream_context_create(array('http' => array('timeout' => 180)));
     $url = $host . 'tests/PHPUnit/proxy/archive.php?token_auth=' . $token . '&forcelogtoscreen=1';
     $output = file_get_contents($url, 0, $streamContext);
     // ignore random build issues
     if (empty($output) || strpos($output, \Piwik\CronArchive::NO_ERROR) === false) {
         $message = "This test has failed. Because it sometimes randomly fails, we skip the test, and ignore this failure.\n";
         $message .= "If you see this message often, or in every build, please investigate as this should only be a random and rare occurence!\n";
         $message .= "\n\narchive web failed: " . $output . "\n\nurl used: {$url}";
         $this->markTestSkipped($message);
     }
     if (!empty($urlTmp)) {
         Option::set('piwikUrl', $urlTmp);
     } else {
         Option::delete('piwikUrl');
     }
     $this->assertContains('Starting Piwik reports archiving...', $output);
     $this->assertContains('Archived website id = 1', $output);
     $this->assertContains('Done archiving!', $output);
     $this->compareArchivePhpOutputAgainstExpected($output);
 }
Esempio n. 2
0
 public function setUp()
 {
     parent::setUp();
     $this->cliMulti = new CliMulti();
     $this->authToken = Fixture::getTokenAuth();
     $this->urls = array('getAnswerToLife' => $this->completeUrl('?module=API&method=ExampleAPI.getAnswerToLife&format=JSON'), 'getPiwikVersion' => $this->completeUrl('?module=API&method=API.getPiwikVersion&format=JSON'));
     $this->responses = array('getAnswerToLife' => '{"value":42}', 'getPiwikVersion' => '{"value":"' . Version::VERSION . '"}');
     \Piwik\Common::$isCliMode = true;
 }
Esempio n. 3
0
 /**
  * Creates a tracking object that invokes the tracker directly (w/o going through HTTP).
  */
 public static function getLocalTracker($idSite)
 {
     $t = new Piwik_LocalTracker($idSite, Fixture::getTrackerUrl());
     $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)");
     $t->setBrowserLanguage('fr');
     $t->setLocalTime('12:34:06');
     $t->setResolution(1024, 768);
     $t->setBrowserHasCookies(true);
     $t->setPlugins($flash = true, $java = true, $director = false);
     $t->setTokenAuth(Fixture::getTokenAuth());
     return $t;
 }
Esempio n. 4
0
 protected static function _addLogData()
 {
     // tracks visits on the following days:
     // - 2012-01-09
     // - 2012-01-14
     // - 2012-01-19
     // - 2012-01-24 <--- everything before this date is to be purged
     // - 2012-01-29
     // - 2012-02-03
     // - 2012-02-08
     // - 2012-02-13
     // - 2012-02-18
     // - 2012-02-23
     // - 2012-02-28
     // 6 visits in feb, 5 in jan
     // following actions are created:
     // - 'First page view'
     // - 'Second page view'
     // - 'SKU2'
     // - 'Canon SLR'
     // - 'Electronics & Cameras'
     // - for every visit (11 visits total):
     //   - http://whatever.com/_{$daysSinceLastVisit}
     //   - http://whatever.com/42/{$daysSinceLastVisit}
     $start = Date::factory(self::$dateTime);
     self::$idSite = Fixture::createWebsite('2012-01-01', $ecommerce = 1);
     $idGoal = APIGoals::getInstance()->addGoal(self::$idSite, 'match all', 'url', 'http', 'contains');
     $t = Fixture::getTracker(self::$idSite, $start, $defaultInit = true);
     $t->enableBulkTracking();
     $t->setTokenAuth(Fixture::getTokenAuth());
     for ($daysAgo = self::$daysAgoStart; $daysAgo >= 0; $daysAgo -= 5) {
         $dateTime = $start->subDay($daysAgo)->toString();
         $t->setForceVisitDateTime($dateTime);
         $t->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)');
         // use $daysAgo to make sure new actions are created for every day and aren't used again.
         // when deleting visits, some of these actions will no longer be referenced in the DB.
         $t->setUrl("http://whatever.com/_{$daysAgo}");
         $t->doTrackPageView('First page view');
         $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.05));
         $t->setUrl("http://whatever.com/42/{$daysAgo}");
         $t->doTrackPageView('Second page view');
         $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.1));
         $t->setUrl("http://whatever.com/event");
         $t->doTrackEvent('Event action', 'event cat', 'daysAgo=' . $daysAgo, 1000);
         $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.2));
         $t->addEcommerceItem($sku = 'SKU2', $name = 'Canon SLR', $category = 'Electronics & Cameras', $price = 1500, $quantity = 1);
         $t->doTrackEcommerceOrder($orderId = '937nsjusu ' . $dateTime, $grandTotal = 1111.11, $subTotal = 1000, $tax = 111, $shipping = 0.11, $discount = 666);
     }
     Fixture::checkBulkTrackingResponse($t->doBulkTrack());
 }
Esempio n. 5
0
 public function test_trackingApiWithBulkRequests_viaCurl_withCorrectTokenAuth()
 {
     $token_auth = Fixture::getTokenAuth();
     \Piwik\Filesystem::deleteAllCacheOnUpdate();
     $this->issueBulkTrackingRequest($token_auth, $expectTrackingToSucceed = true);
 }