<?php
/*
+--------------------------------------------------------------------+
-| CiviCRM version 4.5 |
+| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
* Include class definitions
/**
* Test APIv3 civicrm_create_custom_group
*
- * @package CiviCRM
+ * @package CiviCRM
*/
class api_v3_CustomFieldTest extends CiviUnitTestCase {
protected $_apiversion;
- /**
- * @return array
- */
- function get_info() {
- return array(
- 'name' => 'Custom Field Create',
- 'description' => 'Test all Custom Field Create API methods.',
- 'group' => 'CiviCRM API Tests',
- );
- }
-
- function setUp() {
+ public function setUp() {
$this->_apiversion = 3;
parent::setUp();
}
- function tearDown() {
+ public function tearDown() {
$tablesToTruncate = array(
- 'civicrm_custom_group', 'civicrm_custom_field',
+ 'civicrm_custom_group',
+ 'civicrm_custom_field',
);
// true tells quickCleanup to drop any tables that might have been created in the test
$this->quickCleanup($tablesToTruncate, TRUE);
}
/**
- * check with no array
+ * Check with no array
*/
- function testCustomFieldCreateNoArray() {
+ public function testCustomFieldCreateNoArray() {
$fieldParams = NULL;
$customField = $this->callAPIFailure('custom_field', 'create', $fieldParams);
}
/**
- * check with no label
+ * Check with no label
*/
- function testCustomFieldCreateWithoutLabel() {
+ public function testCustomFieldCreateWithoutLabel() {
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'text_test_group'));
$params = array(
'custom_group_id' => $customGroup['id'],
}
/**
- * check with edit
+ * Check with edit
*/
- function testCustomFieldCreateWithEdit() {
+ public function testCustomFieldCreateWithEdit() {
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'text_test_group'));
$params = array(
'custom_group_id' => $customGroup['id'],
'is_active' => 1,
);
- $customField = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__);
+ $customField = $this->callAPIAndDocument('custom_field', 'create', $params, __FUNCTION__, __FILE__);
$params['id'] = $customField['id'];
- $customField = $this->callAPISuccess('custom_field', 'create', $params);
+ $customField = $this->callAPISuccess('custom_field', 'create', $params);
$this->assertNotNull($customField['id'], 'in line ' . __LINE__);
}
/**
- * check without groupId
+ * Check without groupId
*/
- function testCustomFieldCreateWithoutGroupID() {
+ public function testCustomFieldCreateWithoutGroupID() {
$fieldParams = array(
'name' => 'test_textfield1',
'label' => 'Name',
/**
* Check for Each data type: loop through available form input types
- **/
- function testCustomFieldCreateAllAvailableFormInputs() {
+ */
+ public function testCustomFieldCreateAllAvailableFormInputs() {
$gid = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'testAllFormInputs'));
$dtype = CRM_Core_BAO_CustomField::dataType();
$n++;
}
}
-/*
- * Can't figure out the point of this?
- */
+ /*
+ * Can't figure out the point of this?
+ */
/**
- * @param $params
+ * @param array $params
*/
- function _loopingCustomFieldCreateTest($params) {
+ public function _loopingCustomFieldCreateTest($params) {
$customField = $this->callAPISuccess('custom_field', 'create', $params);
$this->assertNotNull($customField['id']);
$this->getAndCheck($params, $customField['id'], 'CustomField');
}
/**
- * @param $gid
+ * @param int $gid
* @param $htype
* @param $dtype
*
* @return array
*/
- function _buildParams($gid, $htype, $dtype) {
+ public function _buildParams($gid, $htype, $dtype) {
$params = $this->_buildBasicParams($gid, $htype, $dtype);
/* //Not Working for any type. Maybe redundant with testCustomFieldCreateWithOptionValues()
- if ($htype == 'Multi-Select')
- $params = array_merge($params, array(
- 'option_label' => array( 'Label1','Label2'),
- 'option_value' => array( 'val1', 'val2' ),
- 'option_weight' => array( 1, 2),
- 'option_status' => array( 1, 1),
- ));
-*/
-
-
+ if ($htype == 'Multi-Select')
+ $params = array_merge($params, array(
+ 'option_label' => array( 'Label1','Label2'),
+ 'option_value' => array( 'val1', 'val2' ),
+ 'option_weight' => array( 1, 2),
+ 'option_status' => array( 1, 1),
+ ));
+ */
return $params;
}
/**
- * @param $gid
+ * @param int $gid
* @param $htype
* @param $dtype
*
* @return array
*/
- function _buildBasicParams($gid, $htype, $dtype) {
+ public function _buildBasicParams($gid, $htype, $dtype) {
return array(
'custom_group_id' => $gid,
'label' => $dtype . $htype,
* Test using example code
*/
/*function testCustomFieldCreateExample( )
- {
+ {
- $customGroup = $this->customGroupCreate('Individual','date_test_group',3);
- require_once 'api/v3/examples/CustomField/Create.php';
- $result = custom_field_create_example();
- $expectedResult = custom_field_create_expectedresult();
- $this->assertEquals($result,$expectedResult);
- }*/
+ $customGroup = $this->customGroupCreate('Individual','date_test_group',3);
+ require_once 'api/v3/examples/CustomField/Create.php';
+ $result = custom_field_create_example();
+ $expectedResult = custom_field_create_expectedresult();
+ $this->assertEquals($result,$expectedResult);
+ }*/
/**
- * check with data type - Options with option_values
+ * Check with data type - Options with option_values
*/
- function testCustomFieldCreateWithEmptyOptionGroup() {
+ public function testCustomFieldCreateWithEmptyOptionGroup() {
$customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group'));
$params = array(
'custom_group_id' => $customGroup['id'],
$this->assertTrue(is_numeric($optionGroupID) && ($optionGroupID > 0));
$optionGroup = $this->callAPISuccess('option_group', 'getsingle', array(
- 'id' => $optionGroupID));
- $this->assertEquals($optionGroup['title'],'Country');
+ 'id' => $optionGroupID,
+ ));
+ $this->assertEquals($optionGroup['title'], 'Country');
$optionValueCount = $this->callAPISuccess('option_value', 'getcount', array(
- 'option_group_id' => $optionGroupID));
+ 'option_group_id' => $optionGroupID,
+ ));
$this->assertEquals(0, $optionValueCount);
}
/**
* Test custom field with existing option group
*/
- function testCustomFieldExistingOptionGroup() {
+ public function testCustomFieldExistingOptionGroup() {
$customGroup = $this->customGroupCreate(array('extends' => 'Organization', 'title' => 'test_group'));
$params = array(
'custom_group_id' => $customGroup['id'],
'return' => 'option_group_id',
));
- $this->assertEquals($optionGroupID,3);
+ $this->assertEquals($optionGroupID, 3);
}
/**
* Test custom field get works & return param works
*/
- function testCustomFieldGetReturnOptions(){
+ public function testCustomFieldGetReturnOptions() {
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
$customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
/**
* Test custom field get works & return param works
*/
- function testCustomFieldGetReturnArray(){
+ public function testCustomFieldGetReturnArray() {
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
$customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
$result = $this->callAPISuccess('custom_field', 'getsingle', array(
- 'id' => $customField['id'],
+ 'id' => $customField['id'],
'return' => array('data_type'),
));
$this->assertTrue(array_key_exists('data_type', $result));
/**
* Test custom field get works & return param works
*/
- function testCustomFieldGetReturnTwoOptions(){
+ public function testCustomFieldGetReturnTwoOptions() {
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'test_group'));
$customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
$result = $this->callAPISuccess('custom_field', 'getsingle', array(
- 'id' => $customField['id'],
+ 'id' => $customField['id'],
'return' => 'data_type, custom_group_id',
));
$this->assertTrue(array_key_exists('data_type', $result));
$this->assertFalse(array_key_exists('label', $result));
}
- function testCustomFieldCreateWithOptionValues() {
+ public function testCustomFieldCreateWithOptionValues() {
$customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group'));
$option_values = array(
- array('weight' => 1,
+ array(
+ 'weight' => 1,
'label' => 'Label1',
'value' => 1,
'is_active' => 1,
$this->assertNotNull($customField['id']);
$getFieldsParams = array(
'options' => array('get_options' => 'custom_' . $customField['id']),
- 'action' => 'create',
+ 'action' => 'create',
);
- $description = "Demonstrate retrieving metadata with custom field options";
+ $description = "Demonstrate retrieving metadata with custom field options";
$subfile = "GetFieldsOptions";
- $fields = $this->callAPIAndDocument('contact', 'getfields', $getFieldsParams, __FUNCTION__, 'ContactTest.php', $description,$subfile,'GetFields');
+ $fields = $this->callAPIAndDocument('contact', 'getfields', $getFieldsParams, __FUNCTION__, 'ContactTest.php', $description, $subfile, 'GetFields');
$this->assertArrayHasKey('options', $fields['values']['custom_' . $customField['id']]);
$this->assertEquals('Label1', $fields['values']['custom_' . $customField['id']]['options'][1]);
$getOptionsArray = array(
'field' => 'custom_' . $customField['id'],
- );
+ );
$description = "Demonstrates retrieving options for a custom field";
$subfile = "GetOptions";
$result = $this->callAPIAndDocument('contact', 'getoptions', $getOptionsArray, __FUNCTION__, 'ContactTest.php', $description, '', 'getoptions');
///////////////// civicrm_custom_field_delete methods
/**
- * check with no array
+ * Check with no array
*/
- function testCustomFieldDeleteNoArray() {
+ public function testCustomFieldDeleteNoArray() {
$params = NULL;
$customField = $this->callAPIFailure('custom_field', 'delete', $params);
$this->assertEquals($customField['error_message'], 'Input variable `params` is not an array');
}
/**
- * check without Field ID
+ * Check without Field ID
*/
- function testCustomFieldDeleteWithoutFieldID() {
+ public function testCustomFieldDeleteWithoutFieldID() {
$params = array();
$customField = $this->callAPIFailure('custom_field', 'delete', $params,
'Mandatory key(s) missing from params array: id');
}
/**
- * check without valid array
+ * Check without valid array
*/
- function testCustomFieldDelete() {
+ public function testCustomFieldDelete() {
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
$customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
$this->assertNotNull($customField['id'], 'in line ' . __LINE__);
}
/**
- * check for Option Value
+ * Check for Option Value
*/
- function testCustomFieldOptionValueDelete() {
+ public function testCustomFieldOptionValueDelete() {
$customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'ABC'));
$customOptionValueFields = $this->customFieldOptionValueCreate($customGroup, 'fieldABC');
$params = array(
* and "Activity.getfields" should return only their respective fields (not the other's fields),
* and unrelated entities should return no custom fields.
*/
- function testGetfields_CrossEntityPollution() {
+ public function testGetfields_CrossEntityPollution() {
$auxEntities = array('Email', 'Address', 'LocBlock', 'Membership', 'ContributionPage', 'ReportInstance');
$allEntities = array_merge(array('Contact', 'Activity'), $auxEntities);
// Add some fields
$contactGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'test_group_c'));
- $contactField = $this->customFieldCreate(array('custom_group_id' => $contactGroup['id'], 'label' => 'For Contacts'));
+ $contactField = $this->customFieldCreate(array(
+ 'custom_group_id' => $contactGroup['id'],
+ 'label' => 'For Contacts',
+ ));
$indivGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group_i'));
$indivField = $this->customFieldCreate(array('custom_group_id' => $indivGroup['id'], 'label' => 'For Individuals'));
$activityGroup = $this->customGroupCreate(array('extends' => 'Activity', 'title' => 'test_group_a'));
- $activityField = $this->customFieldCreate(array('custom_group_id' => $activityGroup['id'], 'label' => 'For Activities'));
+ $activityField = $this->customFieldCreate(array(
+ 'custom_group_id' => $activityGroup['id'],
+ 'label' => 'For Activities',
+ ));
// Check getfields
$this->assertEquals(
*
* @return array
*/
- function getCustomFieldKeys($getFieldsResult) {
- $isCustom = function($key) {
+ public function getCustomFieldKeys($getFieldsResult) {
+ $isCustom = function ($key) {
return preg_match('/^custom_/', $key);
};
$r = array_values(array_filter(array_keys($getFieldsResult['values']), $isCustom));
sort($r);
return $r;
}
-}
+}