diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php index 00195af7806..15ff184a150 100644 --- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php +++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php @@ -16,7 +16,7 @@ */ class Test_Piwik_Fixture_ManySitesImportedLogs extends Test_Piwik_BaseFixture { - public $dateTime = '2010-03-06 11:22:33'; + public $dateTime = '2012-08-09 11:22:33'; public $idSite = 1; public $idSite2 = 2; public $idGoal = 1; diff --git a/tests/PHPUnit/Integration/AnnotationsTest.php b/tests/PHPUnit/Integration/AnnotationsTest.php index 5d7b29ccb9e..1b0c6d4ce0c 100755 --- a/tests/PHPUnit/Integration/AnnotationsTest.php +++ b/tests/PHPUnit/Integration/AnnotationsTest.php @@ -14,7 +14,7 @@ class AnnotationsTest extends IntegrationTestCase { public static $fixture = null; - public function getOutputPrefix() + public static function getOutputPrefix() { return 'annotations'; } diff --git a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php index 9d19a52a05d..a81941dc89b 100755 --- a/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php +++ b/tests/PHPUnit/Integration/ApiGetReportMetadataTest.php @@ -34,7 +34,7 @@ public function tearDown() Proxy::getInstance()->setHideIgnoredFunctions(true); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'apiGetReportMetadata'; } diff --git a/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php b/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php index 6863c0775e1..44d2d5df98a 100755 --- a/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php +++ b/tests/PHPUnit/Integration/ApiGetReportMetadata_yearTest.php @@ -30,7 +30,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'apiGetReportMetadata_year'; } diff --git a/tests/PHPUnit/Integration/BlobReportLimitingTest.php b/tests/PHPUnit/Integration/BlobReportLimitingTest.php index 835822ed6aa..9577e29d06b 100755 --- a/tests/PHPUnit/Integration/BlobReportLimitingTest.php +++ b/tests/PHPUnit/Integration/BlobReportLimitingTest.php @@ -153,7 +153,7 @@ public function testApiWithRankingQueryDisabled() } } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'reportLimiting'; } diff --git a/tests/PHPUnit/Integration/CsvExportTest.php b/tests/PHPUnit/Integration/CsvExportTest.php index 737530cceda..7e84ababdb3 100755 --- a/tests/PHPUnit/Integration/CsvExportTest.php +++ b/tests/PHPUnit/Integration/CsvExportTest.php @@ -57,7 +57,7 @@ public function testApi($api, $params) $this->runApiTests($api, $params); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'csvExport'; } diff --git a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php index 0de25f5e4b9..3445857b8e1 100755 --- a/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php +++ b/tests/PHPUnit/Integration/EcommerceOrderWithItemsTest.php @@ -174,7 +174,7 @@ public function getApiForTesting() ), self::getApiForTestingScheduledReports($dateTime, 'week')); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'ecommerceOrderWithItems'; } diff --git a/tests/PHPUnit/Integration/FlattenReportsTest.php b/tests/PHPUnit/Integration/FlattenReportsTest.php index 19d9ed14144..1a115411954 100644 --- a/tests/PHPUnit/Integration/FlattenReportsTest.php +++ b/tests/PHPUnit/Integration/FlattenReportsTest.php @@ -112,7 +112,7 @@ public function getApiForTesting() return $return; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'FlattenReports'; } diff --git a/tests/PHPUnit/Integration/ImportLogsTest.php b/tests/PHPUnit/Integration/ImportLogsTest.php index cbb79e257d3..85cc9100f59 100755 --- a/tests/PHPUnit/Integration/ImportLogsTest.php +++ b/tests/PHPUnit/Integration/ImportLogsTest.php @@ -69,7 +69,7 @@ public function testDynamicResolverSitesCreated() $this->assertEquals(1, count($whateverDotCom)); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'ImportLogs'; } diff --git a/tests/PHPUnit/Integration/LabelFilterTest.php b/tests/PHPUnit/Integration/LabelFilterTest.php index 3a345c018cf..06171319a5f 100644 --- a/tests/PHPUnit/Integration/LabelFilterTest.php +++ b/tests/PHPUnit/Integration/LabelFilterTest.php @@ -114,7 +114,7 @@ public function getApiForTesting() return $return; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'LabelFilter'; } diff --git a/tests/PHPUnit/Integration/NoVisitTest.php b/tests/PHPUnit/Integration/NoVisitTest.php index 50cbe20c65a..7c69b9cd3ba 100755 --- a/tests/PHPUnit/Integration/NoVisitTest.php +++ b/tests/PHPUnit/Integration/NoVisitTest.php @@ -39,7 +39,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'noVisit'; } diff --git a/tests/PHPUnit/Integration/NonUnicodeTest.php b/tests/PHPUnit/Integration/NonUnicodeTest.php index 83628577ed1..fb51e6103ff 100755 --- a/tests/PHPUnit/Integration/NonUnicodeTest.php +++ b/tests/PHPUnit/Integration/NonUnicodeTest.php @@ -40,7 +40,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'NonUnicode'; } diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php index 5a96ed8aed3..1cc4ba93041 100755 --- a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php +++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRangeTest.php @@ -85,7 +85,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'oneVisitor_oneWebsite_severalDays_DateRange'; } diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php index a6c53489155..685cb731cbd 100755 --- a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php +++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php @@ -16,7 +16,7 @@ class Test_Piwik_Integration_OneVisitorOneWebsite_SeveralDaysDateRange_Archiving { public static $fixture = null; // initialized below test definition - public function getOutputPrefix() + public static function getOutputPrefix() { return 'oneVisitor_oneWebsite_severalDays_DateRange'; } diff --git a/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php b/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php index 6baa8041922..ebd5827b861 100755 --- a/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php +++ b/tests/PHPUnit/Integration/OneVisitorTwoVisits_withCookieSupportTest.php @@ -36,7 +36,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'OneVisitorTwoVisits_withCookieSupport'; } diff --git a/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php index 02156d7a54d..169eabe8b77 100644 --- a/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php +++ b/tests/PHPUnit/Integration/OneVisitor_LongUrlsTruncatedTest.php @@ -39,7 +39,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'OneVisitor_LongUrlsTruncated'; } diff --git a/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php index 966c85f2ef1..3054089880f 100755 --- a/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php +++ b/tests/PHPUnit/Integration/OneVisitor_NoKeywordSpecifiedTest.php @@ -37,7 +37,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'OneVisitor_NoKeywordSpecified'; } diff --git a/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php index 88d2c5bf766..2b9daa94325 100755 --- a/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php +++ b/tests/PHPUnit/Integration/PeriodIsRange_DateIsLastN_MetadataAndNormalAPITest.php @@ -93,7 +93,7 @@ public function getApiForTesting() return $result; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'periodIsRange_dateIsLastN_MetadataAndNormalAPI'; } diff --git a/tests/PHPUnit/Integration/RowEvolutionTest.php b/tests/PHPUnit/Integration/RowEvolutionTest.php index 90266e842d0..5dce031bd61 100755 --- a/tests/PHPUnit/Integration/RowEvolutionTest.php +++ b/tests/PHPUnit/Integration/RowEvolutionTest.php @@ -210,7 +210,7 @@ public function getApiForTesting() return $return; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'RowEvolution'; } diff --git a/tests/PHPUnit/Integration/SiteSearchTest.php b/tests/PHPUnit/Integration/SiteSearchTest.php index 545c794b382..e8c6ffebccd 100755 --- a/tests/PHPUnit/Integration/SiteSearchTest.php +++ b/tests/PHPUnit/Integration/SiteSearchTest.php @@ -81,7 +81,7 @@ public function getApiForTesting() return $result; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'SiteSearch'; } diff --git a/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php b/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php index 3616dfe3a90..2138e43771e 100755 --- a/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php +++ b/tests/PHPUnit/Integration/TrackCustomVariablesAndCampaigns_ForceUsingVisitIdNotHeuristicsTest.php @@ -34,7 +34,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'PiwikTracker_trackForceUsingVisitId_insteadOfHeuristics_alsoTestsCampaignTracking'; } diff --git a/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php b/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php index 828f0334ef4..d691640d6a9 100755 --- a/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php +++ b/tests/PHPUnit/Integration/TrackGoals_AllowMultipleConversionsPerVisitTest.php @@ -52,7 +52,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'trackGoals_allowMultipleConversionsPerVisit'; } diff --git a/tests/PHPUnit/Integration/TrackerWindowLookBack.php b/tests/PHPUnit/Integration/TrackerWindowLookBack.php index f95a45ecfe7..dfc72fc2be9 100644 --- a/tests/PHPUnit/Integration/TrackerWindowLookBack.php +++ b/tests/PHPUnit/Integration/TrackerWindowLookBack.php @@ -37,7 +37,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'TrackerWindowLookBack'; } diff --git a/tests/PHPUnit/Integration/TransitionsTest.php b/tests/PHPUnit/Integration/TransitionsTest.php index 318a6bc0ce5..0fc0472f232 100644 --- a/tests/PHPUnit/Integration/TransitionsTest.php +++ b/tests/PHPUnit/Integration/TransitionsTest.php @@ -71,7 +71,7 @@ public function getApiForTesting() return $return; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'Transitions'; } diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php index 5baf9b0abac..b4fc77aa568 100755 --- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php +++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDaysTest.php @@ -102,7 +102,7 @@ public function getApiForTesting() return array_merge($result, self::getApiForTestingScheduledReports($dateTime, 'month')); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'TwoVisitors_twoWebsites_differentDays'; } diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php index 89e28bf0b0d..112d0dd950d 100755 --- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php +++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ArchivingDisabledTest.php @@ -53,7 +53,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'TwoVisitors_twoWebsites_differentDays_ArchivingDisabled'; } diff --git a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php index 122d527fc06..f223a7b66ec 100755 --- a/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php +++ b/tests/PHPUnit/Integration/TwoVisitors_TwoWebsites_DifferentDays_ConversionsTest.php @@ -104,7 +104,7 @@ public function getApiForTesting() return $result; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'TwoVisitors_twoWebsites_differentDays_Conversions'; } diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php index f1be9716b34..932ef4ef8b9 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariablesTest.php @@ -49,7 +49,7 @@ public function testApi($api, $params) $this->runApiTests($api, $params); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'twoVisitsWithCustomVariables'; } diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php index 648711e9bb0..f7ad0d004ae 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentContainsTest.php @@ -13,7 +13,7 @@ class Test_Piwik_Integration_TwoVisitsWithCustomVariables_SegmentContains extend { public static $fixture = null; // initialized below class definition - public function getOutputPrefix() + public static function getOutputPrefix() { return 'twoVisitsWithCustomVariables'; } diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php index f217be8d0ba..620140dde73 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchALL_NoGoalDataTest.php @@ -38,7 +38,7 @@ public function getApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'twoVisitsWithCustomVariables_segmentMatchALL_noGoalData'; } diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php index 9a57a57c559..38e4246bde1 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchNONETest.php @@ -70,7 +70,7 @@ public function getSegmentToTest() return $segment; } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'twoVisitsWithCustomVariables_segmentMatchNONE'; } diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php index 4e6b18cbfc0..26a0c876058 100755 --- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php +++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php @@ -96,7 +96,7 @@ public function testCheck() } } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'twoVisitsWithCustomVariables_segmentMatchVisitorType'; } diff --git a/tests/PHPUnit/Integration/UrlNormalizationTest.php b/tests/PHPUnit/Integration/UrlNormalizationTest.php index 7e8d4fa7a16..64046122cd5 100644 --- a/tests/PHPUnit/Integration/UrlNormalizationTest.php +++ b/tests/PHPUnit/Integration/UrlNormalizationTest.php @@ -104,7 +104,7 @@ public function testCheckPostConditions() $this->assertEquals($expected, $urls, "normalization went wrong"); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'UrlNormalization'; } diff --git a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php index ac6f7e5c017..7df95e39195 100644 --- a/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php +++ b/tests/PHPUnit/Integration/VisitsInPast_InvalidateOldReportsTest.php @@ -115,7 +115,7 @@ public function getAnotherApiForTesting() ); } - public function getOutputPrefix() + public static function getOutputPrefix() { return 'VisitsInPast_InvalidateOldReports'; } diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index ed567452ae9..b3d7cbeb1e6 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -941,9 +941,9 @@ public function getApiForTesting() /** * Gets the string prefix used in the name of the expected/processed output files. */ - public function getOutputPrefix() + public static function getOutputPrefix() { - return str_replace('Test_Piwik_Integration_', '', get_class($this)); + return str_replace('Test_Piwik_Integration_', '', get_called_class()); } protected function _setCallableApi($api) @@ -974,7 +974,7 @@ protected function _setCallableApi($api) */ protected function runApiTests($api, $params) { - $testName = 'test_' . $this->getOutputPrefix(); + $testName = 'test_' . static::getOutputPrefix(); $this->missingExpectedFiles = array(); $this->comparisonFailures = array(); diff --git a/tests/PHPUnit/UI/UIIntegrationTest.php b/tests/PHPUnit/UI/UIIntegrationTest.php index b1b95e0df67..efcc88ce577 100644 --- a/tests/PHPUnit/UI/UIIntegrationTest.php +++ b/tests/PHPUnit/UI/UIIntegrationTest.php @@ -5,10 +5,6 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -use Piwik\Piwik; -use Piwik\Access; -use Piwik\AssetManager; -use Piwik\Plugins\VisitsSummary\API; /** * Tests UI code by grabbing screenshots of webpages and comparing with expected files. @@ -19,93 +15,9 @@ * - allow instrumentation javascript to be injected before screenshot is taken (so we can, say, * take a screenshot of column documentation) */ -class Test_Piwik_Integration_UIIntegrationTest extends IntegrationTestCase +class Test_Piwik_Integration_UIIntegrationTest extends UITest { - const IMAGE_TYPE = 'png'; - const CAPTURE_PROGRAM = 'phantomjs'; - - public static $fixture = null; // initialized below class definition - - public static function createAccessInstance() - { - Access::setSingletonInstance($access = new Test_Access_OverrideLogin()); - Piwik_PostEvent('FrontController.initAuthenticationObject'); - } - - public static function setUpBeforeClass() - { - if (!self::isXvfbAvailable()) { - self::markTestSkipped("xvfb is not available, skipping UI integration tests. (install with 'sudo apt-get install xvfb')"); - } else if (self::CAPTURE_PROGRAM == 'slimerjs' - && !self::isSlimerJsAvailable() - ) { - self::markTestSkipped("slimerjs is not available, skipping UI integration tests. " - . "(install by downloading http://slimerjs.org/download.html)"); - } else if (self::CAPTURE_PROGRAM == 'phantomjs' - && !self::isPhantomJsAvailable() - ) { - self::markTestSkipped("phantomjs is not available, skipping UI integration tests. " - . "(install by downloading http://phantomjs.org/download.html)"); - } - - parent::setUpBeforeClass(); - - AssetManager::removeMergedAssets(); - - // launch archiving so tests don't run out of time - API::getInstance()->get(self::$fixture->idSite, 'year', '2012-08-09'); - - // make sure processed & expected dirs exist - list($processedDir, $expectedDir) = self::getProcessedAndExpectedDirs(); - if (!is_dir($processedDir)) { - mkdir($processedDir); - } - if (!is_dir($expectedDir)) { - mkdir($expectedDir); - } - - // run slimerjs/phantomjs w/ all urls so we only invoke it once - $urls = array(); - foreach (self::getUrlsForTesting() as $testInfo) { - list($name, $urlQuery) = $testInfo; - - list($processedScreenshotPath, $expectedScreenshotPath) = self::getProcessedAndExpectedScreenshotPaths($name); - $urls[] = array($processedScreenshotPath, self::getProxyUrl() . $urlQuery); - } - - echo "Generating screenshots...\n"; - self::runCaptureProgram($urls); - } - - public static function tearDownAfterClass() - { - if (file_exists("C:\\nppdf32Log\\debuglog.txt")) { // remove slimerjs oddity - unlink("C:\\nppdf32Log\\debuglog.txt"); - } - - if (!Zend_Registry::get('db')) { - Piwik::createDatabaseObject(); - } - - parent::tearDownAfterClass(); - } - - public function setUp() - { - parent::setUp(); - - if (!Zend_Registry::get('db')) { - Piwik::createDatabaseObject(); - } - } - - public function tearDown() - { - parent::tearDown(); - - \Zend_Registry::get('db')->closeConnection(); - \Zend_Registry::set('db', false); - } + public static $fixture = null; // initialized below class definition public static function getUrlsForTesting() { @@ -219,84 +131,8 @@ public static function getUrlsForTesting() */ public function testUIUrl($name, $urlQuery) { - list($processedScreenshotPath, $expectedScreenshotPath) = self::getProcessedAndExpectedScreenshotPaths($name); - // compare processed w/ expected - $this->compareScreenshot($name, $expectedScreenshotPath, $processedScreenshotPath, $urlQuery); - } - - private static function runCaptureProgram($urlInfo) - { - file_put_contents(PIWIK_INCLUDE_PATH . '/tmp/urls.txt', json_encode($urlInfo)); - $cmd = self::CAPTURE_PROGRAM . " \"" . PIWIK_INCLUDE_PATH . "/tests/resources/screenshot-capture/capture.js\" 2>&1"; - $cmd = 'xvfb-run --server-args="-screen 0, 1024x768x24" ' . $cmd; - - exec($cmd, $output, $result); - $output = implode("\n", $output); - if ($result !== 0 - || strpos($output, "ERROR") !== false - ) { - echo self::CAPTURE_PROGRAM . " failed: " . $output . "\n\ncommand used: $cmd\n"; - throw new Exception("phantomjs failed"); - } - return $output; - } - - private function compareScreenshot($name, $expectedPath, $processedPath, $urlQuery) - { - $processed = file_get_contents($processedPath); - - if (!file_exists($expectedPath)) { - $this->markTestIncomplete("expected screenshot for processed '$processedPath' is missing"); - } - - $expected = file_get_contents($expectedPath); - if ($expected != $processed) { - echo "\nFail: '$processedPath' for '$urlQuery'\n"; - } - $this->assertTrue($expected == $processed, "screenshot compare failed for '$processedPath'"); - } - - private static function isSlimerJsAvailable() - { - return self::isProgramAvailable('slimerjs'); - } - - private static function isPhantomJsAvailable() - { - return self::isProgramAvailable('phantomjs'); - } - - private static function isXvfbAvailable() - { - return self::isProgramAvailable('xvfb-run'); - } - - private static function isProgramAvailable($name) - { - exec($name . ' --help 2>&1', $output, $result); - return $result === 0 || $result === 1; - } - - private static function getProcessedAndExpectedScreenshotPaths($name) - { - list($processedDir, $expectedDir) = self::getProcessedAndExpectedDirs(); - - $processedScreenshotPath = $processedDir . "$name." . self::IMAGE_TYPE; - $expectedScreenshotPath = $expectedDir . "$name." . self::IMAGE_TYPE; - - return array($processedScreenshotPath, $expectedScreenshotPath); - } - - protected static function getProcessedAndExpectedDirs() - { - $path = self::getPathToTestDirectory() . '/../UI'; - return array($path . '/processed-ui-screenshots/', $path . '/expected-ui-screenshots/'); - } - - public static function getProxyUrl() - { - return Test_Piwik_BaseFixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php'; + $this->compareScreenshot($name, $urlQuery); } } diff --git a/tests/PHPUnit/UITest.php b/tests/PHPUnit/UITest.php new file mode 100644 index 00000000000..63f7dd832f2 --- /dev/null +++ b/tests/PHPUnit/UITest.php @@ -0,0 +1,178 @@ +dateTime)->toString(); + API::getInstance()->get(static::$fixture->idSite, 'year', $date); + + // make sure processed & expected dirs exist + list($processedDir, $expectedDir) = self::getProcessedAndExpectedDirs(); + if (!is_dir($processedDir)) { + mkdir($processedDir); + } + if (!is_dir($expectedDir)) { + mkdir($expectedDir); + } + + // run slimerjs/phantomjs w/ all urls so we only invoke it once + $urls = array(); + foreach (static::getUrlsForTesting() as $testInfo) { + list($name, $urlQuery) = $testInfo; + + list($processedScreenshotPath, $expectedScreenshotPath) = self::getProcessedAndExpectedScreenshotPaths($name); + $urls[] = array($processedScreenshotPath, self::getProxyUrl() . $urlQuery); + } + + echo "Generating screenshots...\n"; + self::runCaptureProgram($urls); + } + + public static function tearDownAfterClass() + { + if (file_exists("C:\\nppdf32Log\\debuglog.txt")) { // remove slimerjs oddity + unlink("C:\\nppdf32Log\\debuglog.txt"); + } + + if (!Zend_Registry::get('db')) { + Piwik::createDatabaseObject(); + } + + parent::tearDownAfterClass(); + } + + public function setUp() + { + parent::setUp(); + + if (!Zend_Registry::get('db')) { + Piwik::createDatabaseObject(); + } + } + + public function tearDown() + { + parent::tearDown(); + + \Zend_Registry::get('db')->closeConnection(); + \Zend_Registry::set('db', false); + } + + private static function runCaptureProgram($urlInfo) + { + file_put_contents(PIWIK_INCLUDE_PATH . '/tmp/urls.txt', json_encode($urlInfo)); + $cmd = self::CAPTURE_PROGRAM . " \"" . PIWIK_INCLUDE_PATH . "/tests/resources/screenshot-capture/capture.js\" 2>&1"; + $cmd = 'xvfb-run --server-args="-screen 0, 1024x768x24" ' . $cmd; + + exec($cmd, $output, $result); + $output = implode("\n", $output); + if ($result !== 0 + || strpos($output, "ERROR") !== false + ) { + echo self::CAPTURE_PROGRAM . " failed: " . $output . "\n\ncommand used: $cmd\n"; + throw new Exception("phantomjs failed"); + } + return $output; + } + + protected function compareScreenshot($name, $urlQuery) + { + list($expectedPath, $processedPath) = self::getProcessedAndExpectedScreenshotPaths($name); + + $processed = file_get_contents($processedPath); + + if (!file_exists($expectedPath)) { + $this->markTestIncomplete("expected screenshot for processed '$processedPath' is missing"); + } + + $expected = file_get_contents($expectedPath); + if ($expected != $processed) { + echo "\nFail: '$processedPath' for '$urlQuery'\n"; + } + $this->assertTrue($expected == $processed, "screenshot compare failed for '$processedPath'"); + } + + private static function isSlimerJsAvailable() + { + return self::isProgramAvailable('slimerjs'); + } + + private static function isPhantomJsAvailable() + { + return self::isProgramAvailable('phantomjs'); + } + + private static function isXvfbAvailable() + { + return self::isProgramAvailable('xvfb-run'); + } + + private static function isProgramAvailable($name) + { + exec($name . ' --help 2>&1', $output, $result); + return $result === 0 || $result === 1; + } + + private static function getProcessedAndExpectedScreenshotPaths($name) + { + list($processedDir, $expectedDir) = self::getProcessedAndExpectedDirs(); + + $outputPrefix = static::getOutputPrefix(); + + $processedScreenshotPath = $processedDir . $outputPrefix . '_' . "$name." . self::IMAGE_TYPE; + $expectedScreenshotPath = $expectedDir . $outputPrefix . '_' . "$name." . self::IMAGE_TYPE; + + return array($processedScreenshotPath, $expectedScreenshotPath); + } + + protected static function getProcessedAndExpectedDirs() + { + $path = self::getPathToTestDirectory() . '/../UI'; + return array($path . '/processed-ui-screenshots/', $path . '/expected-ui-screenshots/'); + } + + public static function getProxyUrl() + { + return Test_Piwik_BaseFixture::getRootUrl() . 'tests/PHPUnit/proxy/index.php'; + } +} \ No newline at end of file diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index de5a9d532fe..1b11358c305 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -61,6 +61,7 @@ require_once PIWIK_INCLUDE_PATH . '/libs/spyc.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/DatabaseTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php'; +require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/UITest.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockPiwikOption.php'; require_once PIWIK_INCLUDE_PATH . '/vendor/autoload.php'; diff --git a/tests/resources/screenshot-capture/capture.js b/tests/resources/screenshot-capture/capture.js index 34ac2f80681..d866803f70c 100644 --- a/tests/resources/screenshot-capture/capture.js +++ b/tests/resources/screenshot-capture/capture.js @@ -8,11 +8,9 @@ var PageRenderer = function() { this.urlIndex = 0; this.urls = JSON.parse(readFileSync('../../tmp/urls.txt')); - this.webpage = require('webpage').create(); this.outputPath = ''; this.url = ''; - this._setupWebpageEvents(); this._setScriptTimeout(); }; @@ -32,38 +30,41 @@ PageRenderer.prototype = { console.log("SAVING " + this.url + " at " + this._getElapsedExecutionTime()); + if (this.webpage) { + this.webpage.close(); + } + + this.webpage = require('webpage').create(); + this._setupWebpageEvents(); + this.webpage.viewportSize = {width:1350, height:768}; - this.webpage.open(this.url); - this._setPageTimeouts(); + var self = this; + this.webpage.open(this.url, function () { + self._setPageTimeouts(); + }); }, _setPageTimeouts: function () { var url = this.url, self = this; - this.webpage.onLoadFinished = function () { - // check that we're still on the same url - if (url != self.url) { - return; - } - // in case there are no ajax requests, try triggering after a sec - setTimeout(function () { - if (url == self.url) { - self.webpage.evaluate(function () { - window.piwik.ajaxRequestFinished(); - }); - } - }, 1000) - - // only allowed at most one minute to load - setTimeout(function () { - if (url == self.url) { - self.webpage.evaluate(function () { - window.piwik._triggerRenderInsane(); - }); - } - }, 1000 * 60); - }; + // in case there are no ajax requests, try triggering after a sec + setTimeout(function () { + if (url == self.url) { + self.webpage.evaluate(function () { + window.piwik.ajaxRequestFinished(); + }); + } + }, 1000) + + // only allowed at most one minute to load + setTimeout(function () { + if (url == self.url) { + self.webpage.evaluate(function () { + window.piwik._triggerRenderInsane(); + }); + } + }, 1000 * 60); }, _setupWebpageEvents: function () {