Skip to content

Commit

Permalink
Cleanup following smart group conversions and fix the old name of the…
Browse files Browse the repository at this point in the history
… relationship date relative fields for conversion and add a unit test
  • Loading branch information
seamuslee001 committed Oct 29, 2019
1 parent 1b14ffd commit 434e025
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
5 changes: 1 addition & 4 deletions CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,15 @@ protected function assignTestValue($fieldName, &$fieldDef, $counter) {
*
* @param array $queryParams
* @param array $formValues
* @deprecated
*/
public static function saveRelativeDates(&$queryParams, $formValues) {
// This is required only until all fields are converted to datepicker fields as the new format is truer to the
// form format and simply saves (e.g) custom_3_relative => "this.year"
$relativeDates = ['relative_dates' => []];
$specialDateFields = [
'event_relative',
'participant_relative',
'log_date_relative',
'birth_date_relative',
'deceased_date_relative',
'relation_date_relative',
'relation_action_date_relative',
];
foreach ($formValues as $id => $value) {
Expand Down
3 changes: 0 additions & 3 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,6 @@ public static function relationship(&$form) {
}
CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);

// Add reltionship dates
CRM_Core_Form_Date::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);

// add all the custom searchable fields
CRM_Core_BAO_Query::addCustomFormFields($form, ['Relationship']);
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Upgrade/Incremental/SmartGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function datePickerConversion($fields) {
'case_start_date' => 'case_from',
'case_end_date' => 'case_to',
'mailing_job_start_date' => 'mailing_date',
'relationship_start_date' => 'relation_start_date',
'relationship_end_date' => 'relation_end_date',
'relationship_start_date' => 'relation_start',
'relationship_end_date' => 'relation_end',
];

foreach ($fields as $field) {
Expand Down
29 changes: 29 additions & 0 deletions tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,35 @@ public function testSmartGroupMultipleRelatvieDateConversions() {
$this->assertEquals('this.week', $savedSearch['form_values'][8][2]);
}

/**
* Test converting relationship fields
*/
public function testSmartGroupRelationshipDateConversions() {
$this->callAPISuccess('SavedSearch', 'create', [
'form_values' => [
['relationship_start_date_low', '=', '20191001000000'],
['relationship_start_date_high', '=', '20191031235959'],
['relationship_end_date_low', '=', '20191001000000'],
['relationship_end_date_high', '=', '20191031235959'],
'relative_dates' => [
'relation_start' => 'this.month',
'relation_end' => 'this.month',
],
],
]);
$smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups();
$smartGroupConversionObject->updateGroups([
'datepickerConversion' => [
'relationship_start_date',
'relationship_end_date',
],
]);
$savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []);
$this->assertEquals([], $savedSearch['form_values']['relative_dates']);
$this->assertEquals(['relationship_start_date_relative', '=', 'this.month'], $savedSearch['form_values'][4]);
$this->assertEquals(['relationship_end_date_relative', '=', 'this.month'], $savedSearch['form_values'][5]);
}

/**
* Test conversion of on hold group.
*/
Expand Down

0 comments on commit 434e025

Please sign in to comment.