Commit edbcbd96 authored by totten's avatar totten

CRM-16373 - CRM_Core_BAO_ConfigSetting - Fix enableComponent

parent 71dab367
......@@ -343,17 +343,11 @@ class CRM_Core_BAO_ConfigSetting {
* @param array $enabledComponents
*/
public static function setEnabledComponents($enabledComponents) {
$config = CRM_Core_Config::singleton();
// fix the config object
$config->enableComponents = $enabledComponents;
// fix the config object. update db.
Civi::settings()->set('enable_components', $enabledComponents);
// also force reset of component array
CRM_Core_Component::getEnabledComponents(TRUE);
// update DB
CRM_Core_BAO_Setting::setItem($enabledComponents,
CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components');
}
/**
......
......@@ -42,8 +42,6 @@ class CRM_Core_Component {
*/
const COMPONENT_INFO_CLASS = 'Info';
private static $_info = NULL;
static $_contactSubTypes = NULL;
/**
......@@ -52,8 +50,8 @@ class CRM_Core_Component {
* @return array|null
*/
private static function &_info($force = FALSE) {
if (self::$_info == NULL || $force) {
self::$_info = array();
if (!isset(Civi::$statics[__CLASS__]['info'])|| $force) {
Civi::$statics[__CLASS__]['info'] = array();
$c = array();
$config = CRM_Core_Config::singleton();
......@@ -61,12 +59,12 @@ class CRM_Core_Component {
foreach ($c as $name => $comp) {
if (in_array($name, $config->enableComponents)) {
self::$_info[$name] = $comp;
Civi::$statics[__CLASS__]['info'][$name] = $comp;
}
}
}
return self::$_info;
return Civi::$statics[__CLASS__]['info'];
}
/**
......@@ -90,10 +88,8 @@ class CRM_Core_Component {
* @throws Exception
*/
public static function &getComponents($force = FALSE) {
static $_cache = NULL;
if (!$_cache || $force) {
$_cache = array();
if (!isset(Civi::$statics[__CLASS__]['all']) || $force) {
Civi::$statics[__CLASS__]['all'] = array();
$cr = new CRM_Core_DAO_Component();
$cr->find(FALSE);
......@@ -104,12 +100,12 @@ class CRM_Core_Component {
if ($infoObject->info['name'] !== $cr->name) {
CRM_Core_Error::fatal("There is a discrepancy between name in component registry and in info file ({$cr->name}).");
}
$_cache[$cr->name] = $infoObject;
Civi::$statics[__CLASS__]['all'][$cr->name] = $infoObject;
unset($infoObject);
}
}
return $_cache;
return Civi::$statics[__CLASS__]['all'];
}
/**
......
......@@ -357,6 +357,7 @@ class Container {
);
if ($loadFromDB && $runtime->dsn) {
\CRM_Utils_Hook::singleton(TRUE);
\CRM_Extension_System::singleton(TRUE);
$c = new self();
......
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
require_once 'CiviTest/CiviUnitTestCase.php';
/**
* Class CiviReportTestCase
*/
class CRM_Core_BAO_ConfigSettingTest extends CiviUnitTestCase {
public function testToggleComponent() {
$origNames = array();
foreach (CRM_Core_Component::getEnabledComponents() as $c) {
$origNames[] = $c->name;
}
$this->assertTrue(!in_array('CiviCase', $origNames));
$enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
$this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
$newNames = array();
foreach (CRM_Core_Component::getEnabledComponents() as $c) {
$newNames[] = $c->name;
}
$this->assertTrue(in_array('CiviCase', $newNames));
$this->assertEquals(count($newNames), count($origNames) + 1);
}
}
......@@ -48,12 +48,6 @@ class CiviCaseTestCase extends CiviUnitTestCase {
public function setUp() {
parent::setUp();
/** @var $hooks \CRM_Utils_Hook_UnitTests */
$hooks = \CRM_Utils_Hook::singleton();
$hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
\CRM_Case_XMLRepository::singleton(TRUE);
\CRM_Case_XMLProcessor::flushStaticCaches();
// CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
//. Using XML was causing breakage as id numbers were changing over time
// & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
......@@ -113,6 +107,12 @@ class CiviCaseTestCase extends CiviUnitTestCase {
$enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
$this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
/** @var $hooks \CRM_Utils_Hook_UnitTests */
$hooks = \CRM_Utils_Hook::singleton();
$hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
\CRM_Case_XMLRepository::singleton(TRUE);
\CRM_Case_XMLProcessor::flushStaticCaches();
// create a logged in USER since the code references it for source_contact_id
$this->createLoggedInUser();
$session = CRM_Core_Session::singleton();
......
......@@ -410,7 +410,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
$config = CRM_Core_Config::singleton(TRUE, TRUE); // ugh, performance
// when running unit tests, use mockup user framework
$this->hookClass = CRM_Utils_Hook::singleton(TRUE);
$this->hookClass = CRM_Utils_Hook::singleton();
// Make sure the DB connection is setup properly
$config->userSystem->setMySQLTimeZone();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment