Skip to content

Commit

Permalink
Refs #4087, add UI screenshot tests to new repository, enable tests o…
Browse files Browse the repository at this point in the history
…n travis and make sure new repo is built every time integration tests pass on piwik build.
  • Loading branch information
Benaka Moorthi committed Sep 10, 2013
1 parent d1c056d commit d57f4a8
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 226 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,4 @@ tests/lib/xhprof-0.9.2/extension/run-tests.php
docs/
composer.phar
vendor/
/.htaccess
tests/PHPUnit/UI/processed-ui-screenshots
tests/PHPUnit/UI/expected-ui-screenshots

/.htaccess
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tests/PHPUnit/UI"]
path = tests/PHPUnit/UI
url = https://github.com/piwik/piwik-ui-tests.git
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ env:
- TEST_SUITE=PluginTests
- TEST_SUITE=CoreTests
- TEST_SUITE=IntegrationTests
#- TEST_DIR=UI
global:
secure: "AMhZmPZx4SUcuZRBzGHlQPxzM4D8FvFB3UThDa52gbi9KIBrwcumzV2VGi6B\n5fgjwtB4XTE1In7qhY2HMikPWBmWYYOQ5QcMPJsqqHt4iMmahx8WKzne6NOk\nNpqAuje/fulNGeP2LJZi0nrub3Fh4VwXaOvpNloKNQN/2JuqPtM="
- secure: "AMhZmPZx4SUcuZRBzGHlQPxzM4D8FvFB3UThDa52gbi9KIBrwcumzV2VGi6B\n5fgjwtB4XTE1In7qhY2HMikPWBmWYYOQ5QcMPJsqqHt4iMmahx8WKzne6NOk\nNpqAuje/fulNGeP2LJZi0nrub3Fh4VwXaOvpNloKNQN/2JuqPtM="
- secure: "DySde80fX3dw0osGY5s5lGiGLjMleUkkONsuRDC4xjT1hAQP94FGHpPXVZV8\nAQY0s8MQmcK2eRLOQrmE9Bh1XXbGqh40s66XhSWq0hulFHxQH5OLaZXccFeu\n5WxGkHXnNDIc+CVhXW/IIbHZPO1K6hffS8fuvP1o6mYgxwFL6Xw="

# Run PHP 5.4 for aa tests to generate
# code coverage.
Expand Down Expand Up @@ -43,6 +43,7 @@ before_script:

after_success:
- cd $TRAVIS_BUILD_DIR
- ./tests/travis/initiate_ui_tests.sh
- ./tests/travis/generate_docs.sh

after_script:
Expand Down
4 changes: 2 additions & 2 deletions core/ViewDataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,10 @@ private function overrideViewPropertiesWithQueryParams()
// TODO: should mark properties that are overridable so not all properties can be overidden this way
$queryParams = $_GET + $_POST;
foreach ($queryParams as $name => $value) {
if (empty($queryParams[$name])) {
if (empty($value)) {

This comment has been minimized.

Copy link
@mattab

mattab Sep 12, 2013

Member

is it expected that overriding properties with 0 will not work? (since empty( "0" ) === true)

This comment has been minimized.

Copy link
@diosmosis

diosmosis Sep 12, 2013

Member

tl;dr: you're right that's a bug, but I have a fix in a local branch

Sort of. It was a quick fix for an odd bug, however, I have a replacement for the whole system in a local branch which will be more secure. It was waiting for my uitests work to be finished (and now visitor profile).

continue;
}

$value = Common::getRequestVar($name, $default = null, $type = null, $queryParams);

if (Properties::isCoreViewProperty($name)) {
Expand Down
6 changes: 3 additions & 3 deletions plugins/CoreVisualizations/javascripts/jqplot.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
tickOptions: {
showMark: false,
fontSize: '11px',
fontFamily: 'Arial'
fontFamily: window.piwik.jqplotLabelFont || 'Arial'
},
rendererOptions: {
drawBaseline: false
Expand Down Expand Up @@ -860,7 +860,7 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () {

var ctx = legend.legendCanvas._ctx;
ctx.save();
ctx.font = '11px Arial';
ctx.font = '11px ' + (window.piwik.jqplotLabelFont || 'Arial');

// render series names
var x = 0;
Expand Down Expand Up @@ -996,7 +996,7 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () {
var ctx = legend.pieLegendCanvas._ctx;
ctx.save();

ctx.font = '11px Arial';
ctx.font = '11px ' + (window.piwik.jqplotLabelFont || 'Arial');

// render labels
var height = legend.pieLegendCanvas._elem.height();
Expand Down
11 changes: 11 additions & 0 deletions tests/PHPUnit/TestingEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public static function addHooks()
});
Piwik_AddAction('Config.createConfigSingleton', function($config) {
$config->setTestEnvironment();

$pluginsToLoad = array(
"CorePluginsAdmin", "CoreAdminHome", "CoreHome", "Proxy", "API", "Widgetize", "Transitions",
"LanguagesManager", "Actions", "Dashboard", "MultiSites", "Referers", "UserSettings", "Goals",
"SEO", "UserCountry", "VisitsSummary", "VisitFrequency", "VisitTime", "VisitorInterest",
"ExampleAPI", "ExamplePlugin", "ExampleRssWidget", "Provider", "Feedback", "Login", "UsersManager",
"SitesManager", "Installation", "CoreUpdater", "PDFReports", "UserCountryMap", "Live",
"CustomVariables", "PrivacyManager", "ImageGraph", "DoNotTrack", "Annotations", "MobileMessaging",
"Overlay", "SegmentEditor", "VisitorGenerator", "DevicesDetection", "DBStats",

This comment has been minimized.

Copy link
@halfdan

halfdan Sep 12, 2013

Member

VisitorGenerator and SecurityInfo won't be delivered with 2.0 so they should be removed from the list IMHO - @mattab?

This comment has been minimized.

Copy link
@diosmosis

diosmosis Sep 12, 2013

Member

They're not essential to the tests in any way, I'll remove them.

);
$config->Plugins = array('Plugins' => $pluginsToLoad);
});
Piwik_AddAction('FrontController.dispatch', function() {
\Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true;
Expand Down
1 change: 1 addition & 0 deletions tests/PHPUnit/UI
Submodule UI added at 4883ae
139 changes: 0 additions & 139 deletions tests/PHPUnit/UI/UIIntegrationTest.php

This file was deleted.

40 changes: 20 additions & 20 deletions tests/PHPUnit/UITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public static function createAccessInstance()

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()
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)");
Expand All @@ -51,17 +49,25 @@ public static function setUpBeforeClass()
// make sure processed & expected dirs exist
self::makeDirsAndLinks();

// run slimerjs/phantomjs w/ all urls so we only invoke it once
$urls = array();
foreach (static::getUrlsForTesting() as $testInfo) {
list($name, $urlQuery) = $testInfo;
// run slimerjs/phantomjs w/ all urls so we only invoke it once per 25 entries (travis needs
// there to be output)
$urlsToTest = static::getUrlsForTesting();

list($processedScreenshotPath, $expectedScreenshotPath) = self::getProcessedAndExpectedScreenshotPaths($name);
$urls[] = array($processedScreenshotPath, self::getProxyUrl() . $urlQuery);
reset($urlsToTest);
for ($i = 0; $i < count($urlsToTest); $i += 25) {
$urls = array();
for ($j = $i; $j != $i + 25 && $j < count($urlsToTest); ++$j) {
list($name, $urlQuery) = current($urlsToTest);

list($processedScreenshotPath, $expectedScreenshotPath) = self::getProcessedAndExpectedScreenshotPaths($name);
$urls[] = array($processedScreenshotPath, self::getProxyUrl() . $urlQuery);

next($urlsToTest);
}

echo "Generating screenshots...\n";
self::runCaptureProgram($urls);
}

echo "Generating screenshots...\n";
self::runCaptureProgram($urls);
}

public static function tearDownAfterClass()
Expand Down Expand Up @@ -100,7 +106,6 @@ 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);
Expand Down Expand Up @@ -140,11 +145,6 @@ 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);
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function getProxyUrl()

private static function makeDirsAndLinks()
{
$dirs = self::getProcessedAndExpectedDirs();
$dirs = array_merge(self::getProcessedAndExpectedDirs(), array(PIWIK_INCLUDE_PATH . '/tmp/sessions'));
foreach ($dirs as $dir) {
if (!is_dir($dir)) {
mkdir($dir);
Expand Down
38 changes: 22 additions & 16 deletions tests/resources/screenshot-capture/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var fs = require('fs');
var app = typeof slimer === 'undefined' ? phantom : slimer;
var readFileSync = fs.readFileSync || fs.read;

var VERBOSE = false;

var PageRenderer = function() {
this.start = new Date();

Expand All @@ -11,6 +13,9 @@ var PageRenderer = function() {
this.outputPath = '';
this.url = '';

this.webpage = require('webpage').create();
this._setupWebpageEvents();

this._setScriptTimeout();
};

Expand All @@ -36,32 +41,21 @@ PageRenderer.prototype = {

this.webpage = require('webpage').create();
this._setupWebpageEvents();

this.webpage.viewportSize = {width:1350, height:768};

var self = this;
this.webpage.open(this.url, function () {
self._setPageTimeouts();
});
this.webpage.open(this.url);
this._setPageTimeouts();
},

_setPageTimeouts: function () {
var url = this.url, self = this;

// 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();
console.log("__AJAX_DONE__");
});
}
}, 1000 * 60);
Expand All @@ -88,6 +82,18 @@ PageRenderer.prototype = {
console.log("LOGGED: " + message);
}
};

if (VERBOSE) {
this.webpage.onResourceReceived = function (response) {
console.log('Response (#' + response.id + ', stage "' + response.stage + '", size "' + response.bodySize +
'", status "' + response.status + '"): ' + response.url);
};
}

this.webpage.onResourceError = function (resourceError) {
console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
};
},

_renderNextUrl: function () {
Expand All @@ -114,7 +120,7 @@ PageRenderer.prototype = {
setTimeout(function() {
console.log("ERROR: Timed out!");
app.exit(1);
}, Math.max(1000 * 15 * this.urls.length, 1000 * 60 * 5));
}, Math.max(1000 * 15 * this.urls.length, 1000 * 60 * 10));
},
};

Expand Down
Binary file removed tests/resources/screenshot-override/open_sans.woff
Binary file not shown.
Binary file removed tests/resources/screenshot-override/open_sans_b.woff
Binary file not shown.
Binary file not shown.
Binary file removed tests/resources/screenshot-override/open_sans_i.woff
Binary file not shown.
Loading

0 comments on commit d57f4a8

Please sign in to comment.