Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Napoli <matthieu@mnapoli.fr>2015-08-12 15:08:46 +0300
committerMatthieu Napoli <matthieu@mnapoli.fr>2015-08-12 15:08:46 +0300
commit61da80ed08e485e11d6e6a420c10162ed5372de4 (patch)
treedc7991ef33cd8ed6dd462646efcaa2c82a762b27 /plugins/TestRunner
parent85e2e5320d1f180c97f45171ab9727ac3bf5e01d (diff)
Update the tests:sync-screenshots command to work with the new UI tests viewer
Diffstat (limited to 'plugins/TestRunner')
-rw-r--r--plugins/TestRunner/Commands/SyncScreenshots.php207
1 files changed, 72 insertions, 135 deletions
diff --git a/plugins/TestRunner/Commands/SyncScreenshots.php b/plugins/TestRunner/Commands/SyncScreenshots.php
index 299bc7e726..587a18a23d 100644
--- a/plugins/TestRunner/Commands/SyncScreenshots.php
+++ b/plugins/TestRunner/Commands/SyncScreenshots.php
@@ -51,7 +51,7 @@ class SyncScreenshots extends ConsoleCommand
$this->addArgument('buildnumber', InputArgument::REQUIRED, 'Travis build number you want to sync.');
$this->addArgument('screenshotsRegex', InputArgument::OPTIONAL,
'A regex to use when selecting screenshots to copy. If not supplied all screenshots are copied.', '.*');
- $this->addOption('plugin', 'p', InputOption::VALUE_OPTIONAL, 'Plugin name you want to sync screenshots for.');
+ $this->addOption('repository', 'r', InputOption::VALUE_OPTIONAL, 'Repository name you want to sync screenshots for.', 'piwik/piwik');
$this->addOption('http-user', '', InputOption::VALUE_OPTIONAL, 'the HTTP AUTH username (for premium plugins where artifacts are protected)');
$this->addOption('http-password', '', InputOption::VALUE_OPTIONAL, 'the HTTP AUTH password (for premium plugins where artifacts are protected)');
}
@@ -59,60 +59,89 @@ class SyncScreenshots extends ConsoleCommand
protected function execute(InputInterface $input, OutputInterface $output)
{
$buildNumber = $input->getArgument('buildnumber');
- if (empty($buildNumber)) {
- throw new \InvalidArgumentException('Missing build number.');
- }
-
$screenshotsRegex = $input->getArgument('screenshotsRegex');
-
- $plugin = $input->getOption('plugin');
-
+ $repository = $input->getOption('repository');
$httpUser = $input->getOption('http-user');
$httpPassword = $input->getOption('http-password');
- $urlBase = $this->getUrlBase($plugin, $buildNumber);
- $diffviewer = $this->getDiffviewerContent($output, $urlBase, $httpUser, $httpPassword);
+ $screenshots = $this->getScreenshotList($repository, $buildNumber, $httpUser, $httpPassword);
+
+ $this->logger->notice('Downloading {number} screenshots', array('number' => count($screenshots)));
+ foreach ($screenshots as $name => $url) {
+ if (preg_match('/' . $screenshotsRegex . '/', $name)) {
+ $this->logger->info('Downloading {name}', array('name' => $name));
+ $this->downloadScreenshot($url, $repository, $name, $httpUser, $httpPassword);
+ }
+ }
- $dom = new \DOMDocument();
- $dom->loadHTML($diffviewer);
- foreach ($dom->getElementsByTagName("tr") as $row) {
- $columns = $row->getElementsByTagName("td");
+ $this->displayGitInstructions($output, $repository);
+ }
- $processedColumn = $columns->item(3);
+ private function getScreenshotList($repository, $buildNumber, $httpUser = null, $httpPassword = null)
+ {
+ $url = sprintf('http://builds-artifacts.piwik.org/api/%s/%s', $repository, $buildNumber);
- $file = null;
- if ($processedColumn
- && preg_match("/href=\".*\/(.*)\"/", $dom->saveXml($processedColumn), $matches)
- ) {
- $file = $matches[1];
- }
+ $this->logger->debug('Fetching {url}', array('url' => $url));
- if ($file !== null
- && preg_match("/" . $screenshotsRegex . "/", $file)
- ) {
- $this->downloadProcessedScreenshot($output, $urlBase, $file, $plugin, $httpUser, $httpPassword);
- }
+ $response = Http::sendHttpRequest(
+ $url,
+ $timeout = 60,
+ $userAgent = null,
+ $destinationPath = null,
+ $followDepth = 0,
+ $acceptLanguage = false,
+ $byteRange = false,
+ $getExtendedInfo = true,
+ $httpMethod = 'GET',
+ $httpUser,
+ $httpPassword
+ );
+ $httpStatus = $response['status'];
+ if ($httpStatus == '200') {
+ return json_decode($response['data'], true);
+ }
+ if ($httpStatus == '401') {
+ throw new \Exception('HTTP 401 - Auth username and password are invalid');
}
+ $this->logger->debug('Response content: {content}', array('content' => $response['data']));
+ throw new \Exception("Failed downloading diffviewer from $url - Got HTTP status $httpStatus");
+ }
+
+ private function downloadScreenshot($url, $repository, $screenshot, $httpUser, $httpPassword)
+ {
+ $downloadTo = $this->getDownloadToPath($repository) . $screenshot . '.png';
+ $url = 'http://builds-artifacts.piwik.org' . $url;
- $this->displayGitInstructions($output, $plugin);
+ $this->logger->debug("Downloading {url} to {destination}", array('url' => $url, 'destination' => $downloadTo));
+ Http::sendHttpRequest(
+ $url,
+ $timeout = 60,
+ $userAgent = null,
+ $downloadTo,
+ $followDepth = 0,
+ $acceptLanguage = false,
+ $byteRange = false,
+ $getExtendedInfo = true,
+ $httpMethod = 'GET',
+ $httpUser,
+ $httpPassword
+ );
}
- private function displayGitInstructions(OutputInterface $output, $plugin)
+ private function displayGitInstructions(OutputInterface $output, $repository)
{
- $output->writeln('');
- $output->writeln("If all downloaded screenshots are valid you may push them with these commands:");
- $downloadToPath = $this->getDownloadToPath($plugin);
+ $output->writeln('<comment>If all downloaded screenshots are valid you may push them with these commands:</comment>');
+ $downloadToPath = $this->getDownloadToPath($repository);
$commands = "
cd $downloadToPath
git pull
git add .
git status
-sleep 5
-git commit -m 'UI tests: ...' # Write a good commit message, eg. 'Fixed UI test failure caused by change introduced in <core or plugin commit> which caused failure by <explanation of failure>'
+git commit -m 'UI tests: ...' # Write a good commit message, eg. 'Fixed UI test failure caused by change introduced in X which caused failure by Y'
git push";
- if(empty($plugin)) {
+ if ($repository === 'piwik/piwik') {
$commands .= "
cd ..
git pull
@@ -125,21 +154,16 @@ cd ../../";
$commands .= "
cd ../../../../../";
}
+
$output->writeln($commands);
}
- private function getUrlBase($plugin, $buildNumber)
+ private function getDownloadToPath($repository)
{
- if ($plugin) {
- return sprintf('http://builds-artifacts.piwik.org/ui-tests.master.%s/%s', $plugin, $buildNumber);
- }
- return sprintf('http://builds-artifacts.piwik.org/ui-tests.master/%s', $buildNumber);
- }
+ $plugin = $this->getPluginName($repository);
- private function getDownloadToPath($plugin)
- {
if (empty($plugin)) {
- return PIWIK_DOCUMENT_ROOT . "/tests/UI/expected-ui-screenshots/";
+ return PIWIK_DOCUMENT_ROOT . '/tests/UI/expected-ui-screenshots/';
}
$downloadTo = PIWIK_DOCUMENT_ROOT . "/plugins/$plugin/tests/UI/expected-ui-screenshots/";
@@ -155,100 +179,13 @@ cd ../../../../../";
throw new \Exception("Download to path could not be found: $downloadTo");
}
- private function getDiffviewerContent(OutputInterface $output, &$urlBase, $httpUser = false, $httpPassword = false)
+ private function getPluginName($repository)
{
- $url = $this->getDiffviewerUrl($urlBase);
-
- try {
- $diffViewer = $this->downloadDiffviewer($output, $url);
- } catch (\Exception $e) {
- $this->logger->debug('Not found: {url}', array('url' => $url));
-
- // Maybe this is a Premium Piwik PRO plugin...
- $diffViewer = $this->getDiffviewContentForPrivatePlugin($output, $urlBase, $httpUser, $httpPassword);
- }
+ list($org, $repository) = explode('/', $repository, 2);
- if (empty($diffViewer)) {
- throw new \Exception("Screenshot tests artifacts were not found for this build.");
+ if (strpos($repository, 'plugin-') === 0) {
+ return substr($repository, strlen('plugin-'));
}
- return $diffViewer;
+ return null;
}
-
- private function getDiffviewContentForPrivatePlugin(OutputInterface $output, &$urlBase, $httpUser, $httpPassword)
- {
- if (empty($httpUser) || empty($httpPassword)) {
- $output->writeln("<info>--http-user and --http-password was not specified, skip download of private plugins screenshots.</info>");
- return;
- }
-
- // Attempt to download from protected/ artifacts...
- $urlBase = str_replace("builds-artifacts.piwik.org/", "builds-artifacts.piwik.org/protected/", $urlBase);
- $diffviewerUrl = $this->getDiffviewerUrl($urlBase);
-
- return $this->downloadDiffviewer($output, $diffviewerUrl, $httpUser, $httpPassword);
- }
-
- /**
- * @return string
- */
- private function getDiffviewerUrl($urlBase)
- {
- return $urlBase . "/screenshot-diffs/diffviewer.html";
- }
-
- private function downloadDiffviewer(OutputInterface $output, $urlDiffviewer, $httpUsername = false, $httpPassword = false)
- {
- $this->logger->debug('Downloading {url}', array('url' => $urlDiffviewer));
-
- $responseExtended = Http::sendHttpRequest(
- $urlDiffviewer,
- $timeout = 60,
- $userAgent = null,
- $destinationPath = null,
- $followDepth = 0,
- $acceptLanguage = false,
- $byteRange = false,
- $getExtendedInfo = true,
- $httpMethod = 'GET',
- $httpUsername,
- $httpPassword
- );
- $httpStatus = $responseExtended['status'];
- if ($httpStatus == '200') {
- $output->writeln("Found diffviewer at: " . $urlDiffviewer);
- $diffviewer = str_replace('&', '&amp;', $responseExtended['data']);
- return $diffviewer;
- }
-
- if($httpStatus == '401') {
- $output->writeln("<error>HTTP AUTH username and password are not valid.</error>");
- }
- throw new \Exception ("Failed downloading diffviewer from $urlDiffviewer - Got HTTP status " . $httpStatus);
- }
-
-
- private function downloadProcessedScreenshot(OutputInterface $output, $urlBase, $file, $plugin, $httpUser, $httpPassword)
- {
- $downloadTo = $this->getDownloadToPath($plugin) . $file;
-
- $output->write("<info>Downloading $file to $downloadTo...</info>\n");
- $screenshotUrl = $urlBase . "/processed-ui-screenshots/$file";
-
- $this->logger->debug('Downloading {url}', array('url' => $screenshotUrl));
-
- Http::sendHttpRequest(
- $screenshotUrl,
- $timeout = 60,
- $userAgent = null,
- $downloadTo,
- $followDepth = 0,
- $acceptLanguage = false,
- $byteRange = false,
- $getExtendedInfo = true,
- $httpMethod = 'GET',
- $httpUser,
- $httpPassword
- );
- }
-
}