Merge pull request #11951 from mydropwizard/open-flash-chart-markup
[civicrm-core.git] / tests / phpunit / WebTest / Contact / GroupAddTest.php
index d6e64fe617c5869fdf8a9ffc97ddc11d1b67ec05..24eb83f78988591184d2cf284a41cadc979d9075 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -73,31 +73,31 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
 
     $this->openCiviPage('group', 'reset=1');
     $this->type('title', $params['name']);
-    $this->click('_qf_Search_refresh');
+    $this->click('title');
     $this->waitForAjaxContent();
-    $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]");
-    $createdBy = $this->getText("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td[3]/a");
-    $this->click("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td[7]//span/a[text()='Settings']");
+    $this->waitForElementPresent("xpath=//table/tbody//tr/td/div[contains(text(), '{$params['name']}')]");
+    $createdBy = $this->getText("xpath=//table/tbody//tr/td[3]/a");
+    $this->click("xpath=//table/tbody//tr/td[7]//span/a[text()='Settings']");
     $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/table[1]/tbody/tr[2]/td[contains(text(), '{$createdBy}')]");
     $this->openCiviPage('group', 'reset=1');
 
     //search groups using created by
     $this->type('created_by', $createdBy);
-    $this->click('_qf_Search_refresh');
+    $this->click('created_by');
 
     //show maximum no. of groups on first result set page
     //as many groups can be created by same creator
     //and checking is done on first result set page
-    $this->waitForVisible("xpath=//table[@class='crm-group-selector no-footer dataTable']");
+    $this->waitForVisible("xpath=//table[@class='crm-group-selector crm-ajax-table dataTable no-footer']");
     $this->select("xpath=//div[@class='dataTables_length']/label/select", '100');
-    $this->waitForVisible("xpath=//table[@class='crm-group-selector no-footer dataTable']");
+    $this->waitForVisible("xpath=//table[@class='crm-group-selector crm-ajax-table dataTable no-footer']");
 
-    $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]");
-    $this->click("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
-    $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
+    $this->waitForElementPresent("xpath=//table/tbody/tr/td/div[contains(text(), '{$params['name']}')]");
+    $this->click("xpath=//table/tbody/tr/td/div[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
+    $this->waitForElementPresent("xpath=//table/tbody/tr/td/div[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
 
     //check link of the contact who created the group
-    $this->clickLink("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody//tr/td[1]/span[contains(text(),'{$params['name']}')]/../following-sibling::td[2]/a", "css=div.crm-summary-display_name", FALSE);
+    $this->clickLink("xpath=//table/tbody//tr/td[1]/div[contains(text(),'{$params['name']}')]/../following-sibling::td[2]/a", "css=div.crm-summary-display_name", FALSE);
     $name = explode(',', $createdBy);
     $name1 = isset($name[1]) ? trim($name[1]) : NULL;
     $name0 = trim($name[0]);
@@ -170,7 +170,7 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
 
     $this->openCiviPage('group', 'reset=1');
     $this->type('title', $params['name']);
-    $this->click('_qf_Search_refresh');
+    $this->click('title');
     $this->waitForTextPresent("Adding new reserved group.");
     // Settings link should NOT be included in selector
     // after search returns with only the reserved group.
@@ -254,8 +254,8 @@ class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
 
     $this->openCiviPage('group', 'reset=1');
     $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div[@class='crm-submit-buttons']/a/span[text()=' Add Group']");
-    $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/span[contains(text(), '{$group}')]");
-    $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/span[text()='{$group}']/../../td[7]/span[1]/a[1]");
+    $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/div[contains(text(), '{$group}')]");
+    $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/div[text()='{$group}']/../../td[7]/span[1]/a[1]");
     $this->waitForPageToLoad($this->getTimeoutMsec());
     $this->clickLink("xpath=//form[@id='Basic']/div[2]/a/span");
     $this->waitForElementPresent("_qf_Basic_refresh");
@@ -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]));
+  }
+
 }