Skip to content
Snippets Groups Projects
Commit 544ea0e6 authored by Kurund Jalmi's avatar Kurund Jalmi
Browse files

Merge pull request #2285 from eileenmcnaughton/extra-test

Extra test, a couple of tidy-ups
parents a85fdac0 ee7b49c4
Branches
Tags
No related merge requests found
......@@ -511,7 +511,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
$fields = civicrm_api('setting','getfields', $getFieldsParams);
$invalidParams = (array_diff_key($settingParams, $fields['values']));
if (!empty($invalidParams)) {
throw new API_Exception(implode(',', $invalidParams) . " not valid settings");
throw new api_Exception(implode(',', $invalidParams) . " not valid settings");
}
if (!empty($settingParams)) {
$filteredFields = array_intersect_key($settingParams, $fields['values']);
......@@ -539,7 +539,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
else {
list($class,$fn) = explode('::',$fieldSpec['validate_callback']);
if (!$class::$fn($value,$fieldSpec)) {
throw new API_Exception("validation failed for {$fieldSpec['name']} = $value based on callback {$fieldSpec['validate_callback']}");
throw new api_Exception("validation failed for {$fieldSpec['name']} = $value based on callback {$fieldSpec['validate_callback']}");
}
}
}
......@@ -552,7 +552,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
*/
static function validateBoolSetting(&$value, $fieldSpec) {
if (!CRM_Utils_Rule::boolean($value)) {
throw new API_Exception("Boolean value required for {$fieldSpec['name']}");
throw new api_Exception("Boolean value required for {$fieldSpec['name']}");
}
if (!$value) {
$value = 0;
......@@ -630,6 +630,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
$cacheString .= "_{$filterField}_{$filterString}";
}
$cached = 1;
// the caching into 'All' seems to be a duplicate of caching to
// settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook
$settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Specs', $cacheString, $componentID);
if ($settingsMetadata === NULL) {
$settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Spec', 'All', $componentID);
......
......@@ -105,7 +105,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
//get the log start date.
//it is set during renewal of membership.
$logStartDate = CRM_Utils_array::value('log_start_date', $params);
$logStartDate = CRM_Utils_Array::value('log_start_date', $params);
$logStartDate = ($logStartDate) ? CRM_Utils_Date::isoToMysql($logStartDate) : CRM_Utils_Date::isoToMysql($membership->start_date);
$values = self::getStatusANDTypeValues($membership->id);
......@@ -235,6 +235,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
!CRM_Utils_Array::value('skipStatusCal', $params)
) {
$dates = array('start_date', 'end_date', 'join_date');
$start_date = $end_date = $join_date = NULL; // declare these out of courtesy as IDEs don't pick up the setting of them below
foreach ($dates as $date) {
$$date = $params[$date] = CRM_Utils_Date::processDate(CRM_Utils_Array::value($date, $params), NULL, TRUE, 'Ymd');
}
......@@ -333,6 +334,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
CRM_Utils_Array::value('createActivity', $params)
) {
if (CRM_Utils_Array::value('membership', $ids)) {
$data = array();
CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_Membership',
'id',
$membership->id,
......@@ -966,7 +968,7 @@ INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_ty
if ($onlySameParentOrg && $memType) {
// require the same parent org as the $memType
$params = array('id' => $memType);
$defaults = array();
$defaults = $membershipType = array();
if (CRM_Member_BAO_MembershipType::retrieve($params, $membershipType)) {
$memberTypesSameParentOrg = CRM_Member_BAO_MembershipType::getMembershipTypesByOrg($membershipType['member_of_contact_id']);
$memberTypesSameParentOrgList = implode(',', array_keys($memberTypesSameParentOrg));
......@@ -2400,7 +2402,7 @@ INNER JOIN civicrm_contact contact ON ( contact.id = membership.contact_id AND
function processPriceSet($membershipId, $lineItem) {
//FIXME : need to move this too
if (!$membershipId || !is_array($lineItem)
|| CRM_Utils_system::isNull($lineItem)
|| CRM_Utils_System::isNull($lineItem)
) {
return;
}
......
......@@ -84,14 +84,25 @@ class api_v3_SettingTest extends CiviUnitTestCase {
}
$this->_domainID3 = $result['id'];
$this->_currentDomain = CRM_Core_Config::domainID();
$this->hookClass = CRM_Utils_Hook::singleton();
}
function tearDown() {
CRM_Utils_Hook::singleton()->reset();
parent::tearDown();
$this->callAPISuccess('system','flush', array());
$this->quickCleanup(array('civicrm_domain'));
}
/**
* Set additional settings into metadata (implements hook)
* @param array $metaDataFolders
*/
function setExtensionMetadata(&$metaDataFolders) {
global $civicrm_root;
$metaDataFolders[] = $civicrm_root . '/tests/phpunit/api/v3/settings';
}
/**
/**
* check getfields works
*/
......@@ -361,6 +372,22 @@ class api_v3_SettingTest extends CiviUnitTestCase {
$result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSettingCurrentDomain');
$this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']);
}
/**
* Check that setting defined in extension can be retrieved
*/
function testGetExtensionSetting() {
$this->hookClass->setHook('civicrm_alterSettingsFolders', array($this, 'setExtensionMetadata'));
$data = NULL;
// the caching of data to all duplicates the caching of data to the empty string
CRM_Core_BAO_Cache::setItem($data, 'CiviCRM setting Spec', 'All');
CRM_Core_BAO_Cache::setItem($data, 'CiviCRM setting Specs', 'settingsMetadata__');
$fields = $this->callAPISuccess('setting', 'getfields', array('filters' => array('group_name' => 'Test Settings')));
$this->assertArrayHasKey('test_key', $fields['values']);
$this->callAPISuccess('setting', 'create', array('test_key' => 'keyset'));
$result = $this->callAPISuccess('setting', 'getvalue', array('name' => 'test_key', 'group' => 'Test Settings'));
$this->assertEquals('keyset', $result);
}
/**
* setting api should set & fetch settings stored in config as well as those in settings table
*/
......
<?php
return array(
'test_key' => array(
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_key',
'type' => 'String',
'add' => '4.4',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Test Key',
'title' => 'Test Key',
'help_text' => '',
'html_type' => 'Text',
'quick_form_type' => 'Element',
),
'test_secret' => array(
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_secret',
'type' => 'String',
'add' => '4.4',
'is_domain' => 1,
'is_contact' => 0,
'description' => 'Test Secret',
'title' => 'Test Secret',
'help_text' => '',
'html_type' => 'Text',
'quick_form_type' => 'Element',
),
'test_public_certificate' => array(
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_public_certificate',
'type' => 'Text',
'add' => '4.4',
'is_domain' => 1,
'is_contact' => 0,
'title' => 'Test Public Certificate Path',
'description' => 'Enter the full path to your public Certificate',
'help_text' => '',
'html_type' => 'Text',
'html_attributes' => array(
'size' => 50,
),
'quick_form_type' => 'Element',
),
'test_private_key' => array(
'group_name' => 'Test Settings',
'group' => 'test',
'name' => 'test_private_key',
'type' => 'String',
'add' => '4.4',
'is_domain' => 1,
'is_contact' => 0,
'title' => 'Test Private Key Path',
'description' => 'Enter the full path to your private Key',
'help_text' => '',
'html_type' => 'Text',
'quick_form_type' => 'Element',
),
);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment