$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']);
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']}");
}
}
}
*/
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;
$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);
}
$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
*/
$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
*/
--- /dev/null
+<?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