From: Tim Otten Date: Mon, 11 May 2015 20:44:10 +0000 (-0700) Subject: CRM-16387 - bin/cli.php - Allow calls against the test database X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=dc1e9be866bedb017cf28beafbe5cdf39d6457a5;p=civicrm-core.git CRM-16387 - bin/cli.php - Allow calls against the test database Example: ```bash env CIVICRM_SETTINGS=/path/to/civicrm/tests/phpunit/CiviTest/civicrm.settings.cli.php \ php bin/cli.php -e Contact -a getfields --output ``` This will assist in creating tests for multi-process cron behavior. --- diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 112a9e1a0a..2c64ef560b 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -662,11 +662,17 @@ class CRM_Utils_System { * We typically call authenticate only when we need to bootstrap the CMS * directly via Civi and hence bypass the normal CMS auth and bootstrap * process typically done in CLI and cron scripts. See: CRM-12648 + * + * Q: Can we move this to the userSystem class so that it can be tuned + * per-CMS? For example, when dealing with UnitTests UF, there's no + * userFrameworkDSN. */ $session = CRM_Core_Session::singleton(); $session->set('civicrmInitSession', TRUE); - $dbDrupal = DB::connect($config->userFrameworkDSN); + if ($config->userFrameworkDSN) { + $dbDrupal = DB::connect($config->userFrameworkDSN); + } return $config->userSystem->authenticate($name, $password, $loadCMSBootstrap, $realPath); } diff --git a/CRM/Utils/System/UnitTests.php b/CRM/Utils/System/UnitTests.php index d57901a28e..f2014b027f 100644 --- a/CRM/Utils/System/UnitTests.php +++ b/CRM/Utils/System/UnitTests.php @@ -52,6 +52,20 @@ class CRM_Utils_System_UnitTests extends CRM_Utils_System_Base { return $retVal; } + /** + * Bootstrap the phony CMS. + * + * @param string $name + * Optional username for login. + * @param string $pass + * Optional password for login. + * + * @return bool + */ + public function loadBootStrap($name = NULL, $pass = NULL) { + return TRUE; + } + /** * @inheritDoc */ diff --git a/bin/cli.class.php b/bin/cli.class.php index be58c1c654..510d15e0c2 100644 --- a/bin/cli.class.php +++ b/bin/cli.class.php @@ -216,7 +216,12 @@ class civicrm_cli { $civicrm_root = dirname(__DIR__); chdir($civicrm_root); - require_once 'civicrm.config.php'; + if (getenv('CIVICRM_SETTINGS')) { + require_once getenv('CIVICRM_SETTINGS'); + } + else { + require_once 'civicrm.config.php'; + } // autoload if (!class_exists('CRM_Core_ClassLoader')) { require_once $civicrm_root . '/CRM/Core/ClassLoader.php'; diff --git a/tests/phpunit/CiviTest/civicrm.settings.cli.php b/tests/phpunit/CiviTest/civicrm.settings.cli.php new file mode 100644 index 0000000000..c9ea113650 --- /dev/null +++ b/tests/phpunit/CiviTest/civicrm.settings.cli.php @@ -0,0 +1,14 @@ +register(); + +define('CIVICRM_SETTINGS_PATH', __DIR__ . '/civicrm.settings.dist.php'); +define('CIVICRM_SETTINGS_LOCAL_PATH', __DIR__ . '/civicrm.settings.local.php'); + +if (file_exists(CIVICRM_SETTINGS_LOCAL_PATH)) { + require_once CIVICRM_SETTINGS_LOCAL_PATH; +} +require_once CIVICRM_SETTINGS_PATH;