Merge pull request #4664 from aydun/CRM-15681-master
[civicrm-core.git] / tests / phpunit / WebTest / Contact / AdvancedSearchTest.php
index 3a1bb9339f3a5f9367feae9040e493e03b508862..083bbe5de626b2fded129cf1e678f3f4ac0323c1 100644 (file)
@@ -56,78 +56,60 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->createDetailContact($firstName);
 
     // go to group tab and add to new group
-    $this->click("css=li#tab_group a");
-    $this->waitForElementPresent("_qf_GroupContact_next");
+    $this->clickAjaxLink("css=li#tab_group a", "_qf_GroupContact_next");
     $this->select("group_id", "$groupName");
-    $this->click("_qf_GroupContact_next");
+    $this->clickAjaxLink("_qf_GroupContact_next");
+    $this->waitForText('crm-notification-container', "Contact has been added to '$groupName'");
 
     // go to tag tab and add to new tag
-    $this->click("css=li#tab_tag a");
-    $this->waitForElementPresent("css=div#tagtree");
-    $this->click("xpath=//ul/li/label[text()=\"$tagName\"]");
-    $this->waitForElementPresent("css=.success");
-
-    // is status message correct?
-    $this->waitForTextPresent("Saved");
-    $this->waitForText('crm-notification-container', "Saved");
-
-    // go to event tab and register for event ( auto add activity and contribution )
-    $this->click("css=li#tab_participant a");
-    $this->waitForElementPresent("link=Add Event Registration");
-    $this->click("link=Add Event Registration");
+    $this->clickAjaxLink("css=li#tab_tag a", "css=div#tagtree");
+    $this->click("xpath=//ul/li/span/label[text()=\"$tagName\"]");
+    $this->checkCRMStatus();
+
+    // register for event ( auto add activity and contribution )
+    $this->clickPopupLink("link=Register for Event");
     $this->waitForText('s2id_event_id', "- select event -");
-    // fall fundraiser dinner event label is variable
     $this->select2("event_id", "Fall Fundraiser Dinner");
     $this->waitForElementPresent("receipt_text");
     $this->multiselect2("role_id", array('Volunteer'));
-    $this->click("CIVICRM_QFID_17_4");
+    // Select $100 fee
+    $this->click("css=input[data-amount=100]");
     $this->check("record_contribution");
     $this->waitForElementPresent("contribution_status_id");
     $this->select("payment_instrument_id", "Check");
     $this->type("check_number", "chqNo$firstName");
     $this->type("trxn_id", "trid$firstName");
-    $this->click("_qf_Participant_upload-bottom");
-    $this->waitForElementPresent("link=Add Event Registration");
+    $this->clickAjaxLink("_qf_Participant_upload-bottom", "link=Add Event Registration");
     $this->waitForText('crm-notification-container', "Event registration for $firstName adv$firstName has been added");
 
-    // go to pledge tab and add pledge
-    $this->click("css=li#tab_pledge a");
-    $this->waitForElementPresent("link=Add Pledge");
-    $this->click("link=Add Pledge");
+    // Add pledge
+    $this->clickPopupLink("link=Add Pledge");
     $this->waitForElementPresent("contribution_page_id");
     $this->type("amount", "200");
     $this->type("installments", "5");
     $this->type("frequency_interval", "1");
     $this->select("frequency_unit", "month(s)");
-    $this->click("_qf_Pledge_upload-bottom");
-    $this->waitForElementPresent("link=Add Pledge");
-
+    $this->clickAjaxLink("_qf_Pledge_upload-bottom", "link=Add Pledge");
     $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
 
-    // go to Membership tab and add membership
-    $this->click("css=li#tab_member a");
-    $this->waitForElementPresent("link=Add Membership");
-    $this->clickLink("link=Add Membership", "_qf_Membership_cancel-bottom", FALSE);
+    // Add membership
+    $this->clickPopupLink("link=Add Membership", "_qf_Membership_cancel-bottom");
     //let the organisation be default (Default Organization)
     $this->select("membership_type_id[0]", "value=1");
     $this->click("membership_type_id[1]");
     $this->select("membership_type_id[1]", "Student");
     $this->type("source", "membership source$firstName");
-    $this->clickLink("_qf_Membership_upload-bottom", "link=Add Membership", FALSE);
-
+    $this->clickAjaxLink("_qf_Membership_upload-bottom");
     $this->waitForText('crm-notification-container', "Student membership for $firstName adv$firstName has been added");
 
-    // go to relationship tab and add relationship
-    $this->click("css=li#tab_rel a");
-    $this->waitForElementPresent("link=Add Relationship");
-    $this->click("link=Add Relationship");
-    $this->waitForElementPresent("_qf_Relationship_cancel");
+    // Add relationship
+    $this->clickPopupLink("link=Add Relationship", "_qf_Relationship_cancel");
     $this->select2("relationship_type_id", "Employee of");
     $this->waitForElementPresent("xpath=//input[@id='related_contact_id'][@placeholder='- select organization -']");
     $this->select2("related_contact_id", "Default", TRUE);
     $this->webtestFillDate("start_date", "-1 day");
     $this->webtestFillDate("end_date", "+1 day");
-    $this->click('_qf_Relationship_upload-bottom');
+    $this->clickAjaxLink('_qf_Relationship_upload-bottom', NULL);
     $this->waitForText('crm-notification-container', "Relationship created.");
 
     //-------------- advance search --------------
@@ -191,11 +173,9 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
   function testActivitySearchByTypeTest() {
     $this->webtestLogin();
     $this->openCiviPage('contact/search/advanced', 'reset=1');
-    $this->click("activity");
-    $this->waitForElementPresent('activity_subject');
+    $this->clickAjaxLink("activity", 'activity_subject');
     $this->check("xpath=//div[@id='Activity']//div/label[text()='Tell a Friend']/../input");
-    $this->click("_qf_Advanced_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Advanced_refresh");
     $count = explode(" ", trim($this->getText("xpath=//div[@id='search-status']/table/tbody/tr/td")));
     $count = $count[0];
     $this->assertTrue(is_numeric($count), "The total count of search results not found");
@@ -217,7 +197,7 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
 
         //go to next page
         $this->click("xpath=//div[@class='crm-search-results']/div[@class='crm-pager']/span[@class='crm-pager-nav']/a[@title='next page']");
-        $this->waitForElementPresent("Go");
+        $this->waitForElementPresent("task");
         $j = $j + $subTotal;
       }
 
@@ -232,7 +212,7 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
 
   //function to check match for sumbit Advance Search
   /**
-   * @param $firstName
+   * @param string $firstName
    */
   function submitSearch($firstName) {
     $this->clickLink("_qf_Advanced_refresh");
@@ -244,64 +224,31 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->click("xpath=//form[@id='Advanced']//div[2]/div/div[1]");
   }
 
-  // function to fill auto complete
-  /**
-   * @param $text
-   * @param $elementId
-   */
-  function fillAutoComplete($text, $elementId) {
-    $this->click("$elementId");
-    $this->type("$elementId", "$text");
-    $this->typeKeys("$elementId", "$text");
-    $this->waitForElementPresent("css=div.ac_results li");
-    $this->click("css=div.ac_results li");
-    $this->assertContains($text, $this->getValue("$elementId"),
-      "autocomplete expected $text but didn’t find it in " . $this->getValue("$elementId")
-    );
-  }
-
   /*
    * Check for CRM-14952
    */
   function testStateSorting() {
     $this->webtestLogin();
-    $this->openCiviPage('contact/search/advanced', 'reset=1');
-    $this->waitForElementPresent('group');
+    $this->openCiviPage('contact/search/advanced', 'reset=1', 'group');
     $this->select2("group", "Newsletter", TRUE);
+    $this->select2("group", "Summer", TRUE);
     $this->select2("group", "Advisory", TRUE);
-    $this->click("location");
-    $this->waitForElementPresent('country');
+    $this->clickAjaxLink("location", 'country');
     $this->select2("country", "United States", False);
-    $this->click("_qf_Advanced_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $stateBeforeSort = $this->getText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
-    $this->click("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->assertElementNotContainsText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]", $stateBeforeSort);
-    $this->click("xpath=//form[@id='Advanced']//div//div[contains(text(),'Edit Search Criteria')]/../div");
-    $this->waitForElementPresent('group');
-    $this->select2("group", "Summer", TRUE);
     $this->waitForElementPresent('state_province');
-    $this->select2("state_province", "Ohio", TRUE);
-    $this->select2("state_province", "New York", TRUE);
-    $this->select2("state_province", "New Mexico", TRUE);
-    $this->select2("state_province", "Mississippi", TRUE);
-    $this->select2("state_province", "Connecticut", TRUE);
-    $this->select2("state_province", "Georgia", TRUE);
-    $this->select2("state_province", "New Jersey", TRUE);
-    $this->select2("state_province", "Texas", TRUE);
-    $this->click("_qf_Advanced_refresh");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->multiselect2("state_province", array("Ohio", "New York", "New Mexico", "Connecticut", "Georgia", "New Jersey", "Texas"));
+    $this->clickLink("_qf_Advanced_refresh", "xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
+
     $stateBeforeSort = $this->getText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]");
     $this->click("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("xpath=//div[@class='crm-search-results']//table/thead/tr//th/a[contains(text(),'State')]");
     $this->assertElementNotContainsText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[6]", $stateBeforeSort);
   }
 
   // function to fill basic search detail
   /**
-   * @param $firstName
-   * @param $groupName
+   * @param string $firstName
+   * @param string $groupName
    * @param $tagName
    */
   function addBasicSearchDetail($firstName, $groupName, $tagName) {
@@ -331,8 +278,7 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
    */
   function addAddressSearchDetail($firstName) {
     // select location type (home and main)
-    $this->click("xpath=//div[@id='location']/table/tbody/tr[1]/td[1]//label[text()='Home']");
-    $this->click("xpath=//div[@id='location']/table/tbody/tr[1]/td[1]//label[text()='Main']");
+    $this->multiselect2('location_type', array('Home', 'Main'));
     // fill street address
     $this->type("street_address", "street 1 $firstName");
     // fill city
@@ -343,7 +289,8 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     // select country
     $this->select("country", "United States");
     // select state-province
-    $this->select("state_province", "Alaska");
+    $this->waitForElementPresent('state_province');
+    $this->select2("state_province", "Alaska", TRUE);
   }
 
   // function to fill activity search block in advance search
@@ -549,8 +496,7 @@ class WebTest_Contact_AdvancedSearchTest extends CiviSeleniumTestCase {
     $this->webtestFillDate("deceased_date", "now");
 
     // save contact
-    $this->click("_qf_Contact_upload_view");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink("_qf_Contact_upload_view", 'css=.crm-summary-display_name');
     $this->assertElementContainsText('css=.crm-summary-display_name', "$firstName adv$firstName");
   }
 }