<?php
function civicrm_api3_option_group_get($params) {
-
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
* In case of updating existing survey, id of that particular survey must
* be in $params array.
*
- * @param array $params (referance) Associative array of property
- * name/value pairs to insert in new 'survey'
+ * @param array $params (reference) Associative array of property
+ * name/value pairs to insert in new 'survey'
*
* @return array survey array
*
* @access public
*/
function civicrm_api3_option_group_create($params) {
-
- $ids = array();
- $bao = CRM_Core_BAO_OptionGroup::add($params, $ids);
-
- if (is_null($bao)) {
- return civicrm_api3_create_error('Entity not created');
- }
- else {
- $values = array();
- _civicrm_api3_object_to_array($bao, $values[$bao->id]);
- return civicrm_api3_create_success($values, $params, 'option_group', 'create', $bao);
- }
+ return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
function _civicrm_api3_option_group_create_spec(&$params) {
$params['name']['api.unique'] = 1;
}
+
+/**
+ * delete an existing Option Group
+ *
+ * This method is used to delete any existing Option Group. id of the group
+ * to be deleted is required field in $params array
+ *
+ * @param array $params (reference) array containing id of the group
+ * to be deleted
+ *
+ * @return array (reference) returns flag true if successfull, error
+ * message otherwise
+ * {@getfields OptionGroup_delete}
+ * @access public
+ */
+function civicrm_api3_option_group_delete($params) {
+ return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
--- /dev/null
+<?php
+
+/*
+
+ */
+function option_group_delete_example(){
+$params = array(
+ 'id' => 89,
+);
+
+ $result = civicrm_api( 'option_group','delete',$params );
+
+ return $result;
+}
+
+/*
+ * Function returns array of result expected from previous function
+ */
+function option_group_delete_expectedresult(){
+
+ $expectedResult = array(
+ 'is_error' => 0,
+ 'version' => 3,
+ 'count' => 1,
+ 'values' => true,
+ 'xdebug' => array(
+ 'peakMemory' => 35887080,
+ 'memory' => 33229704,
+ 'timeIndex' => '51.428074836731',
+ ),
+);
+
+ return $expectedResult ;
+}
+
+
+/*
+* This example has been generated from the API test suite. The test that created it is called
+*
+* testDeleteOptionGroup and can be found in
+* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/OptionGroupTest.php
+*
+* You can see the outcome of the API tests at
+* http://tests.dev.civicrm.org/trunk/results-api_v3
+*
+* To Learn about the API read
+* http://book.civicrm.org/developer/current/techniques/api/
+*
+* and review the wiki at
+* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
+*
+* Read more about testing here
+* http://wiki.civicrm.org/confluence/display/CRM/Testing
+*
+* API Standards documentation:
+* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
+*/
\ No newline at end of file
class api_v3_OptionGroupTest extends CiviUnitTestCase {
protected $_apiversion;
public $_eNoticeCompliant = TRUE;
+ protected $_entity = 'OptionGroup';
function setUp() {
$this->_apiversion = 3;
parent::setUp();
+
+ $this->_params = array(
+ 'name' => 'our test Option Group',
+ 'is_reserved' => 1,
+ 'is_active' => 1,
+ );
}
function tearDown() {}
*/
public function testGetOptionGroupGetFields() {
- $result = civicrm_api('option_group', 'getfields', array('version' => 3));
+ $result = $this->callAPISuccess('option_group', 'getfields', array());
$this->assertFalse(empty($result['values']), 'In line ' . __LINE__);
}
public function testGetOptionGroupGetFieldsCreateAction() {
- $result = civicrm_api('option_group', 'getfields', array('action' => 'create', 'version' => 3));
+ $result = $this->callAPISuccess('option_group', 'getfields', array('action' => 'create', 'version' => 3));
$this->assertFalse(empty($result['values']), 'In line ' . __LINE__);
$this->assertEquals($result['values']['name']['api.unique'], 1);
}
public function testGetOptionGroupByID() {
- $result = civicrm_api('option_group', 'get', array('id' => 1, 'version' => 3));
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('option_group', 'get', array('id' => 1, 'version' => 3));
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertEquals(1, $result['id'], 'In line ' . __LINE__);
}
public function testGetOptionGroupByName() {
$params = array('name' => 'preferred_communication_method', 'version' => 3);
- $result = civicrm_api('option_group', 'get', $params);
- $this->documentMe($params, $result, __FUNCTION__, __FILE__);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('option_group', 'get', $params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
$this->assertEquals(1, $result['id'], 'In line ' . __LINE__);
}
public function testGetOptionGroup() {
- $result = civicrm_api('option_group', 'get', array('version' => 3));
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('option_group', 'get', array('version' => 3));
$this->assertGreaterThan(1, $result['count'], 'In line ' . __LINE__);
}
public function testGetOptionDoesNotExist() {
- $result = civicrm_api('option_group', 'get', array('name' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB', 'version' => 3));
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPISuccess('option_group', 'get', array('name' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB', 'version' => 3));
$this->assertEquals(0, $result['count'], 'In line ' . __LINE__);
}
public function testGetOptionCreateSuccess() {
$params = array('version' => $this->_apiversion, 'sequential' => 1, 'name' => 'civicrm_event.amount.560', 'is_reserved' => 1, 'is_active' => 1, 'api.OptionValue.create' => array('label' => 'workshop', 'value' => 35, 'is_default' => 1, 'is_active' => 1, 'format.only_id' => 1));
- $result = civicrm_api('OptionGroup', 'create', $params);
- $this->documentMe($params, $result, __FUNCTION__, __FILE__);
- $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__);
+ $result = $this->callAPIAndDocument('OptionGroup', 'create', $params, __FUNCTION__, __FILE__);
$this->assertEquals('civicrm_event.amount.560', $result['values'][0]['name'], 'In line ' . __LINE__);
$this->assertTrue(is_integer($result['values'][0]['api.OptionValue.create']));
$this->assertGreaterThan(0, $result['values'][0]['api.OptionValue.create']);
- civicrm_api('OptionGroup', 'delete', array('version' => 3, 'id' => $result['id']));
+ $this->callAPISuccess('OptionGroup', 'delete', array('version' => 3, 'id' => $result['id']));
}
/*
* Test the error message when a failure is due to a key duplication issue
'is_reserved' => 1,
'is_active' => 1,
);
- $result1 = civicrm_api('OptionGroup', 'create', $params);
- $this->assertAPISuccess($result1);
- $result = civicrm_api('OptionGroup', 'create', $params);
- civicrm_api('OptionGroup', 'delete', array('version' => 3, 'id' => $result1['id']));
- $this->assertEquals("Field: `name` must be unique. An conflicting entity already exists - id: " . $result1['id'], $result['error_message']);
+ $result1 = $this->callAPISuccess('OptionGroup', 'create', $params);
+ $result = $this->callAPIFailure('OptionGroup', 'create', $params, "Field: `name` must be unique. An conflicting entity already exists - id: " . $result1['id']);
+ $this->callAPISuccess('OptionGroup', 'delete', array('id' => $result1['id']));
}
/*
'Count of option groups should not have changed due to rollback triggered by option value In line ' . __LINE__
);
}
+
+ /**
+ * success test for updating an existing Option Group
+ */
+ public function testCreateUpdateOptionGroup() {
+ $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+ $params = array_merge($this->_params, array('id' => $result['id'], 'is_active' => 0));
+ $this->callAPISuccess($this->_entity, 'create', $params);
+ $this->callAPISuccess('OptionGroup', 'delete', array('id' => $result['id']));
+ }
+
+ /**
+ * success test for deleting an existing Option Group
+ */
+ public function testDeleteOptionGroup() {
+ $result = $this->callAPISuccess($this->_entity, 'create', $this->_params);
+ $this->callAPIAndDocument('OptionGroup', 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__);
+ }
}