public function testWebArchiving() { if (self::isMysqli() && self::isTravisCI()) { $this->markTestSkipped('Skipping on Mysqli as it randomly fails.'); } $host = Fixture::getRootUrl(); $token = Fixture::getTokenAuth(); $urlTmp = Option::get('piwikUrl'); Option::set('piwikUrl', $host . 'tests/PHPUnit/proxy/index.php'); $url = $host . 'tests/PHPUnit/proxy/archive.php?token_auth=' . $token; $output = Http::sendHttpRequest($url, 600); // 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); }
function checkPiwikSetupForTests() { if (empty($_SERVER['REQUEST_URI']) || $_SERVER['REQUEST_URI'] == '@REQUEST_URI@') { echo "WARNING: for tests to pass, you must first:\n1) Install webserver on localhost, eg. apache\n2) Make these Piwik files available on the webserver, at eg. http://localhost/dev/piwik/\n3) Install Piwik by going through the installation process\n4) Copy phpunit.xml.dist to phpunit.xml\n5) Edit in phpunit.xml the @REQUEST_URI@ and replace with the webserver path to Piwik, eg. '/dev/piwik/'\n\nTry again.\n-> If you still get this message, you can work around it by specifying Host + Request_Uri at the top of this file tests/PHPUnit/bootstrap.php. <-"; exit(1); } $baseUrl = \Piwik\Tests\Fixture::getRootUrl(); \Piwik\SettingsPiwik::checkPiwikServerWorking($baseUrl, $acceptInvalidSSLCertificates = true); }
/** * @group Core * @dataProvider getMethodsToTest */ public function testCustomByteRange($method) { $result = Http::sendHttpRequestBy($method, Fixture::getRootUrl() . '/piwik.js', 30, $userAgent = null, $destinationPath = null, $file = null, $followDepth = 0, $acceptLanguage = false, $acceptInvalidSslCertificate = false, $byteRange = array(10, 20), $getExtendedInfo = true); if ($method != 'fopen') { $this->assertEquals(206, $result['status']); $this->assertTrue(isset($result['headers']['Content-Range'])); $this->assertEquals('bytes 10-20/', substr($result['headers']['Content-Range'], 0, 12)); $this->assertEquals('application/x-javascript', $result['headers']['Content-Type']); } }
private function getResponseHeader($url) { if (!function_exists('curl_init')) { $this->markTestSkipped('Curl is not installed'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, Fixture::getRootUrl() . 'tests/PHPUnit/proxy/' . $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $response = curl_exec($ch); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $headerSize); curl_close($ch); return $header; }
protected function issueBulkTrackingRequest($token_auth, $expectTrackingToSucceed) { $piwikHost = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php'; $command = 'curl -s -X POST -d \'{"requests":["?idsite=1&url=http://example.org&action_name=Test bulk log Pageview&rec=1","?idsite=1&url=http://example.net/test.htm&action_name=Another bulk page view&rec=1"],"token_auth":"' . $token_auth . '"}\' ' . $piwikHost; exec($command, $output, $result); if ($result !== 0) { throw new Exception("tracking bulk failed: " . implode("\n", $output) . "\n\ncommand used: {$command}"); } $output = implode("", $output); $this->assertStringStartsWith('{"status":', $output); if ($expectTrackingToSucceed) { $this->assertNotContains('error', $output); $this->assertContains('success', $output); } else { $this->assertContains('error', $output); $this->assertNotContains('success', $output); } }
/** * Helper methods */ private function getStaticSrvUrl() { $url = Fixture::getRootUrl(); $url .= '/tests/resources/'; return $url . "staticFileServer.php?" . FILE_MODE_REQUEST_VAR . "=" . STATIC_SERVER_MODE . "&" . SRV_MODE_REQUEST_VAR . "="; }
/** * Helper methods */ private function getStaticSrvUrl() { return Fixture::getRootUrl(); }
private function runArchivePhpCron() { $archivePhpScript = PIWIK_INCLUDE_PATH . '/tests/PHPUnit/proxy/archive.php'; $urlToProxy = Fixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php'; // create the command $cmd = "php \"{$archivePhpScript}\" --url=\"{$urlToProxy}\" 2>&1"; // run the command exec($cmd, $output, $result); if ($result !== 0 || stripos($result, "error")) { $message = 'This failed once after a lunar eclipse, and it has again randomly failed.'; $message .= "\n\narchive cron failed: " . implode("\n", $output) . "\n\ncommand used: {$cmd}"; $this->markTestSkipped($message); } return $output; }
private function completeUrl($query) { $host = Fixture::getRootUrl(); if (false === strpos($query, '?')) { $query .= '?'; } else { $query .= '&'; } return $host . 'tests/PHPUnit/proxy/index.php' . $query . 'testmode=1&token_auth=' . $this->authToken; }