diff --git a/misc/cron/updatetoken.php b/misc/cron/updatetoken.php index f7cba2ab2092e10d2abb76651a72211dad9839ab..9e6713235bed05893fc9a63a6be67ac710f4836d 100644 --- a/misc/cron/updatetoken.php +++ b/misc/cron/updatetoken.php @@ -31,7 +31,9 @@ if (!Common::isPhpCliMode()) { $testmode = in_array('--testmode', $_SERVER['argv']); if ($testmode) { - Config::getInstance()->setTestEnvironment(); + require_once PIWIK_INCLUDE_PATH . "/tests/PHPUnit/TestingEnvironment.php"; + + \Piwik_TestingEnvironment::addHooks(); } $token = Db::get()->fetchOne("SELECT token_auth diff --git a/plugins/CoreConsole/Commands/RunUITests.php b/plugins/CoreConsole/Commands/RunUITests.php index 1eab394a0ee668eb4321630b60ee1578a9b96706..005a1bf44042cd5c84c2029b57b31eb84cf28f5c 100644 --- a/plugins/CoreConsole/Commands/RunUITests.php +++ b/plugins/CoreConsole/Commands/RunUITests.php @@ -23,6 +23,7 @@ class RunUITests extends ConsoleCommand $this->addOption("persist-fixture-data", null, InputOption::VALUE_NONE, "Persist test data in a database and do not execute tear down."); $this->addOption('keep-symlinks', null, InputOption::VALUE_NONE, "Keep recursive directory symlinks so test pages can be viewed in a browser."); $this->addOption('print-logs', null, InputOption::VALUE_NONE, "Print webpage logs even if tests succeed."); + $this->addOption('drop', null, InputOption::VALUE_NONE, "Drop the existing database and re-setup a persisted fixture."); } protected function execute(InputInterface $input, OutputInterface $output) @@ -31,6 +32,7 @@ class RunUITests extends ConsoleCommand $persistFixtureData = $input->getOption("persist-fixture-data"); $keepSymlinks = $input->getOption('keep-symlinks'); $printLogs = $input->getOption('print-logs'); + $drop = $input->getOption('drop'); $options = array(); if ($persistFixtureData) { @@ -44,6 +46,10 @@ class RunUITests extends ConsoleCommand if ($printLogs) { $options[] = "--print-logs"; } + + if ($drop) { + $options[] = "--drop"; + } $options = implode(" ", $options); $specs = implode(" ", $specs); diff --git a/plugins/UserCountryMap/javascripts/realtime-map.js b/plugins/UserCountryMap/javascripts/realtime-map.js index 45e3076125413d88e7203e9c10d2fabe28d73c51..9b6dd763bfae728ccf48a53a3f1394e33cfaf04f 100644 --- a/plugins/UserCountryMap/javascripts/realtime-map.js +++ b/plugins/UserCountryMap/javascripts/realtime-map.js @@ -449,7 +449,7 @@ visitSymbols.layout().render(); - if (!enableAnimation) { + if (enableAnimation) { $.each(newSymbols, function (i, s) { if (i > 10) return false; diff --git a/plugins/Zeitgeist/templates/empty.twig b/plugins/Zeitgeist/templates/empty.twig index d892ab6016d3f576b6ce14409c5845d0bcbc710e..4275f8050375c08a68719e50a3d0a2c6550b1abb 100644 --- a/plugins/Zeitgeist/templates/empty.twig +++ b/plugins/Zeitgeist/templates/empty.twig @@ -1,6 +1,2 @@ {% block content %} -<<<<<<< HEAD {% endblock %} -======= -{% endblock %} ->>>>>>> 4d5e89b... refs #2174 loads of bugfixes and improvements diff --git a/tests/PHPUnit/Fixture.php b/tests/PHPUnit/Fixture.php index 67fba647f17bc88cd83c3cb786e7b1dcee22e67f..7b9fb329ac9bdf8f658e47c4a4137a298f4eecf0 100644 --- a/tests/PHPUnit/Fixture.php +++ b/tests/PHPUnit/Fixture.php @@ -64,6 +64,8 @@ class Fixture extends PHPUnit_Framework_Assert public $overwriteExisting = true; public $configureComponents = true; public $persistFixtureData = false; + public $resetPersistedFixture = false; + public $printToScreen = false; public $testEnvironment = null; @@ -108,7 +110,11 @@ class Fixture extends PHPUnit_Framework_Assert static::connectWithoutDatabase(); - if ($this->dropDatabaseInSetUp) { + if ($this->dropDatabaseInSetUp + || $this->resetPersistedFixture + ) { + $this->log("Dropping database..."); + $this->dropDatabase(); } @@ -180,12 +186,10 @@ class Fixture extends PHPUnit_Framework_Assert $this->setUp(); $this->markFixtureSetUp(); - echo "Database {$this->dbName} marked as successfully set up."; + $this->log("Database {$this->dbName} marked as successfully set up."); } else { - echo "Using existing database {$this->dbName}."; + $this->log("Using existing database {$this->dbName}."); } - - $this->testEnvironment->save(); } public function isFixtureSetUp() @@ -685,6 +689,13 @@ class Fixture extends PHPUnit_Framework_Assert DbHelper::dropDatabase(); } + + public function log($message) + { + if ($this->printToScreen) { + echo $message . "\n"; + } + } } // TODO: remove when other plugins don't use BaseFixture diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php index 3af47af61a55eb2630cdd226217325b8281b9aed..da4bbdf827f3310d8baa788c9c4e7e1889bce451 100644 --- a/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php +++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php @@ -143,25 +143,6 @@ class Test_Piwik_Fixture_ManySitesImportedLogsWithXssAttempts extends Test_Piwik 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; } diff --git a/tests/PHPUnit/Fixtures/OmniFixture.php b/tests/PHPUnit/Fixtures/OmniFixture.php index e2b351a1760049d29823b1f22eda37ba5c12a69f..ac0c610b792519d1761cd1b126e4ddc8cb937320 100644 --- a/tests/PHPUnit/Fixtures/OmniFixture.php +++ b/tests/PHPUnit/Fixtures/OmniFixture.php @@ -39,7 +39,6 @@ class OmniFixture extends \Fixture 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')) { diff --git a/tests/PHPUnit/Fixtures/UITestFixture.php b/tests/PHPUnit/Fixtures/UITestFixture.php index 9c89de3619097c6de945456444ffd7c0af716352..22f48283b047b8a515ffa2b4c554fad3b0ff9cc1 100644 --- a/tests/PHPUnit/Fixtures/UITestFixture.php +++ b/tests/PHPUnit/Fixtures/UITestFixture.php @@ -14,6 +14,8 @@ use Piwik\AssetManager; use Piwik\Date; use Piwik\Common; use Piwik\Db; +use Piwik\FrontController; +use Piwik\Option; /** * Fixture for UI tests. @@ -25,11 +27,14 @@ class UITestFixture extends OmniFixture parent::setUp(); $this->addNewSitesForSiteSelector(); + $this->createEmptyDashboard(); DbHelper::createAnonymousUser(); UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true); - // launch archiving so tests don't run out of time + Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp()); + + // 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)); @@ -41,12 +46,18 @@ class UITestFixture extends OmniFixture AssetManager::getInstance()->removeMergedAssets(); - $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->testEnvironment->forcedIdVisitor = $visitorIdDeterministic; + + $forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp"); + if ($forcedNowTimestamp == false) { + throw Exception("Incorrect fixture setup, Tests.forcedNowTimestamp option does not exist! Run the setup again."); + } + + $this->testEnvironment->forcedNowTimestamp = $forcedNowTimestamp; + $this->testEnvironment->save(); } public function addNewSitesForSiteSelector() @@ -55,4 +66,33 @@ class UITestFixture extends OmniFixture self::createWebsite("2011-01-01 00:00:00", $ecommerce = 1, $siteName = "Site #$i", $siteUrl = "http://site$i.com"); } } + + public function createEmptyDashboard() + { + $oldGet = $_GET; + + // create empty dashboard + $dashboard = array( + array( + array( + 'uniqueId' => "widgetVisitsSummarygetEvolutionGraphcolumnsArray", + 'parameters' => array( + 'module' => 'VisitsSummary', + 'action' => 'getEvolutionGraph', + 'columns' => 'nb_visits' + ) + ) + ), + array(), + array() + ); + + $_GET['name'] = 'D4'; + $_GET['layout'] = Common::json_encode($dashboard); + $_GET['idDashboard'] = 5; + $_GET['idSite'] = 2; + FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout'); + + $_GET = $oldGet; + } } \ No newline at end of file diff --git a/tests/PHPUnit/TestingEnvironment.php b/tests/PHPUnit/TestingEnvironment.php index 7c1ba8f1ac467ab89e1e650d678a5341fc30fee9..65b1095880d059f6967dbfa929956713bbdb34ad 100644 --- a/tests/PHPUnit/TestingEnvironment.php +++ b/tests/PHPUnit/TestingEnvironment.php @@ -5,6 +5,8 @@ use Piwik\Config; use Piwik\Common; use Piwik\Session\SessionNamespace; +require_once PIWIK_INCLUDE_PATH . "/core/Config.php"; + if (!defined('PIWIK_TEST_MODE')) { define('PIWIK_TEST_MODE', true); } @@ -93,10 +95,6 @@ class Piwik_TestingEnvironment $config->setTestEnvironment(); - if ($testingEnvironment->dbName) { - $config->database_tests['dbname'] = $config->database['dbname'] = $testingEnvironment->dbName; - } - $pluginsToLoad = \Piwik\Plugin\Manager::getInstance()->getPluginsToLoadDuringTests(); $config->Plugins = array('Plugins' => $pluginsToLoad); @@ -106,6 +104,16 @@ class Piwik_TestingEnvironment $config->Plugins_Tracker = array('Plugins_Tracker' => $trackerPluginsToLoad); $config->log['log_writers'] = array('file'); }); + Piwik::addAction('Db.getDatabaseConfig', function (&$dbConfig) use ($testingEnvironment) { + if ($testingEnvironment->dbName) { + $dbConfig['dbname'] = $testingEnvironment->dbName; + } + }); + Piwik::addAction('Tracker.getDatabaseConfig', function (&$dbConfig) use ($testingEnvironment) { + if ($testingEnvironment->dbName) { + $dbConfig['dbname'] = $testingEnvironment->dbName; + } + }); Piwik::addAction('Request.dispatch', function() { \Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true; \Piwik\Visualization\Sparkline::$enableSparklineImages = false; @@ -114,6 +122,9 @@ class Piwik_TestingEnvironment Piwik::addAction('AssetManager.getStylesheetFiles', function(&$stylesheets) { $stylesheets[] = 'tests/resources/screenshot-override/override.css'; }); + Piwik::addAction('AssetManager.getJavaScriptFiles', function(&$jsFiles) { + $jsFiles[] = 'tests/resources/screenshot-override/override.js'; + }); Piwik::addAction('Test.Mail.send', function($mail) { $outputFile = PIWIK_INCLUDE_PATH . 'tmp/' . Common::getRequestVar('module') . '.' . Common::getRequestVar('action') . '.mail.json'; diff --git a/tests/PHPUnit/UI b/tests/PHPUnit/UI index 1e8287b5c9b7afa3d67fee2b5932afc87d30fa26..b3749d8fa0ad972ce4c0fe2b3767d425f45bdb48 160000 --- a/tests/PHPUnit/UI +++ b/tests/PHPUnit/UI @@ -1 +1 @@ -Subproject commit 1e8287b5c9b7afa3d67fee2b5932afc87d30fa26 +Subproject commit b3749d8fa0ad972ce4c0fe2b3767d425f45bdb48 diff --git a/tests/PHPUnit/proxy/piwik.php b/tests/PHPUnit/proxy/piwik.php index bae1f90a72ae092405e2fdbb53a5abeb7fe47456..57766608402b44e1e136b5b68615a9b5fbca7acf 100755 --- a/tests/PHPUnit/proxy/piwik.php +++ b/tests/PHPUnit/proxy/piwik.php @@ -21,6 +21,8 @@ require realpath(dirname(__FILE__)) . "/includes.php"; // calling us waits for the full request to process before unblocking ob_start(); +Piwik_TestingEnvironment::addHooks(); + Config::getInstance()->setTestEnvironment(); try { diff --git a/tests/lib/screenshot-testing/support/app.js b/tests/lib/screenshot-testing/support/app.js index 2a812ada0b90ba7c9b2755146aa1d09dbdaf5634..73eade6892757d4a97fd13a905eef2cbae0f20d3 100644 --- a/tests/lib/screenshot-testing/support/app.js +++ b/tests/lib/screenshot-testing/support/app.js @@ -139,6 +139,10 @@ Application.prototype.setupDatabase = function () { processArgs.push('--persist-fixture-data'); } + if (options['drop']) { + processArgs.push('--drop'); + } + var child = require('child_process').spawn(config.php, processArgs); child.stdout.on("data", function (data) { diff --git a/tests/lib/screenshot-testing/support/page-renderer.js b/tests/lib/screenshot-testing/support/page-renderer.js index 65a492164e55b81a7264910717d26f3161099412..3c99751faf6207050ea016ae8f84eaf826002fe8 100644 --- a/tests/lib/screenshot-testing/support/page-renderer.js +++ b/tests/lib/screenshot-testing/support/page-renderer.js @@ -40,6 +40,10 @@ PageRenderer.prototype.getCurrentUrl = function () { }; // event queueing functions +PageRenderer.prototype.wait = function (waitTime) { + this.queuedEvents.push([this._wait, waitTime]); +}; + PageRenderer.prototype.click = function () { var selector = arguments[0], waitTime = null, @@ -86,6 +90,10 @@ PageRenderer.prototype.evaluate = function (impl, waitTime) { }; // event impl functions +PageRenderer.prototype._wait = function (callback) { + callback(); +}; + PageRenderer.prototype._click = function (selector, modifiers, callback) { var position = this._getPosition(selector); diff --git a/tests/lib/screenshot-testing/support/setupDatabase.php b/tests/lib/screenshot-testing/support/setupDatabase.php index c70eeb45af1678221fcb38b05fc82bb5368cb61f..bbd7c979f2dc6e6857324a54f7d6755e8bab521c 100644 --- a/tests/lib/screenshot-testing/support/setupDatabase.php +++ b/tests/lib/screenshot-testing/support/setupDatabase.php @@ -21,6 +21,10 @@ $fixture = new \Piwik\Tests\Fixtures\UITestFixture(); if (in_array("--persist-fixture-data", $argv)) { $fixture->persistFixtureData = true; } +if (in_array("--drop", $argv)) { + $fixture->resetPersistedFixture = true; +} +$fixture->printToScreen = true; $fixture->performSetUp(""); // make sure symbolic links exist (phantomjs doesn't support symlink-ing yet) diff --git a/tests/lib/screenshot-testing/support/teardownDatabase.php b/tests/lib/screenshot-testing/support/teardownDatabase.php index 077117069268bdd1c6964222861fdf1c21322432..45a07c91aa6084b5efb25d687941a08dcfd54165 100644 --- a/tests/lib/screenshot-testing/support/teardownDatabase.php +++ b/tests/lib/screenshot-testing/support/teardownDatabase.php @@ -19,5 +19,6 @@ require_once dirname(__FILE__) . "/../../../PHPUnit/bootstrap.php"; $fixture = new \Piwik\Tests\Fixtures\UITestFixture(); $fixture->dropDatabaseInSetUp = false; +$fixture->printToScreen = true; $fixture->performSetUp("", $environmentOnly = true); $fixture->performTearDown(""); \ No newline at end of file diff --git a/tests/resources/screenshot-override/override.js b/tests/resources/screenshot-override/override.js index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7113d0d1341e30b3b4748ea6f68f22b29f4196ae 100644 --- a/tests/resources/screenshot-override/override.js +++ b/tests/resources/screenshot-override/override.js @@ -0,0 +1,3 @@ +$(document).ready(function () { + $('.ui-inline-help:contains(UTC time is)').hide(); +}); \ No newline at end of file