Merge pull request #4764 from rohankatkar/CRM-15615
[civicrm-core.git] / tests / phpunit / CiviTest / CiviSeleniumTestCase.php
index cf0a2ae1cbd50c95fb9147d1efd88a00fcf9c7ff..a9f3587b25926ac0d5ab561efea6eef8d4f9b462 100644 (file)
@@ -215,6 +215,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     }
     $this->open("{$this->sboxPath}civicrm/$url");
     $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->checkForErrorsOnPage();
     if ($waitFor) {
       $this->waitForElementPresent($waitFor);
     }
@@ -230,6 +231,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     // conditional wait for page load e.g for ajax form save
     if ($waitForPageLoad) {
       $this->waitForPageToLoad($this->getTimeoutMsec());
+      $this->checkForErrorsOnPage();
     }
     if ($waitFor) {
       $this->waitForElementPresent($waitFor);
@@ -326,7 +328,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * @param $option_group_name
+   * @param string $option_group_name
    *
    * @return array|int
    */
@@ -400,9 +402,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
       }
     }
     if ($added) {
-      $this->click("_qf_Component_next-bottom");
-      $this->waitForPageToLoad($this->getTimeoutMsec());
-      $this->waitForText('crm-notification-container', "Saved");
+      $this->clickLink("_qf_Component_next-bottom");
+      $this->checkCRMAlert("Saved");
     }
   }
 
@@ -504,19 +505,17 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     //$this->assertContains($sortName, $this->getValue('contact_1'), "autocomplete expected $sortName but didn’t find it in " . $this->getValue('contact_1'));
   }
 
-  /*
-     * 1. By default, when no strtotime arg is specified, sets date to "now + 1 month"
-     * 2. Does not set time. For setting both date and time use webtestFillDateTime() method.
-     * 3. Examples of $strToTime arguments -
-     *        webtestFillDate('start_date',"now")
-     *        webtestFillDate('start_date',"10 September 2000")
-     *        webtestFillDate('start_date',"+1 day")
-     *        webtestFillDate('start_date',"+1 week")
-     *        webtestFillDate('start_date',"+1 week 2 days 4 hours 2 seconds")
-     *        webtestFillDate('start_date',"next Thursday")
-     *        webtestFillDate('start_date',"last Monday")
-     */
   /**
+   * 1. By default, when no strtotime arg is specified, sets date to "now + 1 month"
+   * 2. Does not set time. For setting both date and time use webtestFillDateTime() method.
+   * 3. Examples of $strToTime arguments -
+   *        webtestFillDate('start_date',"now")
+   *        webtestFillDate('start_date',"10 September 2000")
+   *        webtestFillDate('start_date',"+1 day")
+   *        webtestFillDate('start_date',"+1 week")
+   *        webtestFillDate('start_date',"+1 week 2 days 4 hours 2 seconds")
+   *        webtestFillDate('start_date',"next Thursday")
+   *        webtestFillDate('start_date',"last Monday")
    * @param $dateElement
    * @param null $strToTimeArgs
    */
@@ -535,8 +534,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     $this->click("link=$day");
   }
 
-  // 1. set both date and time.
   /**
+   * 1. set both date and time.
    * @param $dateElement
    * @param null $strToTimeArgs
    */
@@ -998,7 +997,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @param bool $pledges
    * @param bool $recurring
    * @param bool $membershipTypes
-   * @param null $memPriceSetId
+   * @param int $memPriceSetId
    * @param bool $friend
    * @param int $profilePreId
    * @param int $profilePostId
@@ -1332,12 +1331,11 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Function to update default strict rule.
+   * Update default strict rule.
    *
-   * @params  string   $contactType  Contact type
    * @param string $contactType
-   * @param   array $fields Fields to be set for strict rule
-   * @param   Integer $threshold Rule's threshold value
+   * @param array $fields Fields to be set for strict rule
+   * @param int $threshold Rule's threshold value
    */
   function webtestStrictDedupeRuleDefault($contactType = 'Individual', $fields = array(), $threshold = 10) {
     // set default strict rule.
@@ -1607,7 +1605,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
 
   // Request a record from the DB by seachColumn+searchValue. Success if a record is found.
   /**
-   * @param $daoName
+   * @param string $daoName
    * @param $searchValue
    * @param $returnColumn
    * @param $searchColumn
@@ -1625,7 +1623,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
 
   // Request a record from the DB by seachColumn+searchValue. Success if returnColumn value is NULL.
   /**
-   * @param $daoName
+   * @param string $daoName
    * @param $searchValue
    * @param $returnColumn
    * @param $searchColumn
@@ -1641,8 +1639,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
 
   // Request a record from the DB by id. Success if row not found.
   /**
-   * @param $daoName
-   * @param $id
+   * @param string $daoName
+   * @param int $id
    * @param $message
    */
   function assertDBRowNotExist($daoName, $id, $message) {
@@ -1655,7 +1653,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
 
   // Compare a single column value in a retrieved DB record to an expected value
   /**
-   * @param $daoName
+   * @param string $daoName
    * @param $searchValue
    * @param $returnColumn
    * @param $searchColumn
@@ -1676,8 +1674,8 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
 
   // Compare all values in a single retrieved DB record to an array of expected values
   /**
-   * @param $daoName
-   * @param $searchParams
+   * @param string $daoName
+   * @param array $searchParams
    * @param $expectedValues
    */
   function assertDBCompareValues($daoName, $searchParams, $expectedValues) {
@@ -2009,7 +2007,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * @param $name
+   * @param string $name
    * @param $sku
    * @param $amount
    * @param $price
@@ -2017,7 +2015,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @param $financialType
    */
   function addPremium($name, $sku, $amount, $price, $cost, $financialType) {
-    $this->waitForElementPresent("_qf_ManagePremiums_next-bottom");
+    $this->waitForElementPresent("_qf_ManagePremiums_upload-bottom");
     $this->type("name", $name);
     $this->type("sku", $sku);
     $this->click("CIVICRM_QFID_noImage_16");
@@ -2027,7 +2025,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     if ($financialType) {
       $this->select("financial_type_id", "label={$financialType}");
     }
-    $this->click("_qf_ManagePremiums_next-bottom");
+    $this->click("_qf_ManagePremiums_upload-bottom");
     $this->waitForPageToLoad($this->getTimeoutMsec());
   }
 
@@ -2085,6 +2083,9 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @return void
    */
   function customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl, $beforeTriggering = NULL) {
+    // FIXME: Testing a theory that these failures have something to do with permissions
+    $this->webtestLogin('admin');
+
     //add the custom set
     $return = $this->addCustomGroupField($customSets);
 
@@ -2096,8 +2097,11 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     }
 
     $this->openCiviPage($pageUrl['url'], $pageUrl['args']);
-    // Open the page again just to make sure caches are cleared
-    $this->openCiviPage($pageUrl['url'], $pageUrl['args']);
+
+    // FIXME: Try to find out what the heck is going on with these tests
+    $this->waitForAjaxContent();
+    $this->checkForErrorsOnPage();
+
     foreach($return as $values) {
       foreach ($values as $entityType => $customData) {
         //initiate necessary variables
@@ -2127,8 +2131,12 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
             $this->select2($elementName, $entityData);
           }
         }
+        // FIXME: Try to find out what the heck is going on with these tests
+        $this->waitForAjaxContent();
+        $this->checkForErrorsOnPage();
+
         //checking for proper custom data which is loading through ajax
-        $this->waitForElementPresent("xpath=//div[contains(@class, 'custom-group-{$customData['cgtitle']}')]");
+        $this->waitForElementPresent("css=.custom-group-{$customData['cgtitle']}");
         $this->assertElementPresent("xpath=//div[contains(@class, 'custom-group-{$customData['cgtitle']}')]/div[contains(@class, 'crm-accordion-body')]/table/tbody/tr/td[2]/input",
           "The on the fly custom group field is not present for entity : {$entity} => {$entityData}");
       }
@@ -2188,7 +2196,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * function to type and select first occurance of autocomplete
+   * Type and select first occurance of autocomplete
    */
   function select2($fieldName,$label, $multiple = FALSE, $xpath=FALSE) {
     // In the case of chainSelect, wait for options to load
@@ -2220,7 +2228,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * function to select multiple options
+   * Select multiple options
    */
   function multiselect2($fieldid, $params) {
     // In the case of chainSelect, wait for options to load
@@ -2256,7 +2264,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * function to enable or disable Pop-ups via Display Preferences
+   * Enable or disable Pop-ups via Display Preferences
    */
   function enableDisablePopups($enabled = TRUE) {
     $this->openCiviPage('admin/setting/preferences/display', 'reset=1');
@@ -2272,4 +2280,22 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     }
     $this->clickLink("_qf_Display_next-bottom");
   }
+
+  /**
+   * Attempt to get information about what went wrong if we encounter an error when loading a page
+   */
+  function checkForErrorsOnPage() {
+    foreach (array('Access denied', 'Page not found') as $err) {
+      if ($this->isElementPresent("xpath=//h1[contains(., '$err')]")) {
+        $this->fail("'$err' encountered at " . $this->getLocation() . "\nwhile logged in as '{$this->loggedInAs}'");
+      }
+    }
+    if ($this->isElementPresent("xpath=//span[text()='Sorry but we are not able to provide this at the moment.']")) {
+      $msg = '"Fatal Error" encountered at ' . $this->getLocation();
+      if ($this->isElementPresent('css=div.crm-section.crm-error-message')) {
+        $msg .= "\nError Message: " . $this->getText('css=div.crm-section.crm-error-message');
+      }
+      $this->fail($msg);
+    }
+  }
 }