Skip to content
Snippets Groups Projects
Commit b422b715 authored by eileen's avatar eileen
Browse files

CRM-13234 one line fix for test failure caused by change to set-up class

Well - it would have been one line - except then I wanted to keep testing what happens when the custom field has a default value (the breakage) & without (per before) so then I wound up having to fix up the function signature too
parent 5450a07b
No related branches found
No related tags found
No related merge requests found
...@@ -176,7 +176,7 @@ function civicrm_api3_custom_value_get($params) { ...@@ -176,7 +176,7 @@ function civicrm_api3_custom_value_get($params) {
return civicrm_api3_create_success($values, $params); return civicrm_api3_create_success($values, $params);
} }
else { else {
return civicrm_api3_create_error($result['error_message']); throw new API_Exception($result['error_message']);
} }
} }
else { else {
......
...@@ -126,23 +126,23 @@ function contact_get_expectedresult(){ ...@@ -126,23 +126,23 @@ function contact_get_expectedresult(){
), ),
'3' => array( '3' => array(
'entity_id' => '1', 'entity_id' => '1',
'latest' => '', 'latest' => 'defaultValue',
'id' => '3', 'id' => '3',
'1' => 'warm beer', '1' => 'warm beer',
'2' => '', '2' => 'defaultValue',
), ),
'4' => array( '4' => array(
'entity_id' => '1', 'entity_id' => '1',
'latest' => '', 'latest' => 'defaultValue',
'id' => '4', 'id' => '4',
'1' => '', '1' => 'defaultValue',
'2' => '', '2' => 'defaultValue',
), ),
'5' => array( '5' => array(
'entity_id' => '1', 'entity_id' => '1',
'latest' => '', 'latest' => 'defaultValue',
'id' => '5', 'id' => '5',
'1' => '', '1' => 'defaultValue',
), ),
'6' => array( '6' => array(
'entity_id' => '1', 'entity_id' => '1',
...@@ -152,9 +152,9 @@ function contact_get_expectedresult(){ ...@@ -152,9 +152,9 @@ function contact_get_expectedresult(){
), ),
'7' => array( '7' => array(
'entity_id' => '1', 'entity_id' => '1',
'latest' => '', 'latest' => 'defaultValue',
'id' => '7', 'id' => '7',
'1' => '', '1' => 'defaultValue',
), ),
), ),
), ),
......
...@@ -320,6 +320,10 @@ function contact_getfields_expectedresult(){ ...@@ -320,6 +320,10 @@ function contact_getfields_expectedresult(){
'pseudoconstant' => array( 'pseudoconstant' => array(
'optionGroupName' => 'individual_prefix', 'optionGroupName' => 'individual_prefix',
), ),
'api.aliases' => array(
'0' => 'individual_prefix',
'1' => 'individual_prefix_id',
),
), ),
'suffix_id' => array( 'suffix_id' => array(
'name' => 'suffix_id', 'name' => 'suffix_id',
...@@ -333,6 +337,10 @@ function contact_getfields_expectedresult(){ ...@@ -333,6 +337,10 @@ function contact_getfields_expectedresult(){
'pseudoconstant' => array( 'pseudoconstant' => array(
'optionGroupName' => 'individual_suffix', 'optionGroupName' => 'individual_suffix',
), ),
'api.aliases' => array(
'0' => 'individual_suffix',
'1' => 'individual_suffix_id',
),
), ),
'email_greeting_id' => array( 'email_greeting_id' => array(
'name' => 'email_greeting_id', 'name' => 'email_greeting_id',
...@@ -552,6 +560,7 @@ function contact_getfields_expectedresult(){ ...@@ -552,6 +560,7 @@ function contact_getfields_expectedresult(){
'groupTitle' => 'select_test_g', 'groupTitle' => 'select_test_g',
'data_type' => 'String', 'data_type' => 'String',
'html_type' => 'Select', 'html_type' => 'Select',
'default_value' => '',
'text_length' => '', 'text_length' => '',
'options_per_line' => '', 'options_per_line' => '',
'custom_group_id' => '1', 'custom_group_id' => '1',
......
...@@ -45,7 +45,7 @@ function custom_field_create_expectedresult(){ ...@@ -45,7 +45,7 @@ function custom_field_create_expectedresult(){
'1' => array( '1' => array(
'id' => '1', 'id' => '1',
'custom_group_id' => '1', 'custom_group_id' => '1',
'name' => 'Name1', 'name' => 'test_textfield2',
'label' => 'Name1', 'label' => 'Name1',
'data_type' => 'String', 'data_type' => 'String',
'html_type' => 'Text', 'html_type' => 'Text',
......
...@@ -32,31 +32,52 @@ function custom_value_get_expectedresult(){ ...@@ -32,31 +32,52 @@ function custom_value_get_expectedresult(){
$expectedResult = array( $expectedResult = array(
'is_error' => 0, 'is_error' => 0,
'version' => 3, 'version' => 3,
'count' => 4, 'count' => 7,
'values' => array( 'values' => array(
'mySingleField' => array( 'mySingleField' => array(
'entity_id' => '2', 'entity_id' => '2',
'latest' => 'value 1', 'latest' => 'value 1',
'id' => 'mySingleField', 'id' => 'mySingleField',
), ),
'Cust_Field' => array( 'field_12' => array(
'entity_id' => '2',
'latest' => 'value 3',
'id' => 'field_12',
'1' => 'value 2',
'2' => 'value 3',
),
'field_22' => array(
'entity_id' => '2',
'latest' => '',
'id' => 'field_22',
'1' => 'warm beer',
'2' => '',
),
'field_32' => array(
'entity_id' => '2',
'latest' => '',
'id' => 'field_32',
'1' => 'fl* w*',
'2' => '',
),
'field_13' => array(
'entity_id' => '2', 'entity_id' => '2',
'latest' => 'coffee', 'latest' => 'coffee',
'id' => 'Cust_Field', 'id' => 'field_13',
'1' => '', '1' => 'defaultValue',
'2' => 'coffee', '2' => 'coffee',
), ),
'field_2' => array( 'field_23' => array(
'entity_id' => '2', 'entity_id' => '2',
'latest' => 'value 4', 'latest' => 'value 4',
'id' => 'field_2', 'id' => 'field_23',
'1' => '', '1' => '',
'2' => 'value 4', '2' => 'value 4',
), ),
'field_3' => array( 'field_33' => array(
'entity_id' => '2', 'entity_id' => '2',
'latest' => '', 'latest' => '',
'id' => 'field_3', 'id' => 'field_33',
'1' => 'vegemite', '1' => 'vegemite',
'2' => '', '2' => '',
), ),
......
...@@ -63,7 +63,7 @@ function custom_value_get_expectedresult(){ ...@@ -63,7 +63,7 @@ function custom_value_get_expectedresult(){
'entity_id' => '2', 'entity_id' => '2',
'latest' => 'coffee', 'latest' => 'coffee',
'id' => '5', 'id' => '5',
'1' => '', '1' => 'defaultValue',
'2' => 'coffee', '2' => 'coffee',
), ),
'6' => array( '6' => array(
......
...@@ -1704,14 +1704,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { ...@@ -1704,14 +1704,14 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
$customGroup = $this->CustomGroupMultipleCreateByParams($params); $customGroup = $this->CustomGroupMultipleCreateByParams($params);
$ids['custom_group_id'] = $customGroup['id']; $ids['custom_group_id'] = $customGroup['id'];
$customField = $this->customFieldCreate($ids['custom_group_id']); $customField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'label' => 'field_1' . $ids['custom_group_id']));
$ids['custom_field_id'][] = $customField['id']; $ids['custom_field_id'][] = $customField['id'];
$customField = $this->customFieldCreate($ids['custom_group_id'], 'field_2'); $customField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'default_value' => '', 'label' => 'field_2' . $ids['custom_group_id']));
$ids['custom_field_id'][] = $customField['id']; $ids['custom_field_id'][] = $customField['id'];
$customField = $this->customFieldCreate($ids['custom_group_id'], 'field_3'); $customField = $this->customFieldCreate(array('custom_group_id' => $ids['custom_group_id'], 'default_value' => '', 'label' => 'field_3' . $ids['custom_group_id']));
$ids['custom_field_id'][] = $customField['id']; $ids['custom_field_id'][] = $customField['id'];
return $ids; return $ids;
...@@ -1732,7 +1732,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { ...@@ -1732,7 +1732,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
$entity = substr(basename($filename), 0, strlen(basename($filename)) - 8); $entity = substr(basename($filename), 0, strlen(basename($filename)) - 8);
$params['extends'] = $entity ? $entity : 'Contact'; $params['extends'] = $entity ? $entity : 'Contact';
$customGroup = $this->CustomGroupCreate($params); $customGroup = $this->CustomGroupCreate($params);
$customField = $this->customFieldCreate($customGroup['id'], $function); $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id'], 'label' => $function));
CRM_Core_PseudoConstant::flush(); CRM_Core_PseudoConstant::flush();
return array('custom_group_id' => $customGroup['id'], 'custom_field_id' => $customField['id']); return array('custom_group_id' => $customGroup['id'], 'custom_field_id' => $customField['id']);
...@@ -1744,7 +1744,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { ...@@ -1744,7 +1744,6 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
* @param int $customGroupID * @param int $customGroupID
*/ */
function customGroupDelete($customGroupID) { function customGroupDelete($customGroupID) {
$params['id'] = $customGroupID; $params['id'] = $customGroupID;
return $this->callAPISuccess('custom_group', 'delete', $params); return $this->callAPISuccess('custom_group', 'delete', $params);
} }
...@@ -1752,22 +1751,19 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { ...@@ -1752,22 +1751,19 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
/** /**
* Function to create custom field * Function to create custom field
* *
* @param int $customGroupID * @param array $params (custom_group_id) is required
* @param string $name name of custom field * @param string $name name of custom field
* @param int $apiversion API version to use * @param int $apiversion API version to use
*/ */
function customFieldCreate($customGroupID, $name = "Cust Field") { function customFieldCreate($params) {
$params = array_merge(array(
$params = array( 'label' => 'Custom Field',
'label' => $name,
'name' => $name,
'custom_group_id' => $customGroupID,
'data_type' => 'String', 'data_type' => 'String',
'html_type' => 'Text', 'html_type' => 'Text',
'is_searchable' => 1, 'is_searchable' => 1,
'is_active' => 1, 'is_active' => 1,
'default_value' => 'defaultValue', 'default_value' => 'defaultValue',
); ), $params);
$result = $this->callAPISuccess('custom_field', 'create', $params); $result = $this->callAPISuccess('custom_field', 'create', $params);
......
...@@ -1329,7 +1329,7 @@ class api_v3_ContactTest extends CiviUnitTestCase { ...@@ -1329,7 +1329,7 @@ class api_v3_ContactTest extends CiviUnitTestCase {
$ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
$params['custom_' . $ids['custom_field_id']] = "custom string"; $params['custom_' . $ids['custom_field_id']] = "custom string";
$moreids = $this->CustomGroupMultipleCreateWithFields(); $moreids = $this->CustomGroupMultipleCreateWithFields();
$andmoreids = $this->CustomGroupMultipleCreateWithFields(array('title' => "another group")); $andmoreids = $this->CustomGroupMultipleCreateWithFields(array('title' => "another group", 'name' => 'another name'));
$description = "/*this demonstrates the usage of chained api functions. A variety of techniques are used"; $description = "/*this demonstrates the usage of chained api functions. A variety of techniques are used";
$subfile = "APIChainedArrayMultipleCustom"; $subfile = "APIChainedArrayMultipleCustom";
$params = array( $params = array(
......
...@@ -247,7 +247,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { ...@@ -247,7 +247,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
*/ */
function testCustomFieldGetReturnOptions(){ function testCustomFieldGetReturnOptions(){
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group')); $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
$customField = $this->customFieldCreate($customGroup['id'], 'test_name'); $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
$result = $this->callAPISuccess('custom_field', 'getsingle', array( $result = $this->callAPISuccess('custom_field', 'getsingle', array(
'id' => $customField['id'], 'id' => $customField['id'],
...@@ -262,7 +262,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { ...@@ -262,7 +262,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
*/ */
function testCustomFieldGetReturnArray(){ function testCustomFieldGetReturnArray(){
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group')); $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
$customField = $this->customFieldCreate($customGroup['id'], 'test_name'); $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
$result = $this->callAPISuccess('custom_field', 'getsingle', array( $result = $this->callAPISuccess('custom_field', 'getsingle', array(
'id' => $customField['id'], 'id' => $customField['id'],
...@@ -277,7 +277,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { ...@@ -277,7 +277,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
*/ */
function testCustomFieldGetReturnTwoOptions(){ function testCustomFieldGetReturnTwoOptions(){
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'test_group')); $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'test_group'));
$customField = $this->customFieldCreate($customGroup['id'], 'test_name'); $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
$result = $this->callAPISuccess('custom_field', 'getsingle', array( $result = $this->callAPISuccess('custom_field', 'getsingle', array(
'id' => $customField['id'], 'id' => $customField['id'],
...@@ -365,7 +365,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase { ...@@ -365,7 +365,7 @@ class api_v3_CustomFieldTest extends CiviUnitTestCase {
*/ */
function testCustomFieldDelete() { function testCustomFieldDelete() {
$customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group')); $customGroup = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'test_group'));
$customField = $this->customFieldCreate($customGroup['id'], 'test_name'); $customField = $this->customFieldCreate(array('custom_group_id' => $customGroup['id']));
$this->assertNotNull($customField['id'], 'in line ' . __LINE__); $this->assertNotNull($customField['id'], 'in line ' . __LINE__);
$params = array( $params = array(
......
...@@ -61,7 +61,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { ...@@ -61,7 +61,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase {
$this->CustomGroupIndividual = $this->customGroupCreate($groupIndividual); $this->CustomGroupIndividual = $this->customGroupCreate($groupIndividual);
$this->IndividualField = $this->customFieldCreate($this->CustomGroupIndividual['id'], "Custom Field" . substr(sha1(rand()), 0, 7)); $this->IndividualField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndividual['id']));
// Create Group For Individual-Student Contact Sub Type // Create Group For Individual-Student Contact Sub Type
$groupIndiStudent = array( $groupIndiStudent = array(
...@@ -73,7 +73,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase { ...@@ -73,7 +73,7 @@ class api_v3_CustomValueContactTypeTest extends CiviUnitTestCase {
$this->CustomGroupIndiStudent = $this->customGroupCreate($groupIndiStudent); $this->CustomGroupIndiStudent = $this->customGroupCreate($groupIndiStudent);
$this->IndiStudentField = $this->customFieldCreate($this->CustomGroupIndiStudent['id'], "Custom Field" . substr(sha1(rand()), 0, 7)); $this->IndiStudentField = $this->customFieldCreate(array('custom_group_id' => $this->CustomGroupIndiStudent['id']));
$params = array( $params = array(
'first_name' => 'Mathev', 'first_name' => 'Mathev',
......
...@@ -85,15 +85,17 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { ...@@ -85,15 +85,17 @@ class api_v3_CustomValueTest extends CiviUnitTestCase {
$result = $this->callAPISuccess('Contact', 'create', $params); $result = $this->callAPISuccess('Contact', 'create', $params);
$contact_id = $result['id']; $contact_id = $result['id'];
$result = $this->callAPISuccess('Contact', 'create', $firstCustomField = $this->ids['multi']['custom_field_id'][0];
array( $secondCustomField = $this->ids['multi2']['custom_field_id'][0];
'contact_type' => 'Individual', $thirdCustomField = $this->ids['multi2']['custom_field_id'][1];
'id' => $contact_id, $createParams = array(
'custom_' . $this->ids['multi']['custom_field_id'][0] => "value 3", 'contact_type' => 'Individual',
'custom_' . $this->ids['multi2']['custom_field_id'][0] => "coffee", 'id' => $contact_id,
'custom_' . $this->ids['multi2']['custom_field_id'][1] => "value 4", 'custom_' . $firstCustomField => "value 3",
) 'custom_' . $secondCustomField => "coffee",
'custom_' . $thirdCustomField => "value 4",
); );
$result = $this->callAPISuccess('Contact', 'create', $createParams);
$params = array( $params = array(
'id' => $result['id'], 'id' => $result['id'],
...@@ -105,15 +107,16 @@ class api_v3_CustomValueTest extends CiviUnitTestCase { ...@@ -105,15 +107,16 @@ class api_v3_CustomValueTest extends CiviUnitTestCase {
$resultformatted = $this->callAPIAndDocument('CustomValue', 'Get', $params, __FUNCTION__, __FILE__, "utilises field names", 'formatFieldName'); $resultformatted = $this->callAPIAndDocument('CustomValue', 'Get', $params, __FUNCTION__, __FILE__, "utilises field names", 'formatFieldName');
// delete the contact // delete the contact
$this->callAPISuccess('contact', 'delete', array('id' => $contact_id)); $this->callAPISuccess('contact', 'delete', array('id' => $contact_id));
$this->assertEquals('coffee', $result['values'][$secondCustomField]['2']);
$this->assertEquals('coffee', $result['values'][$this->ids['multi2']['custom_field_id'][0]]['2'], "In line " . __LINE__); $this->assertEquals('coffee', $result['values'][$secondCustomField]['latest']);
$this->assertEquals('coffee', $result['values'][$this->ids['multi2']['custom_field_id'][0]]['latest'], "In line " . __LINE__); $this->assertEquals($secondCustomField, $result['values'][$secondCustomField]['id']);
$this->assertEquals($this->ids['multi2']['custom_field_id'][0], $result['values'][$this->ids['multi2']['custom_field_id'][0]]['id'], "In line " . __LINE__); $this->assertEquals('defaultValue', $result['values'][$secondCustomField]['1']);
$this->assertEquals('', $result['values'][$this->ids['multi2']['custom_field_id'][0]]['1'], "In line " . __LINE__); $this->assertEquals($contact_id, $result['values'][$secondCustomField]['entity_id']);
$this->assertEquals($contact_id, $result['values'][$this->ids['multi2']['custom_field_id'][0]]['entity_id'], "In line " . __LINE__); $this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['0']);
$this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['0'], "In line " . __LINE__); $this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['latest']);
$this->assertEquals('value 1', $result['values'][$this->ids['single']['custom_field_id']]['latest'], "In line " . __LINE__); $this->assertEquals('value 1', $resultformatted['values']['mySingleField']['latest']);
$this->assertEquals('value 1', $resultformatted['values']['mySingleField']['latest'], "In line " . __LINE__); $this->assertEquals('', $result['values'][$thirdCustomField]['1']);
$this->assertEquals('value 4', $result['values'][$thirdCustomField]['2']);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment