X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FCore%2FBAO%2FCustomFieldTest.php;h=e0a1cf9b62ccb6bf2e6f8108e5a7574d6419dddd;hb=d9fcaba3209b11e0a65c3f6e280f88bdff5fec77;hp=53c1456ea6e112c36671bdd3c37cff6f4063a5d0;hpb=bb7515b378f9781643ac6c950ad564df53dac85c;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php index 53c1456ea6..e0a1cf9b62 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php @@ -578,7 +578,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { $this->getCustomFieldName('select_date') => [ 'name' => $this->getCustomFieldName('select_date'), 'type' => 4, - 'title' => 'test_date', + 'title' => 'Test Date', 'headerPattern' => '//', 'import' => 1, 'custom_field_id' => $this->getCustomFieldID('select_date'), @@ -586,11 +586,11 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { 'text_length' => NULL, 'data_type' => 'Date', 'html_type' => 'Select Date', - 'is_search_range' => '0', + 'is_search_range' => '1', 'date_format' => 'mm/dd/yy', 'time_format' => '1', 'id' => $this->getCustomFieldID('select_date'), - 'label' => 'test_date', + 'label' => 'Test Date', 'groupTitle' => 'Custom Group', 'default_value' => '20090711', 'custom_group_id' => $customGroupID, @@ -639,6 +639,38 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { 'extends_table' => 'civicrm_contact', 'search_table' => 'contact_a', ], + $this->getCustomFieldName('int') => [ + 'name' => $this->getCustomFieldName('int'), + 'type' => CRM_Utils_Type::T_INT, + 'title' => 'Enter integer here', + 'headerPattern' => '//', + 'import' => 1, + 'custom_field_id' => $this->getCustomFieldID('int'), + 'options_per_line' => NULL, + 'text_length' => NULL, + 'data_type' => 'Int', + 'html_type' => 'Text', + 'is_search_range' => '1', + 'id' => $this->getCustomFieldID('int'), + 'label' => 'Enter integer here', + 'groupTitle' => 'Custom Group', + 'default_value' => '4', + 'custom_group_id' => $customGroupID, + 'extends' => 'Contact', + 'extends_entity_column_value' => NULL, + 'extends_entity_column_id' => NULL, + 'is_view' => '0', + 'is_multiple' => '0', + 'option_group_id' => NULL, + 'date_format' => NULL, + 'time_format' => NULL, + 'is_required' => '1', + 'table_name' => 'civicrm_value_custom_group_' . $customGroupID, + 'column_name' => $this->getCustomFieldColumnName('int'), + 'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('int'), + 'extends_table' => 'civicrm_contact', + 'search_table' => 'contact_a', + ], ]; $this->assertEquals($expected, CRM_Core_BAO_CustomField::getFieldsForImport()); } @@ -699,4 +731,50 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { $this->assertEquals($expectedDisplayValue, CRM_Core_BAO_CustomField::displayValue($file['id'], $fileField['id'])); } + /** + * Test for hook_civicrm_alterCustomFieldDisplayValue(). + */ + public function testAlterCustomFieldDisplayValueHook() { + CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_alterCustomFieldDisplayValue', [$this, 'alterCustomFieldDisplayValue']); + $customGroupId = $this->customGroupCreate([ + 'extends' => 'Individual', + 'title' => 'Test Contactcustom Group', + ])['id']; + $fieldId = $this->customFieldCreate([ + 'custom_group_id' => $customGroupId, + 'name' => 'alter_cf_field', + 'label' => 'Alter CF Field', + ])['id']; + $contactId = $this->individualCreate(['custom_' . $fieldId => 'Test']); + + $this->assertEquals('Test', $this->callAPISuccessGetValue('Contact', + ['id' => $contactId, 'return' => "custom_{$fieldId}"] + )); + + $values = []; + $fields = [ + 'custom_' . $fieldId => $this->callAPISuccess('Contact', 'getfield', [ + 'name' => 'custom_' . $fieldId, + 'action' => 'get', + ])['values'], + ]; + + // CRM_Core_BAO_UFGroup::getValues() invokes CRM_Core_BAO_CustomField::displayValue() function. + CRM_Core_BAO_UFGroup::getValues($contactId, $fields, $values); + $this->assertEquals('New value', $values['Alter CF Field']); + } + + /** + * @param string $displayValue + * @param mixed $value + * @param int $entityId + * @param array $fieldInfo + * + */ + public function alterCustomFieldDisplayValue(&$displayValue, $value, $entityId, $fieldInfo) { + if ($fieldInfo['name'] == 'alter_cf_field') { + $displayValue = 'New value'; + } + } + }