From 31349d27febeaeeeede069f7c630aea4336c0b10 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Fri, 23 Mar 2018 20:59:05 +1300 Subject: [PATCH] CRM-20922 fix support for passing custom date values via url --- CRM/Core/BAO/CustomGroup.php | 14 +----- .../phpunit/CRM/Core/BAO/CustomGroupTest.php | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 2e88e08014..cfd7e05d54 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1726,19 +1726,7 @@ ORDER BY civicrm_custom_group.weight, } } elseif ($field['data_type'] == 'Date') { - if (!empty($value)) { - $time = NULL; - if (!empty($field['time_format'])) { - $time = CRM_Utils_Request::retrieve($fieldName . - '_time', 'String', $form, FALSE, NULL, 'GET'); - } - list($value, $time) = CRM_Utils_Date::setDateDefaults($value . - ' ' . $time); - if (!empty($field['time_format'])) { - $customValue[$fieldName . '_time'] = $time; - } - } - $valid = TRUE; + $valid = CRM_Utils_Rule::date($value); } if ($valid) { diff --git a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php index a68425762a..d14408de15 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomGroupTest.php @@ -613,4 +613,47 @@ class CRM_Core_BAO_CustomGroupTest extends CiviUnitTestCase { $this->customGroupDelete($customGroup['id']); } + /** + * Test that passed dates are extracted from the url when processing custom data. + */ + public function testExtractGetParamsReturnsDates() { + // Create a custom group to contain the custom field. + $groupParams = array( + 'title' => 'My Custom Group', + 'name' => 'my_custom_group', + 'extends' => 'Individual', + 'is_active' => 1, + 'collapse_display' => 1, + ); + $customGroup = $this->customGroupCreate($groupParams); + $customGroupId = $customGroup['id']; + + // Create teh custom field. + $fieldParams = array( + 'custom_group_id' => $customGroupId, + 'label' => 'My Custom Date Field', + 'html_type' => 'Select Date', + 'data_type' => 'Date', + 'is_required' => 1, + 'is_searchable' => 0, + 'is_active' => 1, + 'default_value' => '', + ); + $customField = $this->customFieldCreate($fieldParams); + $customFieldId = $customField['id']; + + // Create a form object. CRM_Core_BAO_CustomGroup::extractGetParams() will + // need this, along with the REQUEST_METHOD and controller too. + $form = new CRM_Contribute_Form_Contribution(); + $_SERVER['REQUEST_METHOD'] = 'GET'; + $form->controller = new CRM_Core_Controller(); + + // Set the value in $_GET, then extract query string params with + $fieldName = 'custom_' . $customFieldId; + $_GET[$fieldName] = '2017-06-13'; + $extractedGetParams = CRM_Core_BAO_CustomGroup::extractGetParams($form, 'Individual'); + + $this->assertEquals($extractedGetParams[$fieldName], '2017-06-13'); + } + } -- 2.25.1