Merge pull request #17008 from ivan-compucorp/CPS-70-fix-radio-value
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / CustomFieldTest.php
index 0ed1ff2a1700c2231441a09975df81349760e3e2..42a74c2026938496245f2f8b5eadcda19064e209 100644 (file)
@@ -187,6 +187,20 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
           '' => '',
         ],
       ],
+      [
+        'data_type' => 'Money',
+        'html_type' => 'Radio',
+        'option_values' => [
+          '10' => '10 USD',
+          '10.1' => '10.1 USD',
+          '10.99' => '10.99 USD',
+        ],
+        'tests' => [
+          '10 USD' => '10.00',
+          '10.1 USD' => '10.10',
+          '10.99 USD' => '10.99',
+        ],
+      ],
     ];
     foreach ($fieldsToCreate as $num => $field) {
       $params = $field + ['label' => 'test field ' . $num, 'custom_group_id' => $customGroup['id']];
@@ -216,13 +230,13 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
     ];
     $createdField = $this->callAPISuccess('customField', 'create', $params);
     $contact1 = $this->individualCreate();
-    $contact2 = $this->individualCreate(['custom_' . $createdField['id'] => $contact1['id']]);
-
-    $this->assertEquals($contact1['display_name'], CRM_Core_BAO_CustomField::displayValue($contact2['id'], $createdField['id']));
+    $contact2 = $this->individualCreate(['custom_' . $createdField['id'] => $contact1]);
+    $contact1Details = $this->callAPISuccess('Contact', 'getsingle', ['id' => $contact1]);
+    $this->assertEquals($contact1Details['display_name'], CRM_Core_BAO_CustomField::displayValue($contact2, $createdField['id']));
     $this->assertEquals("Bob", CRM_Core_BAO_CustomField::displayValue("Bob", $createdField['id']));
 
-    $this->contactDelete($contact2['id']);
-    $this->contactDelete($contact1['id']);
+    $this->contactDelete($contact2);
+    $this->contactDelete($contact1);
     $this->customGroupDelete($customGroup['id']);
   }
 
@@ -463,10 +477,50 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'time_format' => NULL,
         'is_required' => 0,
         'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
-        'column_name' => 'country_' . $this->getCustomFieldID('country'),
-        'where' => 'civicrm_value_custom_group_' . $customGroupID . '.country_' . $this->getCustomFieldID('country'),
+        'column_name' => $this->getCustomFieldColumnName('country'),
+        'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('country'),
+        'extends_table' => 'civicrm_contact',
+        'search_table' => 'contact_a',
+        'serialize' => NULL,
+        'pseudoconstant' => [
+          'table' => 'civicrm_country',
+          'keyColumn' => 'id',
+          'labelColumn' => 'name',
+          'nameColumn' => 'iso_code',
+        ],
+      ],
+      $this->getCustomFieldName('multi_country') => [
+        'name' => $this->getCustomFieldName('multi_country'),
+        'type' => 1,
+        'title' => 'Country-multi',
+        'headerPattern' => '//',
+        'import' => 1,
+        'custom_field_id' => $this->getCustomFieldID('multi_country'),
+        'options_per_line' => NULL,
+        'text_length' => NULL,
+        'data_type' => 'Country',
+        'html_type' => 'Select Country',
+        'is_search_range' => '0',
+        'id' => $this->getCustomFieldID('multi_country'),
+        'label' => 'Country-multi',
+        'groupTitle' => 'Custom Group',
+        'default_value' => NULL,
+        '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' => 0,
+        'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+        'column_name' => $this->getCustomFieldColumnName('multi_country'),
+        'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('multi_country'),
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
+        'serialize' => 1,
         'pseudoconstant' => [
           'table' => 'civicrm_country',
           'keyColumn' => 'id',
@@ -505,6 +559,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'where' => 'civicrm_value_custom_group_' . $customGroupID . '.my_file_' . $this->getCustomFieldID('file'),
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
+        'serialize' => NULL,
       ],
       $this->getCustomFieldName('text') => [
         'name' => $this->getCustomFieldName('text'),
@@ -538,6 +593,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
         'maxlength' => 300,
+        'serialize' => NULL,
       ],
       $this->getCustomFieldName('select_string') => [
         'name' => $this->getCustomFieldName('select_string'),
@@ -570,6 +626,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'where' => 'civicrm_value_custom_group_' . $customGroupID . '.pick_color_' . $this->getCustomFieldID('select_string'),
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
+        'serialize' => NULL,
         'pseudoconstant' => [
           'optionGroupName' => $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']),
           'optionEditPath' => 'civicrm/admin/options/' . $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID('select_string'), 'return' => 'option_group_id.name']),
@@ -606,6 +663,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_date_' . $this->getCustomFieldID('select_date'),
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
+        'serialize' => NULL,
       ],
       $this->getCustomFieldName('link') => [
         'name' => $this->getCustomFieldName('link'),
@@ -638,6 +696,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'where' => 'civicrm_value_custom_group_' . $customGroupID . '.test_link_' . $this->getCustomFieldID('link'),
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
+        'serialize' => NULL,
       ],
       $this->getCustomFieldName('int') => [
         'name' => $this->getCustomFieldName('int'),
@@ -670,6 +729,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('int'),
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
+        'serialize' => NULL,
       ],
       $this->getCustomFieldName('contact_reference') => [
         'name' => $this->getCustomFieldName('contact_reference'),
@@ -702,6 +762,119 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
         'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('contact_reference'),
         'extends_table' => 'civicrm_contact',
         'search_table' => 'contact_a',
+        'serialize' => NULL,
+      ],
+      $this->getCustomFieldName('state') => [
+        'name' => $this->getCustomFieldName('state'),
+        'id' => $this->getCustomFieldID('state'),
+        'label' => 'State',
+        'headerPattern' => '//',
+        'title' => 'State',
+        'custom_field_id' => $this->getCustomFieldID('state'),
+        'groupTitle' => 'Custom Group',
+        'default_value' => NULL,
+        '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' => 0,
+        'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+        'column_name' => $this->getCustomFieldColumnName('state'),
+        'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('state'),
+        'extends_table' => 'civicrm_contact',
+        'search_table' => 'contact_a',
+        'serialize' => NULL,
+        'pseudoconstant' => [
+          'table' => 'civicrm_state_province',
+          'keyColumn' => 'id',
+          'labelColumn' => 'name',
+        ],
+        'import' => 1,
+        'data_type' => 'StateProvince',
+        'type' => 1,
+        'html_type' => 'Select State/Province',
+        'text_length' => NULL,
+        'options_per_line' => NULL,
+        'is_search_range' => '0',
+      ],
+      $this->getCustomFieldName('multi_state') => [
+        'id' => $this->getCustomFieldID('multi_state'),
+        'label' => 'State-multi',
+        'headerPattern' => '//',
+        'title' => 'State-multi',
+        'custom_field_id' => $this->getCustomFieldID('multi_state'),
+        'groupTitle' => 'Custom Group',
+        'default_value' => NULL,
+        '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' => 0,
+        'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+        'column_name' => $this->getCustomFieldColumnName('multi_state'),
+        'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('multi_state'),
+        'extends_table' => 'civicrm_contact',
+        'search_table' => 'contact_a',
+        'serialize' => 1,
+        'pseudoconstant' => [
+          'table' => 'civicrm_state_province',
+          'keyColumn' => 'id',
+          'labelColumn' => 'name',
+        ],
+        'import' => 1,
+        'data_type' => 'StateProvince',
+        'name' => $this->getCustomFieldName('multi_state'),
+        'type' => 1,
+        'html_type' => 'Select State/Province',
+        'text_length' => NULL,
+        'options_per_line' => NULL,
+        'is_search_range' => '0',
+      ],
+      $this->getCustomFieldName('boolean') => [
+        'id' => $this->getCustomFieldID('boolean'),
+        'label' => 'Yes No',
+        'headerPattern' => '//',
+        'title' => 'Yes No',
+        'custom_field_id' => $this->getCustomFieldID('boolean'),
+        'groupTitle' => 'Custom Group',
+        'default_value' => NULL,
+        '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' => 0,
+        'table_name' => 'civicrm_value_custom_group_' . $customGroupID,
+        'column_name' => $this->getCustomFieldColumnName('boolean'),
+        'where' => 'civicrm_value_custom_group_' . $customGroupID . '.' . $this->getCustomFieldColumnName('boolean'),
+        'extends_table' => 'civicrm_contact',
+        'search_table' => 'contact_a',
+        'import' => 1,
+        'data_type' => 'Boolean',
+        'name' => $this->getCustomFieldName('boolean'),
+        'type' => 16,
+        'html_type' => 'Radio',
+        'text_length' => NULL,
+        'options_per_line' => NULL,
+        'is_search_range' => '0',
+        'serialize' => NULL,
+        'pseudoconstant' => [
+          'callback' => 'CRM_Core_SelectValues::boolean',
+        ],
       ],
     ];
     $this->assertEquals($expected, CRM_Core_BAO_CustomField::getFieldsForImport());