Skip to content

Commit

Permalink
Refs #2935, add installation UI test, allow no fixture to be specifie…
Browse files Browse the repository at this point in the history
…d for screenshot test and fix following installation process regressions:

- pending events should be executed after all plugins successfully loaded so plugin order in config file is unimportant
- do not set piwikUrl on View instances if the DB cannot be connected to
- create Twig instance when clearing template cache instead of new View
  • Loading branch information
diosmosis committed Mar 12, 2014
1 parent 3d3f3c0 commit 50742af
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
8 changes: 7 additions & 1 deletion core/Plugin/Manager.php
Expand Up @@ -669,6 +669,7 @@ private function reloadPlugins()

$this->pluginsToLoad = array_unique($this->pluginsToLoad);

$pluginsToPostPendingEventsTo = array();
foreach ($this->pluginsToLoad as $pluginName) {
if (!$this->isPluginLoaded($pluginName)
&& !$this->isPluginThirdPartyAndBogus($pluginName)
Expand All @@ -678,9 +679,14 @@ private function reloadPlugins()
continue;
}

EventDispatcher::getInstance()->postPendingEventsTo($newPlugin);
$pluginsToPostPendingEventsTo[] = $newPlugin;
}
}

// post pending events after all plugins are successfully loaded
foreach ($pluginsToPostPendingEventsTo as $plugin) {
EventDispatcher::getInstance()->postPendingEventsTo($plugin);
}
}

public function getIgnoredBogusPlugins()
Expand Down
11 changes: 8 additions & 3 deletions core/View.php
Expand Up @@ -134,9 +134,14 @@ public function __construct($templateFile)
$this->initializeTwig();

$this->piwik_version = Version::VERSION;
$this->piwikUrl = SettingsPiwik::getPiwikUrl();
$this->userLogin = Piwik::getCurrentUserLogin();
$this->isSuperUser = Access::getInstance()->hasSuperUserAccess(); // TODO: redundancy w/ userIsSuperUser

try {
$this->piwikUrl = SettingsPiwik::getPiwikUrl();
} catch (Exception $ex) {
// pass (occurs when DB cannot be connected to, perhaps piwik URL cache should be stored in config file...)
}
}

/**
Expand Down Expand Up @@ -337,8 +342,8 @@ public function assign($var, $value = null)
*/
static public function clearCompiledTemplates()
{
$view = new View(null);
$view->twig->clearTemplateCache();
$twig = new Twig();
$twig->getTwigEnvironment()->clearTemplateCache();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPUnit/UI
Submodule UI updated from f18a91 to f744d2
7 changes: 6 additions & 1 deletion tests/lib/screenshot-testing/support/app.js
Expand Up @@ -105,7 +105,7 @@ Application.prototype.loadTestModules = function () {

// configure suites (auto-add fixture setup/teardown)
mocha.suite.suites.forEach(function (suite) {
var fixture = suite.fixture || 'UITestFixture';
var fixture = typeof suite.fixture === 'undefined' ? 'UITestFixture' : suite.fixture;

suite.beforeAll(function (done) {
testEnvironment.setupFixture(fixture, done);
Expand All @@ -115,6 +115,11 @@ Application.prototype.loadTestModules = function () {
suite._beforeAll.unshift(suite._beforeAll.pop());

suite.afterAll(function (done) {
if (!fixture) {
done();
return;
}

testEnvironment.teardownFixture(fixture, done);
});
});
Expand Down
24 changes: 13 additions & 11 deletions tests/lib/screenshot-testing/support/setupDatabase.php
Expand Up @@ -20,19 +20,21 @@
require_once "PHPUnit/Autoload.php";
require_once dirname(__FILE__) . "/../../../PHPUnit/bootstrap.php";

if (!class_exists($fixtureClass)) {
$fixtureClass = "Piwik\\Tests\\Fixtures\\$fixtureClass";
}
if (!empty($fixtureClass)) {
if (!class_exists($fixtureClass)) {
$fixtureClass = "Piwik\\Tests\\Fixtures\\$fixtureClass";
}

$fixture = new $fixtureClass();
if (in_array("--persist-fixture-data", $argv)) {
$fixture->persistFixtureData = true;
}
if (in_array("--drop", $argv)) {
$fixture->resetPersistedFixture = true;
$fixture = new $fixtureClass();
if (in_array("--persist-fixture-data", $argv)) {
$fixture->persistFixtureData = true;
}
if (in_array("--drop", $argv)) {
$fixture->resetPersistedFixture = true;
}
$fixture->printToScreen = true;
$fixture->performSetUp("");
}
$fixture->printToScreen = true;
$fixture->performSetUp("");

// make sure symbolic links exist (phantomjs doesn't support symlink-ing yet)
foreach (array('libs', 'plugins', 'tests', 'piwik.js') as $linkName) {
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/screenshot-testing/support/test-environment.js
Expand Up @@ -88,7 +88,7 @@ TestingEnvironment.prototype.setupFixture = function (fixtureClass, done) {
console.log(" Setting up fixture " + fixtureClass + "...");

var setupFile = path.join("./support", "setupDatabase.php"),
processArgs = [setupFile, "--server=" + JSON.stringify(config.phpServer), "--fixture=" + fixtureClass];
processArgs = [setupFile, "--server=" + JSON.stringify(config.phpServer), "--fixture=" + (fixtureClass || "")];

if (options['persist-fixture-data']) {
processArgs.push('--persist-fixture-data');
Expand Down

0 comments on commit 50742af

Please sign in to comment.