Merge pull request #5192 from colemanw/CRM-15988
[civicrm-core.git] / tests / phpunit / CiviTest / CiviSeleniumTestCase.php
index 9b708b70dd657608c72e2a85800fd143116cd9a2..4df99add862a3f3a91c482066bc04305979e68c9 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *  Include configuration
@@ -49,7 +49,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   protected $loggedInAs = NULL;
 
   /**
-   *  Constructor
+   *  Constructor.
    *
    *  Because we are overriding the parent class constructor, we
    *  need to show the same arguments as exist in the constructor of
@@ -103,6 +103,9 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     }
   }
 
+  /**
+   * @return string
+   */
   protected function prepareTestSession() {
     $result = parent::prepareTestSession();
 
@@ -151,7 +154,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Authenticate as drupal user
+   * Authenticate as drupal user.
    * @param $user : (str) the key 'user' or 'admin', or a literal username
    * @param $pass : (str) if $user is a literal username and not 'user' or 'admin', supply the password
    */
@@ -226,7 +229,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Click on a link or button
+   * Click on a link or button.
    * Wait for the page to load
    * Wait for an element to be present
    * @param $element
@@ -246,7 +249,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Click a link or button and wait for an ajax dialog to load
+   * Click a link or button and wait for an ajax dialog to load.
    * @param string $element
    * @param string $waitFor
    */
@@ -258,7 +261,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Click a link or button and wait for ajax content to load or refresh
+   * Click a link or button and wait for ajax content to load or refresh.
    * @param string $element
    * @param string $waitFor
    */
@@ -286,7 +289,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Wait for all ajax snippets to finish loading
+   * Wait for all ajax snippets to finish loading.
    */
   public function waitForAjaxContent() {
     $this->waitForElementNotPresent('css=.blockOverlay');
@@ -299,7 +302,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Call the API on the local server
+   * Call the API on the local server.
    * (kind of defeats the point of a webtest - see CRM-11889)
    * @param $entity
    * @param $action
@@ -317,7 +320,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Call the API on the remote server
+   * Call the API on the remote server.
    * Experimental - currently only works if permissions on remote site allow anon user to access ajax api
    * @see CRM-11889
    * @param $entity
@@ -402,7 +405,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Ensures the required CiviCRM components are enabled
+   * Ensures the required CiviCRM components are enabled.
    * @param $components
    */
   public function enableComponents($components) {
@@ -424,7 +427,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Add a contact with the given first and last names and either a given email
+   * Add a contact with the given first and last names and either a given email.
    * (when specified), a random email (when true) or no email (when unspecified or null).
    *
    * @param string $fname
@@ -549,7 +552,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     $mon = date('n', $timeStamp) - 1;
     $day = date('j', $timeStamp);
 
-    $this->click("{$dateElement}_display");
+    $this->click("xpath=//input[starts-with(@id, '{$dateElement}_display_')]");
     $this->waitForElementPresent("css=div#ui-datepicker-div.ui-datepicker div.ui-datepicker-header div.ui-datepicker-title select.ui-datepicker-month");
     $this->select("css=div#ui-datepicker-div.ui-datepicker div.ui-datepicker-header div.ui-datepicker-title select.ui-datepicker-month", "value=$mon");
     $this->select("css=div#ui-datepicker-div div.ui-datepicker-header div.ui-datepicker-title select.ui-datepicker-year", "value=$year");
@@ -602,7 +605,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Types text into a ckEditor rich text field in a form
+   * Types text into a ckEditor rich text field in a form.
    *
    * @param string $fieldName
    *   Form field name (as assigned by PHP buildForm class).
@@ -635,7 +638,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Types option label and name into a table of multiple choice options
+   * Types option label and name into a table of multiple choice options.
    * (for price set fields of type select, radio, or checkbox)
    * TODO: extend for custom field multiple choice table input
    *
@@ -663,7 +666,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Use a contact EntityRef field to add a new contact
+   * Use a contact EntityRef field to add a new contact.
    * @param string $field
    *   Selector.
    * @param string $contactType
@@ -708,7 +711,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @param int $row
    * @param string $prefix
    */
-  function webtestNewDialogContact(
+  public function webtestNewDialogContact(
     $fname = 'Anthony', $lname = 'Anderson', $email = 'anthony@anderson.biz',
     $type = 4, $selectId = 's2id_contact_id', $row = 1, $prefix = '') {
     // 4 - Individual profile
@@ -746,7 +749,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Generic function to check that strings are present in the page
+   * Generic function to check that strings are present in the page.
    *
    * @strings  array    array of strings or a single string
    *
@@ -784,7 +787,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Returns a single argument from the url query
+   * Returns a single argument from the url query.
    * @param $arg
    * @param null $url
    * @return null
@@ -809,7 +812,6 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @throws PHPUnit_Framework_AssertionFailedError
    * @return int
    */
-
   public function webtestAddPaymentProcessor($processorName = 'Test Processor', $processorType = 'Dummy', $processorSettings = NULL, $financialAccount = 'Deposit Bank Account') {
     if (!$processorName) {
       $this->fail("webTestAddPaymentProcessor requires $processorName.");
@@ -936,7 +938,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     if (!$filePath) {
       $filePath = '/tmp/testfile_' . substr(sha1(rand()), 0, 7) . '.txt';
       $fp = @fopen($filePath, 'w');
-      fputs($fp, 'Test file created by selenium test.');
+      fwrite($fp, 'Test file created by selenium test.');
       @fclose($fp);
     }
 
@@ -1067,7 +1069,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @return null
    *   of newly created online contribution page.
    */
-  function webtestAddContributionPage(
+  public function webtestAddContributionPage(
     $hash = NULL,
     $rand = NULL,
     $pageTitle = NULL,
@@ -1627,8 +1629,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   /**
    * @return bool
    */
-  static
-  public function checkDoLocalDBTest() {
+  public static function checkDoLocalDBTest() {
     if (defined('CIVICRM_WEBTEST_LOCAL_DB') &&
       CIVICRM_WEBTEST_LOCAL_DB
     ) {
@@ -1639,7 +1640,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Generic function to compare expected values after an api call to retrieved
+   * Generic function to compare expected values after an api call to retrieved.
    * DB values.
    *
    * @param string $daoName
@@ -1649,7 +1650,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @param array $match
    *   Associative array of field name => expected value. Empty if asserting
    *                      that a DELETE occurred
-   * @param boolean $delete
+   * @param bool $delete
    *   are we checking that a DELETE action occurred?
    */
   public function assertDBState($daoName, $id, $match, $delete = FALSE) {
@@ -1699,7 +1700,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Compare all values in a single retrieved DB record to an array of expected values
+   * Compare all values in a single retrieved DB record to an array of expected values.
    * @param string $daoName
    * @param array $searchParams
    * @param $expectedValues
@@ -1720,7 +1721,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Add new Financial Account
+   * Add new Financial Account.
    * @param $financialAccountTitle
    * @param bool $financialAccountDescription
    * @param bool $accountingCode
@@ -1732,7 +1733,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @param bool $taxRate
    * @param bool $isDefault
    */
-  function _testAddFinancialAccount(
+  public function _testAddFinancialAccount(
     $financialAccountTitle,
     $financialAccountDescription = FALSE,
     $accountingCode = FALSE,
@@ -1810,7 +1811,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Edit Financial Account
+   * Edit Financial Account.
    * @param $editfinancialAccount
    * @param bool $financialAccountTitle
    * @param bool $financialAccountDescription
@@ -1823,7 +1824,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
    * @param bool $taxRate
    * @param bool $isDefault
    */
-  function _testEditFinancialAccount(
+  public function _testEditFinancialAccount(
     $editfinancialAccount,
     $financialAccountTitle = FALSE,
     $financialAccountDescription = FALSE,
@@ -1909,7 +1910,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Delete Financial Account
+   * Delete Financial Account.
    * @param $financialAccountTitle
    */
   public function _testDeleteFinancialAccount($financialAccountTitle) {
@@ -1921,7 +1922,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Verify data after ADD and EDIT
+   * Verify data after ADD and EDIT.
    * @param $verifyData
    */
   public function _assertFinancialAccount($verifyData) {
@@ -2000,7 +2001,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Give the specified permissions
+   * Give the specified permissions.
    * Note: this function logs in as 'admin' (logging out if necessary)
    * @param $permission
    */
@@ -2080,7 +2081,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Ensure we have a default mailbox set up for CiviMail
+   * Ensure we have a default mailbox set up for CiviMail.
    */
   public function setupDefaultMailbox() {
     $this->openCiviPage('admin/mailSettings', 'action=update&id=1&reset=1');
@@ -2241,7 +2242,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Type and select first occurance of autocomplete
+   * Type and select first occurance of autocomplete.
    * @param $fieldName
    * @param $label
    * @param bool $multiple
@@ -2277,7 +2278,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Select multiple options
+   * Select multiple options.
    * @param $fieldid
    * @param $params
    */
@@ -2337,7 +2338,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
   }
 
   /**
-   * Attempt to get information about what went wrong if we encounter an error when loading a page
+   * Attempt to get information about what went wrong if we encounter an error when loading a page.
    */
   public function checkForErrorsOnPage() {
     foreach (array('Access denied', 'Page not found') as $err) {
@@ -2353,4 +2354,5 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
       $this->fail($msg);
     }
   }
+
 }