From 3a431eaa0209a1093b7c308fbfac24b7ba782051 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 2 Nov 2019 08:31:07 +1100 Subject: [PATCH] Switch default handling so that we convert to created_date field by default as that matches the current form code and extend unit test to cover senario where no radio button was filled in --- CRM/Upgrade/Incremental/SmartGroups.php | 11 +++++---- .../CRM/Upgrade/Incremental/BaseTest.php | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/CRM/Upgrade/Incremental/SmartGroups.php b/CRM/Upgrade/Incremental/SmartGroups.php index 2bd5329d99..7ba68e3894 100644 --- a/CRM/Upgrade/Incremental/SmartGroups.php +++ b/CRM/Upgrade/Incremental/SmartGroups.php @@ -256,16 +256,17 @@ class CRM_Upgrade_Incremental_SmartGroups { } + /** + * Convert the log_date saved search date fields to their correct name + * default to switching to created_date as that is what the code did originally + */ public function renameLogFields() { - $addedDate = FALSE; + $addedDate = TRUE; foreach ($this->getSearchesWithField('log_date') as $savedSearch) { $formValues = $savedSearch['form_values']; foreach ($formValues as $index => $formValue) { if (isset($formValue[0]) && $formValue[0] === 'log_date') { - if ($formValue[2] == 1) { - $addedDate = TRUE; - } - else { + if ($formValue[2] == 2) { $addedDate = FALSE; } } diff --git a/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php b/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php index 63ebb74665..e5a1067d91 100644 --- a/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php +++ b/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php @@ -259,6 +259,22 @@ class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase { ['log_date_low', '=', '20191001000000'], ], ]); + // On the original search form you didn't need to select the log_date radio + // If it wasn't selected it defaulted to created_date filtering. + $this->callAPISuccess('SavedSearch', 'create', [ + 'form_values' => [ + ['log_date_low', '=', '20191001000000'], + ['log_date_high', '=', '20191031235959'], + 'relative_dates' => [ + 'log' => 'this.month', + ], + ], + ]); + $this->callAPISuccess('SavedSearch', 'create', [ + 'form_values' => [ + ['log_date_low', '=', '20191001000000'], + ], + ]); $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); $smartGroupConversionObject->renameLogFields(); $smartGroupConversionObject->updateGroups([ @@ -289,6 +305,14 @@ class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase { 1 => ['modified_date_low', '=', '2019-10-01 00:00:00'], 2 => ['modified_date_relative', '=', 0], ], + 5 => [ + 'relative_dates' => [], + 2 => ['created_date_relative', '=', 'this.month'], + ], + 6 => [ + 0 => ['created_date_low', '=', '2019-10-01 00:00:00'], + 1 => ['created_date_relative', '=', 0], + ], ]; } -- 2.25.1