Skip to content
Snippets Groups Projects
Commit 89ab5601 authored by pratik.joshi's avatar pratik.joshi
Browse files

CRM-13814

parent be6227f6
Branches
No related tags found
No related merge requests found
......@@ -195,8 +195,19 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue {
$p = array(1 => array($params['option_group_id'], 'Integer'));
CRM_Core_DAO::executeQuery($query, $p);
}
// CRM-13814 : evalute option group id
if (!array_key_exists('option_group_id', $params) && !empty($ids['optionValue'])) {
$groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
$ids['optionValue'], 'option_group_id', 'id'
);
}
else {
$groupId = $params['option_group_id'];
}
$groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
$params['option_group_id'], 'name', 'id'
$groupId, 'name', 'id'
);
if (in_array($groupName, CRM_Core_OptionGroup::$_domainIDGroups)) {
$optionValue->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
......
......@@ -38,9 +38,20 @@ function civicrm_api3_option_value_get($params) {
* @access public
*/
function civicrm_api3_option_value_create($params) {
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $params['option_group_id']));
// CRM-13814 : evalute option group id
// option group id would be passed in case of adding a new option value record
if (!empty($params['id']) && !array_key_exists('option_group_id', $params)) {
$groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
$params['id'], 'option_group_id', 'id'
);
}
else {
$groupId = $params['option_group_id'];
}
civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $groupId));
return $result;
}
......
......@@ -67,4 +67,4 @@ function option_value_getsingle_expectedresult(){
*
* API Standards documentation:
* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
*/
\ No newline at end of file
*/
......@@ -278,5 +278,43 @@ class api_v3_OptionValueTest extends CiviUnitTestCase {
$fields = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
$this->assertFalse(in_array($newOption, $fields['values']));
}
}
/*
* update option value with 'id' paramter and the value to update
* and not passing option group id
*/
public function testUpdateOptionValueNoGroupId() {
// create a option group
$og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group', 'is_active' => 1));
// create a option value
$ov = $this->callAPISuccess('option_value', 'create',
array('option_group_id' => $og['id'], 'label' => 'test option value')
);
// update option value without 'option_group_id'
$res = $this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'is_active' => 0));
$val = $this->callAPISuccess('option_value', 'getvalue', array(
'id' => $ov['id'], 'return' => 'is_active',
));
$this->assertEquals($val, 0, "update with no group id is not proper" . __LINE__);
}
/*
* update option value with 'id' paramter and the value to update
* and as well as option group id
*/
public function testUpdateOptionValueWithGroupId() {
// create a option group
$og = $this->callAPISuccess('option_group', 'create', array('name' => 'our test Option Group for with group id', 'is_active' => 1));
// create a option value
$ov = $this->callAPISuccess('option_value', 'create',
array('option_group_id' => $og['id'], 'label' => 'test option value')
);
// update option value without 'option_group_id'
$this->callAPISuccess('option_value', 'create', array('id' => $ov['id'], 'option_group_id' => $og['id'], 'is_active' => 0));
$val = $this->callAPISuccess('option_value', 'getvalue', array(
'id' => $ov['id'], 'return' => 'is_active',
));
$this->assertEquals($val, 0, "update with group id is not proper " . __LINE__);
}
}
\ 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