diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI index 673d21c6a750d8280f4e9ab9d203072dd8d844d2..310d1dfc5a5b9bda331e49db93488b70a95c8b08 160000 --- a/tests/PHPUnit/UI +++ b/tests/PHPUnit/UI @@ -1 +1 @@ -Subproject commit 673d21c6a750d8280f4e9ab9d203072dd8d844d2 +Subproject commit 310d1dfc5a5b9bda331e49db93488b70a95c8b08 diff --git a/tests/PHPUnit/UITest.php b/tests/PHPUnit/UITest.php index 26988c5a43456392d89d7d49e013dbdb03f4edde..30bfac19dd2f3f88407113390965e17e2f490972 100644 --- a/tests/PHPUnit/UITest.php +++ b/tests/PHPUnit/UITest.php @@ -64,6 +64,7 @@ abstract class UITest extends IntegrationTestCase reset($urlsToTest); for ($i = 0; $i < count($urlsToTest); $i += self::SCREENSHOT_GROUP_SIZE) { $urls = array(); + echo "Generating screenshots..."; for ($j = $i; $j != $i + self::SCREENSHOT_GROUP_SIZE && $j < count($urlsToTest); ++$j) { $currentTest = current($urlsToTest); @@ -74,13 +75,29 @@ abstract class UITest extends IntegrationTestCase list($name, $urlQuery, $jsToTest) = $currentTest; } + $testUrl = self::getProxyUrl() . $urlQuery; + + // Screenshot Zeitgeist list($processedScreenshotPath, $expectedScreenshotPath) = self::getProcessedAndExpectedScreenshotPaths($name); - $urls[] = array($processedScreenshotPath, self::getProxyUrl() . $urlQuery, $jsToTest); + $urls[] = array($processedScreenshotPath, $testUrl, $jsToTest); + + // Screenshot Morpheus + list($processedScreenshotPath, $expectedScreenshotPath) = self::getProcessedAndExpectedScreenshotPaths($name, "Morpheus/"); + $enableMorpheus = "&morpheus=1"; + // Add the parameter to the query string, not the hash + if(($hash = strpos($testUrl, '#')) !== false) { + $testUrl = substr($testUrl, 0, $hash) . $enableMorpheus . substr($testUrl, $hash); + } else { + $testUrl .= $enableMorpheus; + } + + $urls[] = array($processedScreenshotPath, $testUrl, $jsToTest); next($urlsToTest); + echo "."; } - - echo "Generating screenshots...\n"; + echo "\n"; + self::runCaptureProgram($urls); } @@ -164,35 +181,9 @@ abstract class UITest extends IntegrationTestCase { list($processedPath, $expectedPath) = self::getProcessedAndExpectedScreenshotPaths($name); - if (!file_exists($processedPath)) { - $this->fail("failed to generate screenshot for '$name'."); - return; - } - - $processed = file_get_contents($processedPath); - - if (!file_exists($expectedPath)) { - $this->fail("expected screenshot for '$name' test is missing. -Generated screenshot: $processedPath"); - return; - } - - $expected = file_get_contents($expectedPath); - if ($expected != $processed) { - self::$failureScreenshotNames[] = $name; - - $diffPath = self::getScreenshotDiffPath($name); - - echo "\nFail: generated screenshot does not match expected for '$name'. -Url to reproduce: $urlQuery -Generated screenshot: $processedPath -Expected screenshot: $expectedPath -Screenshot diff: $diffPath\n"; + $this->compareScreenshotAgainstExpected($name, $urlQuery, $processedPath, $expectedPath); - $this->saveImageDiff($expectedPath, $processedPath, $diffPath); - } - $this->assertTrue($expected == $processed, "screenshot compare failed for '$processedPath'"); } private function saveImageDiff($expectedPath, $processedPath, $diffPath) @@ -228,14 +219,14 @@ Screenshot diff: $diffPath\n"; return $result === 0 || $result === 1; } - private static function getProcessedAndExpectedScreenshotPaths($name) + private static function getProcessedAndExpectedScreenshotPaths($name, $pathSuffix = '') { list($processedDir, $expectedDir) = self::getProcessedAndExpectedDirs(); $outputPrefix = static::getOutputPrefix(); - $processedScreenshotPath = $processedDir . $outputPrefix . '_' . "$name." . self::IMAGE_TYPE; - $expectedScreenshotPath = $expectedDir . $outputPrefix . '_' . "$name." . self::IMAGE_TYPE; + $processedScreenshotPath = $processedDir . $pathSuffix . $outputPrefix . '_' . "$name." . self::IMAGE_TYPE; + $expectedScreenshotPath = $expectedDir . $pathSuffix . $outputPrefix . '_' . "$name." . self::IMAGE_TYPE; return array($processedScreenshotPath, $expectedScreenshotPath); } @@ -364,4 +355,43 @@ If processed screenshots are correct, you can copy the generated screenshots to file_put_contents($diffDir . '/diffviewer.html', $diffViewerHtml); } + + /** + * @param $name + * @param $urlQuery + * @param $processedPath + * @param $expectedPath + */ + protected function compareScreenshotAgainstExpected($name, $urlQuery, $processedPath, $expectedPath) + { + if (!file_exists($processedPath)) { + $this->fail("failed to generate screenshot for '$name'."); + return; + } + + $processed = file_get_contents($processedPath); + + if (!file_exists($expectedPath)) { + $this->fail("expected screenshot for '$name' test is missing. +Generated screenshot: $processedPath"); + return; + } + + $expected = file_get_contents($expectedPath); + if ($expected != $processed) { + self::$failureScreenshotNames[] = $name; + + $diffPath = self::getScreenshotDiffPath($name); + + echo "\nFail: generated screenshot does not match expected for '$name'. +Url to reproduce: $urlQuery +Generated screenshot: $processedPath +Expected screenshot: $expectedPath +Screenshot diff: $diffPath\n"; + + $this->saveImageDiff($expectedPath, $processedPath, $diffPath); + } + + $this->assertTrue($expected == $processed, "screenshot compare failed for '$processedPath'"); + } } \ No newline at end of file diff --git a/tests/PHPUnit/proxy/index.php b/tests/PHPUnit/proxy/index.php index 8ce7649e32e06b73b52a0c0bfb7377c5c4770d44..70e99b6fe601e7f423e60849c102a1e01b02c1ba 100644 --- a/tests/PHPUnit/proxy/index.php +++ b/tests/PHPUnit/proxy/index.php @@ -15,7 +15,7 @@ ob_start(); Piwik_TestingEnvironment::addHooks(); \Piwik\Tracker::setTestEnvironment(); -Cache::deleteTrackerCache(); + \Piwik\Profiler::setupProfilerXHProf(); @@ -25,13 +25,38 @@ define('PIWIK_ENABLE_DISPATCH', false); include PIWIK_INCLUDE_PATH . '/index.php'; $controller = \Piwik\FrontController::getInstance(); - +/** + * @return bool + */ +function loadAllPluginsButOneTheme() +{ // Load all plugins that are found so UI tests are really testing real world use case -\Piwik\Config::getInstance()->Plugins['Plugins'] = \Piwik\Plugin\Manager::getInstance()->getAllPluginsNames(); + $pluginsToEnable = \Piwik\Plugin\Manager::getInstance()->getAllPluginsNames(); + + $themesNotToEnable = array('ExampleTheme', 'LeftMenu', 'PleineLune'); + + $enableMorpheus = empty($_REQUEST['morpheus']); + if (!$enableMorpheus) { + $themesNotToEnable[] = 'Morpheus'; + } + + $pluginsToEnable = array_diff($pluginsToEnable, $themesNotToEnable); + \Piwik\Config::getInstance()->Plugins['Plugins'] = $pluginsToEnable; + return $enableMorpheus; +} + +$enableMorpheus = loadAllPluginsButOneTheme(); $controller->init(); +\Piwik\Filesystem::deleteAllCacheOnUpdate(); + $response = $controller->dispatch(); +if($enableMorpheus) { + $replace = "action=getCss"; + $response = str_replace($replace, $replace . "&morpheus=1", $response); +} + if (!is_null($response)) { echo $response; }