Skip to content

Commit

Permalink
Refs #4189, bug fixes for dashboard & changes to make dashboard UI te…
Browse files Browse the repository at this point in the history
…sts possible. Includes:

- fix for bug where top controls not displayed correctly when dashboard is displayed in a widget iframe.
- do not display dashboard manager after dashboard action selected.
- truncate tables when running UI tests w/ --persist-fixture-data so existing database data won't be used if the fixture setup didn't complete before.
- do not create super user more than once in Fixture.
- don't include Test_Piwik_Fixture_CustomAlerts in omni fixture.
- make sure UITestFixture executes the correct code every time regardless of whether --persist-fixture-data isn't used.
- add mouseup/mousedown events to screenshot testing page rendere.
- add ability to call controller methods in screenshot tests and fix API calling mechanism.
  • Loading branch information
diosmosis committed Feb 28, 2014
1 parent 67d34eb commit 57bf5d0
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 44 deletions.
2 changes: 2 additions & 0 deletions plugins/Dashboard/javascripts/dashboard.js
Expand Up @@ -167,6 +167,8 @@ function copyDashboardToUser() {
// on menu item click, trigger action event on this
var self = this;
this.$element.on('click', 'ul.submenu li[data-action]', function (e) {
self.$element.toggleClass('visible');

$(self).trigger($(this).attr('data-action'));
});

Expand Down
4 changes: 4 additions & 0 deletions plugins/SegmentEditor/javascripts/Segmentation.js
Expand Up @@ -1171,6 +1171,10 @@ $(document).ready(function() {
};

$('body')[0].addEventListener('mouseup', this.onMouseUp);

// re-initialize top controls since the size of the control is not the same after it's
// initialized.
initTopControls();
};

/**
Expand Down
7 changes: 6 additions & 1 deletion tests/PHPUnit/Fixture.php
Expand Up @@ -135,6 +135,10 @@ public function performSetUp($testCase, $setupEnvironmentOnly = false)
include "DataFiles/LanguageToCountry.php";
include "DataFiles/Providers.php";

if (!$this->isFixtureSetUp()) {
DbHelper::truncateAllTables();
}

static::createAccessInstance();

// We need to be SU to create websites for tests
Expand Down Expand Up @@ -177,6 +181,7 @@ public function performSetUp($testCase, $setupEnvironmentOnly = false)
$this->setUp();

$this->markFixtureSetUp();
echo "Database {$this->dbName} marked as successfully set up.";
} else {
echo "Using existing database {$this->dbName}.";
}
Expand Down Expand Up @@ -427,7 +432,7 @@ public static function getTokenAuth()
);
}

public static function createSuperUser($removeExisting = true)
private static function createSuperUser($removeExisting = true)
{
$login = self::ADMIN_USER_LOGIN;
$password = UsersManager::getPasswordHash(self::ADMIN_USER_PASSWORD);
Expand Down
3 changes: 1 addition & 2 deletions tests/PHPUnit/Fixtures/ManySitesImportedLogs.php
Expand Up @@ -131,7 +131,7 @@ private function logVisitsWithStaticResolver()
'--enable-testmode' => false,
'--recorders' => '4',
'--recorder-max-payload-size' => '2');
self::createSuperUser();

self::executeLogImporter($logFile, $opts);
}

Expand All @@ -149,7 +149,6 @@ public function logVisitsWithDynamicResolver()
'--enable-testmode' => false,
'--recorders' => '4',
'--recorder-max-payload-size' => '1');
self::createSuperUser();
self::executeLogImporter($logFile, $opts);
}

Expand Down
27 changes: 27 additions & 0 deletions tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php
Expand Up @@ -135,6 +135,33 @@ public function setupDashboards()
FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout');
}

$allWidgets = array();
foreach (WidgetsList::get() as $category => $widgets) {
$allWidgets = array_merge($allWidgets, $widgets);
}
usort($allWidgets, function ($lhs, $rhs) {
return strcmp($lhs['uniqueId'], $rhs['uniqueId']);
});

// create empty dashboard
$widget = reset($allWidgets);
$dashboard = array(
array(
array(
'uniqueId' => $widget['uniqueId'],
'parameters' => $widget['parameters']
)
),
array(),
array()
);

$_GET['name'] = 'D4';
$_GET['layout'] = Common::json_encode($dashboard);
$_GET['idDashboard'] = 5;
$_GET['idSite'] = 2;
FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout');

$_GET = $oldGet;
}

Expand Down
1 change: 1 addition & 0 deletions tests/PHPUnit/Fixtures/OmniFixture.php
Expand Up @@ -39,6 +39,7 @@ public function __construct()
if (is_subclass_of($className, 'Fixture')
&& !is_subclass_of($className, __CLASS__)
&& $className != __CLASS__
&& $className != "Test_Piwik_Fixture_CustomAlerts" // HACK! should check by namespace
) {
$fixture = new $className();
if (!property_exists($fixture, 'dateTime')) {
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php
Expand Up @@ -55,7 +55,7 @@ private function setUpWebsitesAndGoals()
private function trackVisits()
{
$dateTime = $this->dateTime;
$idSite = $this->idSite;
$idSite = 1;
$idGoal_OneConversionPerVisit = $this->idGoal_OneConversionPerVisit;
$idGoal_MultipleConversionPerVisit = $this->idGoal_MultipleConversionPerVisit;

Expand Down
50 changes: 12 additions & 38 deletions tests/PHPUnit/Fixtures/UITestFixture.php
Expand Up @@ -25,24 +25,28 @@ public function setUp()
parent::setUp();

$this->addNewSitesForSiteSelector();
$this->createOneWidgetDashboard();

DbHelper::createAnonymousUser();
UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true);

// launch archiving so tests don't run out of time
$date = Date::factory($this->dateTime)->toString();
VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date);
VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment));
}

public function performSetUp($testCase, $setupEnvironmentOnly = false)
{
parent::performSetUp($testCase, $setupEnvironmentOnly);

AssetManager::getInstance()->removeMergedAssets();

$this->testingEnvironment->forcedNowTimestamp = $this->now->getTimestamp();
$this->testEnvironment->forcedNowTimestamp = $this->now->getTimestamp();

$visitorIdDeterministic = bin2hex(Db::fetchOne(
"SELECT idvisitor FROM " . Common::prefixTable('log_visit')
. " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1"));
$this->testingEnvironment->forcedIdVisitor = $visitorIdDeterministic;

// launch archiving so tests don't run out of time
$date = Date::factory($this->dateTime)->toString();
VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date);
VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment));
$this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic;
}

public function addNewSitesForSiteSelector()
Expand All @@ -51,34 +55,4 @@ public function addNewSitesForSiteSelector()
self::createWebsite("2011-01-01 00:00:00", $ecommerce = 1, $siteName = "Site #$i", $siteUrl = "http://site$i.com");
}
}

public function createOneWidgetDashboard()
{
$allWidgets = array(); // TODO: redundant
foreach (WidgetsList::get() as $category => $widgets) {
$allWidgets = array_merge($allWidgets, $widgets);
}
usort($allWidgets, function ($lhs, $rhs) {
return strcmp($lhs['uniqueId'], $rhs['uniqueId']);
});

// create empty dashboard
$widget = reset($allWidgets);
$dashboard = array(
array(
array(
'uniqueId' => $widget['uniqueId'],
'parameters' => $widget['parameters']
)
),
array(),
array()
);

$_GET['name'] = 'D4';
$_GET['layout'] = Common::json_encode($dashboard);
$_GET['idDashboard'] = 5;
$_GET['idSite'] = 2;
FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout');
}
}
2 changes: 1 addition & 1 deletion tests/PHPUnit/UI
Submodule UI updated from c3d9d7 to 393bc2
22 changes: 22 additions & 0 deletions tests/lib/screenshot-testing/support/page-renderer.js
Expand Up @@ -61,6 +61,14 @@ PageRenderer.prototype.mouseMove = function (selector, waitTime) {
this.queuedEvents.push([this._mousemove, waitTime, selector]);
};

PageRenderer.prototype.mousedown = function (selector, waitTime) {
this.queuedEvents.push([this._mousedown, waitTime, selector]);
};

PageRenderer.prototype.mouseup = function (selector, waitTime) {
this.queuedEvents.push([this._mouseup, waitTime, selector]);
};

PageRenderer.prototype.reload = function (waitTime) {
this.queuedEvents.push([this._reload, waitTime]);
};
Expand Down Expand Up @@ -105,6 +113,20 @@ PageRenderer.prototype._mousemove = function (selector, callback) {
callback();
};

PageRenderer.prototype._mousedown = function (selector, callback) {
var position = this._getPosition(selector);
this.webpage.sendEvent('mousedown', position.x, position.y);

callback();
};

PageRenderer.prototype._mouseup = function (selector, callback) {
var position = this._getPosition(selector);
this.webpage.sendEvent('mouseup', position.x, position.y);

callback();
};

PageRenderer.prototype._reload = function (callback) {
this.webpage.reload();

Expand Down
16 changes: 15 additions & 1 deletion tests/lib/screenshot-testing/support/test-environment.js
Expand Up @@ -28,6 +28,20 @@ TestingEnvironment.prototype.callApi = function (method, params, done) {
params.method = method;
params.format = 'json';

this._call(params, done);
};

TestingEnvironment.prototype.callController = function (method, params, done) {
var parts = method.split('.');

params.module = parts[0];
params.action = parts[1];
params.idSite = params.idSite || 1;

this._call(params, done);
};

TestingEnvironment.prototype._call = function (params, done) {
var url = path.join(config.piwikUrl, "tests/PHPUnit/proxy/index.php?");
for (var key in params) {
url += key + "=" + encodeURIComponent(params[key]) + "&";
Expand All @@ -38,7 +52,7 @@ TestingEnvironment.prototype.callApi = function (method, params, done) {
page.open(url, function () {
var response = page.plainText;
if (response.replace(/\s*/g, "")) {
JSON.parse(response);
response = JSON.parse(response);
}

page.close();
Expand Down

0 comments on commit 57bf5d0

Please sign in to comment.