From 87ad77cb539e868b3fa8f20cd7d6074b9e154d0e Mon Sep 17 00:00:00 2001 From: diosmosis <benakamoorthi@fastmail.fm> Date: Fri, 27 Jun 2014 15:02:43 -0700 Subject: [PATCH] Allow UI testing system to specify extra plugins to load and install when running UI tests for a plugin. --- plugins/CoreConsole/Commands/SetupFixture.php | 7 +++++++ tests/PHPUnit/Fixture.php | 9 +++++---- tests/lib/screenshot-testing/support/test-environment.js | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/CoreConsole/Commands/SetupFixture.php b/plugins/CoreConsole/Commands/SetupFixture.php index 91f79d0d1b..9ff1f89676 100644 --- a/plugins/CoreConsole/Commands/SetupFixture.php +++ b/plugins/CoreConsole/Commands/SetupFixture.php @@ -53,6 +53,8 @@ class SetupFixture extends ConsoleCommand "Used by UI tests. Creates symlinks to root directory in tests/PHPUnit/proxy."); $this->addOption('server-global', null, InputOption::VALUE_REQUIRED, "Used by UI tests. Sets the \$_SERVER global variable from a JSON string."); + $this->addOption('plugins', null, InputOption::VALUE_REQUIRED, + "Used by UI tests. Comma separated list of plugin names to activate and install when setting up a fixture."); } protected function execute(InputInterface $input, OutputInterface $output) @@ -108,6 +110,11 @@ class SetupFixture extends ConsoleCommand $fixture->resetPersistedFixture = true; } + $extraPluginsToLoad = $input->getOption('plugins'); + if ($extraPluginsToLoad) { + $fixture->extraPluginsToLoad = explode(',', $extraPluginsToLoad); + } + if($fixture->createConfig) { Config::getInstance()->setTestEnvironment(); } diff --git a/tests/PHPUnit/Fixture.php b/tests/PHPUnit/Fixture.php index f651dd1d75..a2fa0258e2 100644 --- a/tests/PHPUnit/Fixture.php +++ b/tests/PHPUnit/Fixture.php @@ -68,6 +68,7 @@ class Fixture extends PHPUnit_Framework_Assert public $printToScreen = false; public $testCaseClass = false; + public $extraPluginsToLoad = array(); public $testEnvironment = null; @@ -175,7 +176,7 @@ class Fixture extends PHPUnit_Framework_Assert Cache::deleteTrackerCache(); - static::loadAllPlugins($this->getTestEnvironment(), $this->testCaseClass); + static::loadAllPlugins($this->getTestEnvironment(), $this->testCaseClass, $this->extraPluginsToLoad); $_GET = $_REQUEST = array(); $_SERVER['HTTP_REFERER'] = ''; @@ -267,7 +268,7 @@ class Fixture extends PHPUnit_Framework_Assert Translate::unloadEnglishTranslation(); } - public static function loadAllPlugins($testEnvironment = null, $testCaseClass = false) + public static function loadAllPlugins($testEnvironment = null, $testCaseClass = false, $extraPluginsToLoad = array()) { DbHelper::createTables(); $pluginsManager = \Piwik\Plugin\Manager::getInstance(); @@ -275,10 +276,10 @@ class Fixture extends PHPUnit_Framework_Assert $plugins = $pluginsManager->getPluginsToLoadDuringTests(); // make sure the plugin that executed this method is included in the plugins to load - $extraPlugins = array( + $extraPlugins = array_merge($extraPluginsToLoad, array( \Piwik\Plugin::getPluginNameFromBacktrace(debug_backtrace()), \Piwik\Plugin::getPluginNameFromNamespace($testCaseClass) - ); + )); foreach ($extraPlugins as $pluginName) { if (empty($pluginName)) { continue; diff --git a/tests/lib/screenshot-testing/support/test-environment.js b/tests/lib/screenshot-testing/support/test-environment.js index 4527b868d4..36807dac89 100644 --- a/tests/lib/screenshot-testing/support/test-environment.js +++ b/tests/lib/screenshot-testing/support/test-environment.js @@ -144,6 +144,10 @@ TestingEnvironment.prototype.setupFixture = function (fixtureClass, done) { droppedOnce = true; } + if (options['plugin']) { + args.push('--plugins=' + options['plugin']); + } + var self = this; this.executeConsoleCommand('tests:setup-fixture', args, function (code) { self.reload(); -- GitLab