From 41e6c841e2aafcca04db4965974cc6c8e9eb4e16 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 3 Jan 2017 15:43:01 +0530 Subject: [PATCH] add unit test --- CRM/Contact/Form/Search/Advanced.php | 5 ++++ .../CRM/Contact/BAO/SavedSearchTest.php | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 822356e939..6f46ef9df2 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -194,6 +194,11 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { * the default array reference */ public function setDefaultValues() { + // Set ssID for unit tests. + if (empty($this->_ssID)) { + $this->_ssID = $this->get('ssID'); + } + $defaults = array_merge($this->_formValues, array( 'privacy_toggle' => 1, 'operator' => 'AND', diff --git a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php index 18be1916bc..2338085cc9 100644 --- a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php +++ b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php @@ -56,6 +56,31 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { )); } + /** + * Test setDefaults for privacy radio buttons. + */ + public function testDefaultValues() { + $sg = new CRM_Contact_Form_Search_Advanced(); + $sg->controller = new CRM_Core_Controller(); + $sg->_formValues = array( + 'group_search_selected' => 'group', + 'privacy_options' => array('do_not_email'), + 'privacy_operator' => 'OR', + 'privacy_toggle' => 2, + 'operator' => 'AND', + 'component_mode' => 1, + ); + CRM_Core_DAO::executeQuery( + "INSERT INTO civicrm_saved_search (form_values) VALUES('" . serialize($sg->_formValues) . "')" + ); + $ssID = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'); + $sg->set('ssID', $ssID); + + $defaults = $sg->setDefaultValues(); + + $this->checkArrayEquals($defaults, $sg->_formValues); + } + /** * Test fixValues function. * -- 2.25.1