Merge pull request #71 from dpradeep/merge-20140930
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SearchBuilderTest.php
index 6a708b0405023495ee6605866d9820264f44ccd5..16f37032e3eb7f6a2fd389b4f368651b7a181389 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 */
 
 require_once 'CiviTest/CiviSeleniumTestCase.php';
+
+/**
+ * Class WebTest_Contact_SearchBuilderTest
+ */
 class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
 
   protected function setUp() {
@@ -68,6 +72,9 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
   }
 
   // function to create contact with details (contact details, address, Constituent information ...)
+  /**
+   * @param null $firstName
+   */
   function createDetailContact($firstName = NULL) {
 
     if (!$firstName) {
@@ -159,8 +166,8 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     $this->click("_qf_Contact_upload_view");
     $this->waitForPageToLoad($this->getTimeoutMsec());
     $this->_searchBuilder('Email', NULL, NULL, 'IS NULL');
-    $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->type('CRM_Contact_Form_Search_Builder-rows-per-page-select', '100');
+    $this->waitForElementPresent('CRM_Contact_Form_Search_Builder-rows-per-page-select');
     $names = array(
       1 => $firstName1,
       2 => $firstName2,
@@ -176,8 +183,8 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     }
     //searching contacts whose phone field is not empty
     $this->_searchBuilder('Phone', NULL, $firstName, 'IS NOT EMPTY');
-    $this->click("xpath=//div[@class='crm-search-results']/div[4]/a[2]");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->type('CRM_Contact_Form_Search_Builder-rows-per-page-select', '100');
+    $this->waitForElementPresent('CRM_Contact_Form_Search_Builder-rows-per-page-select');
     $this->assertTrue($this->isTextPresent($firstName));
 
     $firstName4 = "AB" . substr(sha1(rand()), 0, 7);
@@ -205,6 +212,13 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     $this->_advancedSearch("this is notes by $firstName8", $firstName8, NULL, NULL, 'note_both', 'notes');
   }
 
+  /**
+   * @param $field
+   * @param null $fieldValue
+   * @param null $name
+   * @param string $op
+   * @param null $count
+   */
   function _searchBuilder($field, $fieldValue = NULL, $name = NULL, $op = '=', $count = NULL) {
     // search builder using contacts(not using contactType)
     $this->openCiviPage("contact/search/builder", "reset=1");
@@ -264,11 +278,18 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     }
   }
 
+  /**
+   * @param null $fieldValue
+   * @param null $name
+   * @param null $contactType
+   * @param null $count
+   * @param $field
+   */
   function _advancedSearch($fieldValue = NULL, $name = NULL, $contactType = NULL, $count = NULL, $field) {
     //advanced search by selecting the contactType
     $this->openCiviPage("contact/search/advanced", "reset=1");
     if (isset($contactType)) {
-      $this->select("id=crmasmSelect0", "value=$contactType");
+      $this->select("id=contact_type", "value=$contactType");
     }
     if (substr($field, 0, 5) == 'note_') {
       $this->click("notes");
@@ -286,7 +307,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     }
     else {
       $this->click("location");
-      $this->waitForElementPresent("xpath=//div[@id='location']/table/tbody/tr[2]/td/table/tbody/tr[4]/td[2]/select");
+      $this->waitForElementPresent("$field");
       if ($contactType == 'Individual') {
         $this->type("$field", $fieldValue);
       }
@@ -309,6 +330,13 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     }
   }
 
+  /**
+   * @param $contactType
+   * @param $name
+   * @param $email
+   * @param null $streetName
+   * @param null $postalCode
+   */
   function _createContact($contactType, $name, $email, $streetName = NULL, $postalCode = NULL) {
     $this->openCiviPage('contact/add', array('reset' => 1, 'ct' => $contactType), '_qf_Contact_cancel');
 
@@ -348,11 +376,6 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
    *
    */
   function testSearchBuilderfinancialType() {
-    // Logging in. Remember to wait for page to load. In most cases,
-    // you can rely on 30000 as the value that allows your test to pass, however,
-    // sometimes your test might fail because of this. In such cases, it's better to pick one element
-    // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
-    // page contents loaded and you can continue your test execution.
     $this->webtestLogin();
 
     // add financial type
@@ -376,8 +399,7 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
         $financialType = $financialTypeName2;
       }
       // create new contact using dialog
-      $firstName = substr(sha1(rand()), 0, 7);
-      $this->webtestNewDialogContact($firstName, 'Contributor', $firstName . '@example.com');
+      $this->createDialogContact();
       $this->select('financial_type_id', $financialType);
       $this->type('total_amount', 100 * $i);
       $this->clickLink('_qf_Contribution_upload_new', '_qf_Contribution_upload_new');
@@ -385,15 +407,14 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
     $this->openCiviPage("contact/search/builder", "reset=1", "_qf_Builder_refresh");
 
     $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName1));
-    $this->click('_qf_Builder_refresh');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_Builder_refresh');
 
     $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
 
     $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
     $this->enterValues(1, 1, 'Contribution', 'Financial Type', NULL, '=', array($financialTypeName2));
-    $this->click('_qf_Builder_refresh');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_Builder_refresh');
+
     $this->assertTrue($this->isTextPresent('3 Contacts'), 'Missing text: ' . '3 Contacts');
 
     $this->click("xpath=//div[@class='crm-accordion-header crm-master-accordion-header']");
@@ -401,8 +422,8 @@ class WebTest_Contact_SearchBuilderTest extends CiviSeleniumTestCase {
       $financialTypeName1,
       $financialTypeName2
     ));
-    $this->click('_qf_Builder_refresh');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_Builder_refresh');
+
     $this->assertTrue($this->isTextPresent('6 Contacts'), 'Missing text: ' . '6 Contacts');
   }