From d5c86914bd1c2747f1f75d19200f7395a98f9a76 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 15 Dec 2015 22:07:20 -0500 Subject: [PATCH] CRM-17646 - Add unit tests --- .../phpunit/CRM/Core/BAO/CustomFieldTest.php | 80 +++++++++++++++---- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php index fb5b509309..f808556692 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php @@ -120,21 +120,73 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { public function testGetDisplayedValues() { $customGroup = Custom::createGroup(array(), 'Individual'); - $fields = array( - 'label' => 'testCountryFld1', - 'data_type' => 'Country', - 'html_type' => 'Select Country', - 'is_active' => 1, - 'default_value' => 1228, - 'custom_group_id' => $customGroup->id, - ); - $customField1 = CRM_Core_BAO_CustomField::create($fields); - $customFieldID1 = $this->assertDBNotNull('CRM_Core_DAO_CustomField', $customGroup->id, 'id', 'custom_group_id', - 'Database check for created CustomField.' + $fieldsToCreate = array( + array( + 'data_type' => 'Country', + 'html_type' => 'Select Country', + 'tests' => array( + 'UNITED STATES' => 1228, + '' => NULL, + ), + ), + array( + 'data_type' => 'StateProvince', + 'html_type' => 'Multi-Select State/Province', + 'tests' => array( + '' => 0, + 'Alabama' => 1000, + 'Alabama, Alaska' => array(1000, 1001), + ), + ), + array( + 'data_type' => 'String', + 'html_type' => 'Radio', + 'option_values' => array( + 'key' => 'KeyLabel', + ), + 'tests' => array( + 'KeyLabel' => 'key', + ), + ), + array( + 'data_type' => 'String', + 'html_type' => 'CheckBox', + 'option_values' => array( + 'key1' => 'Label1', + 'key2' => 'Label2', + 'key3' => 'Label3', + 'key4' => 'Label4', + ), + 'tests' => array( + 'Label1' => array('key1'), + 'Label2' => 'key2', + 'Label2, Label3' => array('key2', 'key3'), + 'Label3, Label4' => CRM_Utils_Array::implodePadded(array('key3', 'key4')), + 'Label1, Label4' => array('key1' => 1, 'key4' => 1), + ), + ), + array( + 'data_type' => 'Date', + 'html_type' => 'Select Date', + 'date_format' => 'd M yy', + 'time_format' => 1, + 'tests' => array( + '1 Jun 1999 1:30PM' => '1999-06-01 13:30', + '' => '', + ), + ), ); - $display = CRM_Core_BAO_CustomField::displayValue($fields['default_value'], $customFieldID1); - - $this->assertEquals('UNITED STATES', $display, 'Confirm Country display Name'); + foreach ($fieldsToCreate as $num => $field) { + $params = $field + array( + 'label' => 'test field ' . $num, + 'custom_group_id' => $customGroup->id, + ); + unset($params['tests']); + $createdField = $this->callAPISuccess('customField', 'create', $params); + foreach ($field['tests'] as $expected => $input) { + $this->assertEquals($expected, CRM_Core_BAO_CustomField::displayValue($input, $createdField['id'])); + } + } Custom::deleteGroup($customGroup); } -- 2.25.1