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

SyncUITestScreenshots.php « Commands « CoreConsole « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6317581c26a0009ac938d488228c7fd2cd4a55b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */

namespace Piwik\Plugins\CoreConsole\Commands;

use Piwik\Http;
use Piwik\Plugin\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 */
class SyncUITestScreenshots extends ConsoleCommand
{
    protected function configure()
    {
        $this->setName('development:sync-ui-test-screenshots');
        $this->setDescription('For Piwik core devs. Copies screenshots '
                            . 'from travis artifacts to tests/PHPUnit/UI/expected-ui-screenshots/');
        $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');
        $screenshotsRegex = $input->getArgument('screenshotsRegex');

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

        $urlBase = sprintf('http://builds-artifacts.piwik.org/ui-tests.master/%s', $buildNumber);
        $diffviewer = Http::sendHttpRequest($urlBase . "/screenshot-diffs/diffviewer.html", $timeout = 60);
        $diffviewer = str_replace('&', '&amp;', $diffviewer);

        $dom = new \DOMDocument();
        $dom->loadHTML($diffviewer);
        foreach ($dom->getElementsByTagName("tr") as $row) {
            $columns = $row->getElementsByTagName("td");

            $nameColumn = $columns->item(0);
            $processedColumn = $columns->item(3);

            $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);
            }
        }
    }
}