From d0f1a3ab3f40d13f8d8598f9ff9e22505b56d45b Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Tue, 12 Jul 2016 12:27:59 +0530 Subject: [PATCH] CRM-18585 - Fix Smart Group operator --- CRM/Contact/Form/Task/SaveSearch.php | 7 +++- .../phpunit/WebTest/Contact/GroupAddTest.php | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Form/Task/SaveSearch.php b/CRM/Contact/Form/Task/SaveSearch.php index 62f3ee8a92..e0f5610199 100644 --- a/CRM/Contact/Form/Task/SaveSearch.php +++ b/CRM/Contact/Form/Task/SaveSearch.php @@ -180,6 +180,11 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task { //save the search $savedSearch = new CRM_Contact_BAO_SavedSearch(); $savedSearch->id = $this->_id; + $queryParams = $this->get('queryParams'); + // CRM-18585 include selected operator in $savedSearch->form_values + if (!empty($formValues['operator'])) { + $queryParams[] = array('operator', '=', $formValues['operator'], 0, 0); + } // Use the query parameters rather than the form values - these have already been assessed / converted // with the extra knowledge that the form has. // Note that we want to move towards a standardised way of saving the query that is not @@ -187,7 +192,7 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task { // Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the // sql operator syntax at the query layer. if (!$isSearchBuilder) { - $savedSearch->form_values = serialize($this->get('queryParams')); + $savedSearch->form_values = serialize($queryParams); } else { // We want search builder to be able to convert back & forth at the form layer diff --git a/tests/phpunit/WebTest/Contact/GroupAddTest.php b/tests/phpunit/WebTest/Contact/GroupAddTest.php index 8a127f9084..ec044c3255 100644 --- a/tests/phpunit/WebTest/Contact/GroupAddTest.php +++ b/tests/phpunit/WebTest/Contact/GroupAddTest.php @@ -280,4 +280,41 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase { $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']")); } + /** + * CRM-18585 - test to check OR operator on Smart Groups + */ + public function testAddSmartGroup() { + $this->webtestLogin(); + $this->openCiviPage('contact/search/advanced', 'reset=1'); + $this->click("xpath=//input[@value='OR']"); + $this->select('group', 'Advisory Board'); + $this->select('contact_tags', 'Major Donor'); + $this->clickLink("_qf_Advanced_refresh"); + $this->waitForElementPresent("task"); + $count = trim($this->getText("//div[@id='search-status']/table/tbody/tr/td")); + + //create smart group for contacts resulted from OR operator search. + $this->click('radio_ts', 'ts_all'); + $this->click('task'); + $this->select('task', 'label=Group - create smart group'); + $this->waitForPageToLoad($this->getTimeoutMsec()); + $smartGroupTitle = "SmartGroup" . substr(sha1(rand()), 0, 4); + $this->type("title", $smartGroupTitle); + $this->clickLink("_qf_SaveSearch_next-bottom"); + $this->waitForText('crm-notification-container', "Your smart group has been saved as '$smartGroupTitle'"); + $this->clickLink("_qf_Result_done"); + $expectedCount = explode('-', $this->getText("//div[@id='search-status']/table/tbody/tr/td")); + $this->assertEquals($count, trim($expectedCount[1])); + + //Assert the count from Contacts link in Manage Group Page. + $this->openCiviPage('group', 'reset=1'); + $this->waitForElementPresent("xpath=//table/tbody//tr//td/div[contains(text(), \"{$smartGroupTitle} (Smart Group)\")]"); + $this->clickLink("xpath=//table/tbody//tr//td/div[contains(text(), \"{$smartGroupTitle} (Smart Group)\")]/../../td[@class='crm-group-group_links']/span/a[contains(text(), 'Contacts')]"); + $this->waitForElementPresent("xpath=//span[contains(text(), \"Edit Smart Group Search Criteria for {$smartGroupTitle}\")]"); + $this->clickLink("xpath=//a/span[contains(text(), \"Edit Smart Group Search Criteria for {$smartGroupTitle}\")]/"); + $this->waitForElementPresent('search-status'); + $expectedCount = explode('-', $this->getText("//div[@id='search-status']/table/tbody/tr/td")); + $this->assertEquals($count, trim($expectedCount[1])); + } + } -- 2.25.1