From a45841622c44cb2e2c64ae3aea2d982ed39baabd Mon Sep 17 00:00:00 2001 From: Edsel Date: Thu, 21 Jul 2016 16:37:02 +0530 Subject: [PATCH] CRM-18231 Fixed unit and api tests ---------------------------------------- * CRM-18231: Support safe migration from production to non-production instances https://issues.civicrm.org/jira/browse/CRM-18231 --- CRM/Admin/Form/Setting.php | 2 +- tests/phpunit/CRM/Core/BAO/SettingTest.php | 24 +++++-------------- .../Admin/Form/Setting/DebuggingTest.php | 9 +++---- tests/phpunit/api/v3/SettingTest.php | 23 ++++-------------- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/CRM/Admin/Form/Setting.php b/CRM/Admin/Form/Setting.php index 78afc79f369c..dc2a52b4c1a6 100644 --- a/CRM/Admin/Form/Setting.php +++ b/CRM/Admin/Form/Setting.php @@ -136,7 +136,7 @@ public function buildQuickForm() { } elseif ($add == 'addSelect') { $element = $this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props)); - if (CRM_Core_BAO_Setting::isEnvironmentSet($setting)) { + if (defined('CIVICRM_ENVIRONMENT')) { $element->freeze(); CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info'); } diff --git a/tests/phpunit/CRM/Core/BAO/SettingTest.php b/tests/phpunit/CRM/Core/BAO/SettingTest.php index 9ad7b7cc1b2b..a58e1b2a7895 100644 --- a/tests/phpunit/CRM/Core/BAO/SettingTest.php +++ b/tests/phpunit/CRM/Core/BAO/SettingTest.php @@ -185,25 +185,13 @@ public static function _testOnChange_onChangeExample($oldValue, $newValue, $meta * */ public function testSetCivicrmEnvironment() { - CRM_Core_BAO_Setting::setItem(TRUE, CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'isProductionEnvironment'); - $values = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'isProductionEnvironment'); - $this->assertEquals(TRUE, $values); + CRM_Core_BAO_Setting::setItem('Staging', CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'environment'); + $values = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'environment'); + $this->assertEquals('Staging', $values); - global $civicrm_setting; - $civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['isProductionEnvironment'] = FALSE; - Civi::service('settings_manager')->useMandatory(); - $values = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'isProductionEnvironment'); - $this->assertEquals(FALSE, $values); - - // check that attempt to override value set in civicrm.settings.php raises error - try { - CRM_Core_BAO_Setting::setItem(TRUE, CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME, 'isProductionEnvironment'); - $this->fail("Missed expected exception"); - } - catch (Exception $e) { - $this->assertEquals(ts('CiviCRM Environment already set in civicrm.settings.php!'), $e->getMessage()); - } - unset($civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['isProductionEnvironment']); + define('CIVICRM_ENVIRONMENT', 'Development'); + $environment = CRM_Core_Config::environment(); + $this->assertEquals('Development', $environment); } } diff --git a/tests/phpunit/WebTest/Admin/Form/Setting/DebuggingTest.php b/tests/phpunit/WebTest/Admin/Form/Setting/DebuggingTest.php index d050aa8daea7..d1f2ca191a5b 100644 --- a/tests/phpunit/WebTest/Admin/Form/Setting/DebuggingTest.php +++ b/tests/phpunit/WebTest/Admin/Form/Setting/DebuggingTest.php @@ -38,7 +38,7 @@ protected function setUp() { public function testSetCivicrmEnvironment() { $this->webtestLogin(); $this->openCiviPage('admin/setting/debug', 'reset=1'); - $this->click('xpath=//tr[@class="crm-debugging-form-block-isProductionEnvironment"]/td[2]/label[contains(text(), "No")]'); + $this->select('environment', 'Staging'); $this->click('_qf_Debugging_next-top'); $this->waitForPageToLoad($this->getTimeoutMsec()); @@ -48,11 +48,8 @@ public function testSetCivicrmEnvironment() { catch (PHPUnit_Framework_AssertionFailedError$e) { array_push($this->verificationErrors, $e->toString()); } - global $civicrm_setting; - $civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['isProductionEnvironment'] = TRUE; - $this->openCiviPage('admin/setting/debug', 'reset=1'); - $disabled = $this->getAttribute("xpath=//tr[@class='crm-debugging-form-block-isProductionEnvironment']/td[2]/input[1]@disabled"); - $this->assertEquals(1, $disabled); + $envi = $this->getValue("environment"); + $this->assertEquals('Staging', $envi); } } diff --git a/tests/phpunit/api/v3/SettingTest.php b/tests/phpunit/api/v3/SettingTest.php index fe93e7f56eed..a032cbe631ac 100644 --- a/tests/phpunit/api/v3/SettingTest.php +++ b/tests/phpunit/api/v3/SettingTest.php @@ -554,34 +554,21 @@ public function testDefaults() { */ public function testSetCivicrmEnvironment() { $params = array( - 'isProductionEnvironment' => TRUE, + 'environment' => 'Staging', ); $result = $this->callAPISuccess('Setting', 'create', $params); $params = array( - 'name' => 'isProductionEnvironment', + 'name' => 'environment', 'group' => 'Developer Preferences', ); $result = $this->callAPISuccess('Setting', 'getvalue', $params); - $this->assertEquals(TRUE, $result); + $this->assertEquals('Staging', $result); global $civicrm_setting; - $civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['isProductionEnvironment'] = FALSE; + $civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['environment'] = 'Production'; Civi::service('settings_manager')->useMandatory(); $result = $this->callAPISuccess('Setting', 'getvalue', $params); - $this->assertEquals(FALSE, $result); - - // check that attempt to override value set in civicrm.settings.php raises error - $params = array( - 'isProductionEnvironment' => TRUE, - ); - $result = $this->callAPIFailure('Setting', 'create', $params); - $params = array( - 'name' => 'isProductionEnvironment', - 'group' => 'Developer Preferences', - ); - $result = $this->callAPISuccess('Setting', 'getvalue', $params); - $this->assertEquals(FALSE, $result); - unset($civicrm_setting[CRM_Core_BAO_Setting::DEVELOPER_PREFERENCES_NAME]['isProductionEnvironment']); + $this->assertEquals('Production', $result); } }