public function test_fetchRemoteFile() { Piwik::createConfigObject(); Piwik_Config::getInstance()->setTestEnvironment(); $methods = array('curl', 'fopen', 'socket'); $this->assertTrue(in_array(Piwik_Http::getTransportMethod(), $methods)); foreach ($methods as $method) { $version = ''; try { $version = Piwik_Http::sendHttpRequestBy($method, 'http://api.piwik.org/1.0/getLatestVersion/', 5); } catch (Exception $e) { var_dump($e->getMessage()); } $this->assertTrue(preg_match('/^([0-9.]+)$/', $version), $method); } $destinationPath = PIWIK_USER_PATH . '/tmp/latest/LATEST'; try { Piwik_Http::fetchRemoteFile('http://api.piwik.org/1.0/getLatestVersion/', $destinationPath, 3); } catch (Exception $e) { var_dump($e->getMessage()); } $this->assertTrue(filesize($destinationPath) > 0); $destinationPath = PIWIK_USER_PATH . '/tmp/latest/latest.zip'; try { Piwik_Http::fetchRemoteFile('http://piwik.org/latest.zip', $destinationPath, 3); } catch (Exception $e) { var_dump($e->getMessage()); } $this->assertTrue(filesize($destinationPath) > 0); }
/** * @group Core * @group Http */ public function testFetchLatestZip() { $destinationPath = PIWIK_USER_PATH . '/tmp/latest/latest.zip'; Piwik_Http::fetchRemoteFile('http://piwik.org/latest.zip', $destinationPath, 3); $this->assertFileExists($destinationPath); $this->assertGreaterThan(0, filesize($destinationPath)); }
private function oneClick_Download() { $this->pathPiwikZip = PIWIK_USER_PATH . self::PATH_TO_EXTRACT_LATEST_VERSION . 'latest.zip'; Piwik::checkDirectoriesWritableOrDie(array(self::PATH_TO_EXTRACT_LATEST_VERSION)); // we catch exceptions in the caller (i.e., oneClickUpdate) $url = Zend_Registry::get('config')->General->latest_version_url . '?cb=' . $this->newVersion; $fetched = Piwik_Http::fetchRemoteFile($url, $this->pathPiwikZip); }
protected static function trackVisits() { $dateTime = self::$dateTime; $idSite = self::$idSite; /* // Trigger invalid website $trackerInvalidWebsite = self::getTracker($idSiteFake = 0, $dateTime, $defaultInit = true); $response = Piwik_Http::fetchRemoteFile($trackerInvalidWebsite->getUrlTrackPageView()); self::assertTrue(strpos($response, 'Invalid idSite') !== false, 'invalid website ID'); // Trigger wrong website $trackerWrongWebsite = self::getTracker($idSiteFake = 33, $dateTime, $defaultInit = true); $response = Piwik_Http::fetchRemoteFile($trackerWrongWebsite->getUrlTrackPageView()); self::assertTrue(strpos($response, 'The requested website id = 33 couldn\'t be found') !== false, 'non-existent website ID'); */ // Trigger empty request $trackerUrl = self::getTrackerUrl(); $response = Piwik_Http::fetchRemoteFile($trackerUrl); self::assertTrue(strpos($response, 'is a free open source web') !== false, 'Piwik empty request response not correct: ' . $response); $t = self::getTracker($idSite, $dateTime, $defaultInit = true); // test GoogleBot UA visitor $t->setUserAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); self::checkResponse($t->doTrackPageView('bot visit, please do not record')); // Test IP Exclusion works with or without IP exclusion foreach (array(false, true) as $enable) { // Enable IP Anonymization $t->DEBUG_APPEND_URL = '&forceIpAnonymization=' . (int) $enable; // test with excluded IP $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)'); // restore normal user agent $excludedIp = '154.1.12.34'; Piwik_SitesManager_API::getInstance()->updateSite($idSite, 'new site name', $url = array('http://site.com'), $ecommerce = 0, $excludedIp . ',1.2.3.4'); $t->setIp($excludedIp); self::checkResponse($t->doTrackPageView('visit from IP excluded')); // test with global list of excluded IPs $excludedIpBis = '145.5.3.4'; Piwik_SitesManager_API::getInstance()->setGlobalExcludedIps($excludedIpBis); $t->setIp($excludedIpBis); self::checkResponse($t->doTrackPageView('visit from IP globally excluded')); } try { @$t->setAttributionInfo(array()); self::fail(); } catch (Exception $e) { } try { $t->setAttributionInfo(json_encode('test')); self::fail(); } catch (Exception $e) { } $t->setAttributionInfo(json_encode(array())); }