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); }
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 = Fixture::getRootUrl(); \Piwik\SettingsPiwik::checkPiwikServerWorking($baseUrl, $acceptInvalidSSLCertificates = true); }
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); $output = implode("", $output); if ($result !== 0) { throw new Exception("tracking bulk failed: " . implode("\n", $output) . "\n\ncommand used: {$command}"); } $this->assertStringStartsWith('{"status":', $output); if ($expectTrackingToSucceed) { $this->assertNotContains('error', $output); $this->assertContains('success', $output); } else { $this->assertContains('error', $output); $this->assertNotContains('success', $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; }
/** * 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; }
/** * 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 . "="; }