From: jitendrapurohit Date: Tue, 3 Jan 2017 10:13:01 +0000 (+0530) Subject: add unit test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=41e6c841e2aafcca04db4965974cc6c8e9eb4e16;p=civicrm-core.git add unit test --- 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. *