From 07f66e0cbe9247e953e78d9b7f06519ff09385d1 Mon Sep 17 00:00:00 2001 From: mattab <matthieu.aubry@gmail.com> Date: Tue, 15 Oct 2013 13:11:31 +1300 Subject: [PATCH] Type hint for Singleton Enabling All plugins during tests --- core/API/Proxy.php | 1 + core/Config.php | 2 ++ core/DataTable/Manager.php | 1 + core/Db/Schema.php | 1 + core/EventDispatcher.php | 2 ++ core/FrontController.php | 1 + core/Log.php | 2 ++ core/Menu/MenuAbstract.php | 1 + core/Plugin/Manager.php | 22 ++++++++++--- core/Registry.php | 1 + plugins/CoreConsole/RunTests.php | 33 ++++++++++++------- plugins/ExamplePlugin/config/local.config.php | 10 ------ plugins/SitesManager/API.php | 1 + plugins/UserCountryMap/UserCountryMap.php | 4 --- tests/PHPUnit/IntegrationTestCase.php | 9 +++-- tests/PHPUnit/UITest.php | 2 +- tests/README.md | 8 +---- 17 files changed, 60 insertions(+), 41 deletions(-) delete mode 100644 plugins/ExamplePlugin/config/local.config.php diff --git a/core/API/Proxy.php b/core/API/Proxy.php index f504bdeb8f..bceac4556b 100644 --- a/core/API/Proxy.php +++ b/core/API/Proxy.php @@ -28,6 +28,7 @@ use ReflectionMethod; * * @package Piwik * @subpackage Piwik_API + * @method \Piwik\API\Proxy getInstance() */ class Proxy extends Singleton { diff --git a/core/Config.php b/core/Config.php index c7a5ad9d27..37213540d5 100644 --- a/core/Config.php +++ b/core/Config.php @@ -41,6 +41,8 @@ use Exception; * * @package Piwik * @subpackage Piwik_Config + * @method \Piwik\Config getInstance() + * */ class Config extends Singleton { diff --git a/core/DataTable/Manager.php b/core/DataTable/Manager.php index 0ae03ede89..3613f70ee8 100644 --- a/core/DataTable/Manager.php +++ b/core/DataTable/Manager.php @@ -23,6 +23,7 @@ use Piwik\Singleton; * * @package Piwik * @subpackage DataTable + * @method \Piwik\DataTable\Manager getInstance() */ class Manager extends Singleton { diff --git a/core/Db/Schema.php b/core/Db/Schema.php index 5ce1d55d62..9fc6283c58 100644 --- a/core/Db/Schema.php +++ b/core/Db/Schema.php @@ -20,6 +20,7 @@ use Piwik\Singleton; * * @package Piwik * @subpackage Piwik_Db + * @method \Piwik\Db\Schema getInstance() */ class Schema extends Singleton { diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php index c57cea990e..642aaee3f7 100644 --- a/core/EventDispatcher.php +++ b/core/EventDispatcher.php @@ -16,6 +16,8 @@ use Piwik\Plugin; /** * This class allows code to post events from anywhere in Piwik and for * plugins to associate callbacks to be executed when events are posted. + * + * @method \Piwik\EventDispatcher getInstance() */ class EventDispatcher extends Singleton { diff --git a/core/FrontController.php b/core/FrontController.php index 8b42c87a98..3cf537c9f0 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -26,6 +26,7 @@ use Piwik\Session; * * @package Piwik * @subpackage FrontController + * @method \Piwik\FrontController getInstance() */ class FrontController extends Singleton { diff --git a/core/Log.php b/core/Log.php index 23017acd59..7a82135859 100644 --- a/core/Log.php +++ b/core/Log.php @@ -25,6 +25,8 @@ use Piwik\Db; * * The logging utility can be configured by manipulating the INI config options in the * [log] section. + * + * @method \Piwik\Log getInstance() */ class Log extends Singleton { diff --git a/core/Menu/MenuAbstract.php b/core/Menu/MenuAbstract.php index b8f5b11e1a..0c71a79ee3 100644 --- a/core/Menu/MenuAbstract.php +++ b/core/Menu/MenuAbstract.php @@ -16,6 +16,7 @@ use Piwik\Singleton; /** * @package Piwik_Menu + * @method \Piwik\Menu\MenuAbstract getInstance() */ abstract class MenuAbstract extends Singleton { diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index fd461af5bb..69020f4785 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -25,6 +25,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/EventDispatcher.php'; /** * Plugin manager * + * @method \Piwik\Plugin\Manager getInstance() * @package Piwik * @subpackage Manager */ @@ -67,6 +68,11 @@ class Manager extends Singleton 'TreemapVisualization', // should be moved to marketplace ); + public function getCorePluginsDisabledByDefault() + { + return $this->corePluginsDisabledByDefault; + } + // If a plugin hooks onto at least an event starting with "Tracker.", we load the plugin during tracker const TRACKER_EVENT_PREFIX = 'Tracker.'; @@ -399,15 +405,22 @@ class Manager extends Singleton $pluginsBundledWithPiwik = $pluginsBundledWithPiwik['Plugins']; return (!empty($pluginsBundledWithPiwik) - && in_array($name, $pluginsBundledWithPiwik)) - || in_array($name, $this->corePluginsDisabledByDefault); + && in_array($name, $pluginsBundledWithPiwik)) + || in_array($name, $this->getCorePluginsDisabledByDefault()); } protected function isPluginThirdPartyAndBogus($pluginName) { $path = $this->getPluginsDirectory() . $pluginName; + + $bogusPlugins = array( + 'PluginMarketplace' //defines a plugin.json but 1.x Piwik plugin + ); + $isBogus = !$this->isPluginBundledWithCore($pluginName) - && !$this->isManifestFileFound($path); + || !$this->isManifestFileFound($path) + || in_array($pluginName, $bogusPlugins); + return $isBogus; } @@ -423,6 +436,7 @@ class Manager extends Singleton if (is_null($pluginsToLoad)) { $pluginsToLoad = array(); } + $pluginsToLoad = array_unique($pluginsToLoad); $this->pluginsToLoad = $pluginsToLoad; $this->reloadPlugins(); } @@ -462,8 +476,6 @@ class Manager extends Singleton /** * Execute postLoad() hook for loaded plugins - * - * @see Piwik_Plugin::postLoad() */ public function postLoadPlugins() { diff --git a/core/Registry.php b/core/Registry.php index 88ecc1ce95..12ed1d963c 100644 --- a/core/Registry.php +++ b/core/Registry.php @@ -14,6 +14,7 @@ namespace Piwik; * Registry class. * * @package Piwik + * @method \Piwik\Registry getInstance() */ class Registry extends Singleton { diff --git a/plugins/CoreConsole/RunTests.php b/plugins/CoreConsole/RunTests.php index 4176ab1dcc..7250993e8d 100644 --- a/plugins/CoreConsole/RunTests.php +++ b/plugins/CoreConsole/RunTests.php @@ -22,10 +22,15 @@ use Symfony\Component\Console\Output\OutputInterface; */ class RunTests extends Command { + protected function getTestsGroups() + { + return array('Core', 'Plugins', 'Integration'); + } + protected function configure() { $this->setName('tests:run'); - $this->setDescription('Run Piwik PHPUnit tests'); + $this->setDescription('Run Piwik PHPUnit tests one group after the other'); $this->addArgument('group', InputArgument::OPTIONAL, 'Run only a specific test group. Separate multiple groups by comma, for instance core,integration', ''); $this->addOption('options', 'o', InputOption::VALUE_OPTIONAL, 'All options will be forwarded to phpunit', ''); } @@ -33,17 +38,23 @@ class RunTests extends Command protected function execute(InputInterface $input, OutputInterface $output) { $options = $input->getOption('options'); - $group = $input->getArgument('group'); + $groups = $input->getArgument('group'); + $groups = explode(",", $groups); + $groups = array_map('ucfirst', $groups); + $groups = array_filter('strlen', $groups); + if(empty($groups)) { + $groups = $this->getTestsGroups(); - if (!empty($group)) { - $groups = explode(',', $group); - $groups = array_map('ucfirst', $groups); - $options = '--group ' . implode(',', $groups) . ' ' . $options; + if(\UITest::isPhantomJsAvailable()) { + $groups[] = 'UI'; + } + } + foreach($groups as $group) { + $params = '--group ' . $group . ' ' . $options; + $cmd = sprintf('cd %s/tests/PHPUnit && phpunit %s', PIWIK_DOCUMENT_ROOT, $params); + $output->writeln('Executing command: ' . $cmd); + passthru($cmd); + $output->writeln(); } - - $cmd = sprintf('cd %s/tests/PHPUnit && phpunit %s', PIWIK_DOCUMENT_ROOT, $options); - - $output->writeln('Executing command: ' . $cmd); - passthru($cmd); } } \ No newline at end of file diff --git a/plugins/ExamplePlugin/config/local.config.php b/plugins/ExamplePlugin/config/local.config.php deleted file mode 100644 index cf846146e4..0000000000 --- a/plugins/ExamplePlugin/config/local.config.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php -return array ( - 0 => 1, - 1 => 'mixed', - 2 => - array ( - 0 => 'a', - ), - 'b' => 'c', -); diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php index 7387789568..612d6de6f1 100644 --- a/plugins/SitesManager/API.php +++ b/plugins/SitesManager/API.php @@ -42,6 +42,7 @@ use Piwik\UrlHelper; * The existing values can be fetched via "getExcludedIpsGlobal" and "getExcludedQueryParametersGlobal". * See also the documentation about <a href='http://piwik.org/docs/manage-websites/' target='_blank'>Managing Websites</a> in Piwik. * @package SitesManager + * @method \Piwik\Plugins\SitesManager\API getInstance() */ class API extends \Piwik\Plugin\API { diff --git a/plugins/UserCountryMap/UserCountryMap.php b/plugins/UserCountryMap/UserCountryMap.php index 1fd94f98dd..c295c48a3d 100644 --- a/plugins/UserCountryMap/UserCountryMap.php +++ b/plugins/UserCountryMap/UserCountryMap.php @@ -17,7 +17,6 @@ use Piwik\Version; use Piwik\WidgetsList; /** - * * @package UserCountryMap */ class UserCountryMap extends \Piwik\Plugin @@ -50,9 +49,6 @@ class UserCountryMap extends \Piwik\Plugin $out .= FrontController::getInstance()->fetchDispatch('UserCountryMap', 'visitorMap'); } - /** - * @see Piwik_Plugin::getListHooksRegistered - */ public function getListHooksRegistered() { $hooks = array( diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index ae83c70bfc..867ee1e834 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -101,9 +101,12 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase public static function loadAllPlugins() { $pluginsManager = \Piwik\Plugin\Manager::getInstance(); - $pluginsToLoad = Config::getInstance()->Plugins['Plugins']; - $pluginsToLoad[] = 'DevicesDetection'; - + + $pluginsToLoad = array_merge( + $pluginsManager->readPluginsDirectory(), + $pluginsManager->getCorePluginsDisabledByDefault(), + Config::getInstance()->Plugins['Plugins'] + ); $pluginsManager->loadPlugins($pluginsToLoad); } diff --git a/tests/PHPUnit/UITest.php b/tests/PHPUnit/UITest.php index 87eee4114f..e073711a55 100644 --- a/tests/PHPUnit/UITest.php +++ b/tests/PHPUnit/UITest.php @@ -218,7 +218,7 @@ Screenshot diff: $diffPath\n"; return self::isProgramAvailable('slimerjs'); } - private static function isPhantomJsAvailable() + public static function isPhantomJsAvailable() { return self::isProgramAvailable('phantomjs'); } diff --git a/tests/README.md b/tests/README.md index 25c26207e0..cc68fd804f 100644 --- a/tests/README.md +++ b/tests/README.md @@ -154,16 +154,10 @@ You can import data over several days in Piwik: 5. You can then archive the reports with: - $ php5 /home/piwik/misc/cron/archive.php --url=http://localhost/path/ + $ php5 /home/piwik/misc/cron/archive.php --url=http://localhost/path/ You should now have some interesting data to test with in November 2012! -## Selenium Webdriver tests - -We would like to add Webdriver selenium testing for the following: installation, auto update from 1.0, initial user login. - -Task is tracked in: http://dev.piwik.org/trac/ticket/2935 - ## Scheduled Reports Tests Piwik scheduled reports (HTML, PDF & SMS) are part of the integration test suite. -- GitLab