Skip to content

Commit

Permalink
CRM-17860 - civicrm.settings.php.template - Load test DB if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Jan 18, 2017
1 parent c829601 commit 30ef9dd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
19 changes: 19 additions & 0 deletions templates/CRM/common/civicrm.settings.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@
* CiviCRM Configuration File.
*/

/**
* If ENV[CIVICRM_UF]==UnitTests, switch to alternate config.
*/
if (getenv('CIVICRM_UF') === 'UnitTests') {
define('CIVICRM_UF', 'UnitTests');
$_CIVI_TEST_DIR = rtrim('%%crmRoot%%', '/') . '/tests/phpunit/CiviTest';
if (!defined('CIVICRM_SETTINGS_LOCAL_PATH')) {
define('CIVICRM_SETTINGS_LOCAL_PATH', $_CIVI_TEST_DIR . '/civicrm.settings.local.php');
if (file_exists(CIVICRM_SETTINGS_LOCAL_PATH)) {
require_once CIVICRM_SETTINGS_LOCAL_PATH;
}
}

if (!defined('CIVICRM_SETTINGS_PATH')) {
define('CIVICRM_SETTINGS_PATH', $_CIVI_TEST_DIR . '/civicrm.settings.dist.php');
}
require_once $_CIVI_TEST_DIR . '/civicrm.settings.dist.php';
}

/**
* Content Management System (CMS) Host:
*
Expand Down
15 changes: 10 additions & 5 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@
/**
* Include configuration
*/
define('CIVICRM_SETTINGS_PATH', __DIR__ . '/civicrm.settings.dist.php');
define('CIVICRM_SETTINGS_LOCAL_PATH', __DIR__ . '/civicrm.settings.local.php');
if (!defined('CIVICRM_SETTINGS_LOCAL_PATH')) {
define('CIVICRM_SETTINGS_LOCAL_PATH', __DIR__ . '/civicrm.settings.local.php');
if (file_exists(CIVICRM_SETTINGS_LOCAL_PATH)) {
require_once CIVICRM_SETTINGS_LOCAL_PATH;
}
}

if (file_exists(CIVICRM_SETTINGS_LOCAL_PATH)) {
require_once CIVICRM_SETTINGS_LOCAL_PATH;
if (!defined('CIVICRM_SETTINGS_PATH')) {
define('CIVICRM_SETTINGS_PATH', __DIR__ . '/civicrm.settings.dist.php');
require_once CIVICRM_SETTINGS_PATH;
}
require_once CIVICRM_SETTINGS_PATH;

/**
* Include class definitions
*/
Expand Down
25 changes: 13 additions & 12 deletions tests/phpunit/CiviTest/civicrm.settings.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,30 @@
}
}


require_once "DB.php";
$dsninfo = DB::parseDSN(CIVICRM_DSN);

$GLOBALS['mysql_host'] = $dsninfo['hostspec'];
$GLOBALS['mysql_port'] = @$dsninfo['port'];
$GLOBALS['mysql_user'] = $dsninfo['username'];
$GLOBALS['mysql_pass'] = $dsninfo['password'];
$GLOBALS['mysql_db'] = $dsninfo['database'];

/**
* Content Management System (CMS) Host:
*
* CiviCRM can be hosted in either Drupal, Joomla or WordPress.
*/
define('CIVICRM_UF', 'UnitTests');


global $civicrm_root;
if (empty($civicrm_root)) {
$civicrm_root = dirname(dirname(dirname(dirname(__FILE__))));
}
#$civicrm_root = '/var/www/drupal7.dev.civicrm.org/public/sites/devel.drupal7.tests.dev.civicrm.org/modules/civicrm';

$tests_dir = $civicrm_root . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'phpunit';
$civi_pkgs_dir = $civicrm_root . DIRECTORY_SEPARATOR . 'packages';
ini_set('safe_mode', 0);
ini_set('include_path', $civicrm_root . PATH_SEPARATOR . $tests_dir . PATH_SEPARATOR . $civi_pkgs_dir . PATH_SEPARATOR . ini_get('include_path'));

require_once 'DB.php';
$dsninfo = DB::parseDSN(CIVICRM_DSN);
$GLOBALS['mysql_host'] = $dsninfo['hostspec'];
$GLOBALS['mysql_port'] = @$dsninfo['port'];
$GLOBALS['mysql_user'] = $dsninfo['username'];
$GLOBALS['mysql_pass'] = $dsninfo['password'];
$GLOBALS['mysql_db'] = $dsninfo['database'];

// set this to a temporary directory. it defaults to /tmp/civi on linux
//define( 'CIVICRM_TEMPLATE_COMPILEDIR', 'the/absolute/path/' );
Expand Down

0 comments on commit 30ef9dd

Please sign in to comment.