diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-10-05 15:05:47 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-10-05 15:05:47 +0400 |
commit | 5a1eab97f54b44f57356b4276b9c9df2a8eef51b (patch) | |
tree | 83864ece2806ccf6e6bb49abf3fd65de92c13ad8 /tests/PHPUnit/System/ArchiveWebTest.php | |
parent | 19bcd2d262343eae9d553378e4c66ce7e033b4d8 (diff) |
refs #5940 put tests in correct folders, better testsuite names, some tests still fail and I cannot figure out why
Diffstat (limited to 'tests/PHPUnit/System/ArchiveWebTest.php')
-rw-r--r-- | tests/PHPUnit/System/ArchiveWebTest.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/PHPUnit/System/ArchiveWebTest.php b/tests/PHPUnit/System/ArchiveWebTest.php new file mode 100644 index 0000000000..53f262df1a --- /dev/null +++ b/tests/PHPUnit/System/ArchiveWebTest.php @@ -0,0 +1,79 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Tests\System; + +use Piwik\Option; +use Piwik\Http; +use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Fixtures\ManySitesImportedLogs; +use Piwik\Tests\Fixture; +use Exception; + +/** + * Tests to call the archive.php script via web and check there is no error. + * + * @group Core + * @group ArchiveWebTest + */ +class ArchiveWebTest extends SystemTestCase +{ + public static $fixture = null; // initialized below class definition + + 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); + } + + private function compareArchivePhpOutputAgainstExpected($output) + { + $fileName = 'test_ArchiveCronTest_archive_php_cron_output.txt'; + list($pathProcessed, $pathExpected) = static::getProcessedAndExpectedDirs(); + + $expectedOutputFile = $pathExpected . $fileName; + + try { + $this->assertTrue(is_readable($expectedOutputFile)); + $this->assertEquals(file_get_contents($expectedOutputFile), $output); + } catch (Exception $ex) { + $this->comparisonFailures[] = $ex; + } + } +} + +ArchiveWebTest::$fixture = new ManySitesImportedLogs(); +ArchiveWebTest::$fixture->addSegments = true;
\ No newline at end of file |