1226, fixed Change log relative date search for creating smart group
authorPradeep Nayak <pradpnayak@gmail.com>
Fri, 30 Aug 2019 20:31:01 +0000 (21:31 +0100)
committerPradeep Nayak <pradpnayak@gmail.com>
Sat, 31 Aug 2019 11:49:23 +0000 (12:49 +0100)
CRM/Contact/BAO/SavedSearch.php
tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php

index b3561a72fed2ab933d3e6386e5958bab7adcd1c9..19942540c58330390218c13ae001d06213a01a16 100644 (file)
@@ -437,7 +437,7 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_
     // 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', 'case_from_relative', 'case_to_relative', 'participant_relative'];
+    $specialDateFields = ['event_relative', 'case_from_relative', 'case_to_relative', 'participant_relative', 'log_date_relative'];
     foreach ($formValues as $id => $value) {
       if ((preg_match('/_date$/', $id) || in_array($id, $specialDateFields)) && !empty($value)) {
         $entityName = strstr($id, '_date', TRUE);
index 52965533db0bbc5faf522c909afaeaed935b3b66..01b45fc6f0fff87cbbc3e9f3ef2a8e43db740efc 100644 (file)
@@ -202,6 +202,30 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase {
     $this->checkArrayEquals($result['relative_dates'], $expectedResult);
   }
 
+  /**
+   * Test if change log relative dates are stored correctly
+   * in civicrm_saved_search table.
+   */
+  public function testRelativeDateChangeLog() {
+    $savedSearch = new CRM_Contact_BAO_SavedSearch();
+    $formValues = [
+      'operator' => 'AND',
+      'log_date_relative' => 'this.month',
+      'radio_ts' => 'ts_all',
+    ];
+    $queryParams = [];
+    CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues);
+    CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues);
+    $savedSearch->form_values = serialize($queryParams);
+    $savedSearch->save();
+
+    $result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'));
+    $expectedResult = [
+      'log' => 'this.month',
+    ];
+    $this->checkArrayEquals($result['relative_dates'], $expectedResult);
+  }
+
   /**
    * Test relative dates
    *