Skip to content

Commit

Permalink
Refs #4739, modify SyncUITestScreenshots command to work with new scr…
Browse files Browse the repository at this point in the history
…eenshot testing code and display location hint in diffviewer output if expected file is stored within plugin and not the UI tests repo.
  • Loading branch information
diosmosis committed Mar 4, 2014
1 parent ba6a60a commit f073d10
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 13 deletions.
57 changes: 46 additions & 11 deletions plugins/CoreConsole/Commands/SyncUITestScreenshots.php
Expand Up @@ -9,6 +9,7 @@

namespace Piwik\Plugins\CoreConsole\Commands;

use Piwik\Http;
use Piwik\Plugin\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -21,26 +22,60 @@ class SyncUITestScreenshots extends ConsoleCommand
protected function configure()
{
$this->setName('development:sync-ui-test-screenshots');
$this->setDescription('This command is intended for Piwik core developers. It copies all processed screenshot tests on Travis to the expected screenshot directory.');
$this->addArgument('buildnumber', InputArgument::REQUIRED, 'Travis build number you want to sync');
$this->setDescription('This command is intended for Piwik core developers. It copies all processed screenshot '
. 'tests on Travis to the expected screenshot directory.');
$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.', '.*');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$buildnumber = $input->getArgument('buildnumber');
$buildNumber = $input->getArgument('buildnumber');
$screenshotsRegex = $input->getArgument('screenshotsRegex');

if (empty($buildnumber)) {
if (empty($buildNumber)) {
throw new \InvalidArgumentException('Missing build number.');
}

$target = PIWIK_DOCUMENT_ROOT . '/tests/PHPUnit/UI/expected-ui-screenshots';
$urlBase = sprintf('http://builds-artifacts.piwik.org/ui-tests.master/%s', $buildNumber);
$diffviewer = Http::sendHttpRequest($urlBase . "/screenshot-diffs/diffviewer.html", $timeout = 60);

$cmd = sprintf('wget -r --level=0 --no-parent -m -nH --cut-dirs=3 -p -erobots=off -P "%s" -A *.png http://builds-artifacts.piwik.org/ui-tests.master/%s/processed-ui-screenshots', $target, $buildnumber);
$output->writeln('Executing command: ' . $cmd);
passthru($cmd);
$dom = new \DOMDocument();
$dom->loadHTML($diffviewer);
foreach ($dom->getElementsByTagName("tr") as $row) {
$columns = $row->getElementsByTagName("td");

$cmd = sprintf('rm -rf %s/Morpheus', $target);
$output->writeln('Executing command: ' . $cmd);
passthru($cmd);
$nameColumn = $columns->item(0);
$processedColumn = $columns->item(2);

$testPlugin = null;
if ($nameColumn
&& preg_match("/\(for ([a-zA-Z_]+) plugin\)/", $dom->saveXml($nameColumn), $matches)
) {
$testPlugin = $matches[1];
}

$file = null;
if ($processedColumn
&& preg_match("/href=\".*\/(.*)\"/", $dom->saveXml($processedColumn), $matches)
) {
$file = $matches[1];
}

if ($file !== null
&& preg_match("/" . $screenshotsRegex . "/", $file)
) {
if ($testPlugin == null) {
$downloadTo = "tests/PHPUnit/UI/expected-ui-screenshots/$file";
} else {
$downloadTo = "plugins/$testPlugin/tests/UI/expected-ui-screenshots/$file";
}

$output->write("<info>Downloading $file to .$downloadTo...</info>\n");
Http::sendHttpRequest("$urlBase/processed-ui-screenshots/$file", $timeout = 60, $userAgent = null,
PIWIK_DOCUMENT_ROOT . "/" . $downloadTo);
}
}
}
}
8 changes: 7 additions & 1 deletion tests/lib/screenshot-testing/support/diff-viewer.js
Expand Up @@ -80,9 +80,15 @@ DiffViewerGenerator.prototype.generate = function (callback) {
entry.processedUrl = self.getUrlForPath(entry.processed);
}

var entryLocationHint = '',
m = entry.expected.match(/\/plugins\/([^\/]*)\//);
if (m) {
entryLocationHint = ' <em>(for ' + m[1] + ' plugin)</em>';
}

diffViewerContent += '\
<tr>\
<td>' + entry.name + '</td>\
<td>' + entry.name + entryLocationHint + '</td>\
<td>' + expectedHtml + '</td>\
<td>' + (entry.processed ? ('<a href="' + entry.processedUrl + '">Processed</a>') : '<em>Not found</em>') + '</td>\
<td>' + (entry.diffUrl ? ('<a href="' + entry.diffUrl + '">Difference</a>') : '<em>Could not create diff.</em>') + '</td>\
Expand Down
1 change: 0 additions & 1 deletion tests/lib/screenshot-testing/support/fs-extras.js
Expand Up @@ -36,7 +36,6 @@ fs.relpath = function (p, start) {

rel_list.push.apply(rel_list, path_list.slice(l));


if (rel_list.length == 0) {
return '.';
}
Expand Down

0 comments on commit f073d10

Please sign in to comment.