phpcs - Fix error, "Expected 1 newline at end of file; XXX found".
[civicrm-core.git] / tests / phpunit / WebTest / Export / ExportCiviSeleniumTestCase.php
index e596c60ecaf506639fbd3faaba3f01cec0f3e0ca..b52b745892d8444e278a068be698d19952d56dc3 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -32,19 +32,15 @@ require_once 'CiviTest/CiviSeleniumTestCase.php';
 class ExportCiviSeleniumTestCase extends CiviSeleniumTestCase {
 
   /**
-   * Function to download CSV file.
+   * Download CSV file.
    *
-   * @params string $selector element selector(download button in most of the cases).
-   * @params sting  $fileName file name to be download.
-   * @params string $downloadDir download dir.
-   *
-   * @param $selector
-   * @param string $fileName
-   * @param string $downloadDir
+   * @param string $selector element selector(download button in most of the cases).
+   * @param string  $fileName file name to be download.
+   * @param string $downloadDir download dir.
    *
    * @return string downloaded file path.
    */
-  function downloadCSV($selector, $fileName = 'CiviCRM_Contact_Search.csv', $downloadDir = '/tmp') {
+  public function downloadCSV($selector, $fileName = 'CiviCRM_Contact_Search.csv', $downloadDir = '/tmp') {
     // File download path.
     $file = "{$downloadDir}/{$fileName}";
 
@@ -53,28 +49,26 @@ class ExportCiviSeleniumTestCase extends CiviSeleniumTestCase {
       @unlink($file);
     }
 
-    // Download file.
-    // File will automatically download without confirmation.
     $this->click($selector);
-    // Because it tends to cause problems, all uses of sleep() must be justified in comments
-    // Sleep should never be used for wait for anything to load from the server
-    // FIXME: consider doing the following assertion in a while loop
-    // with a more reasonable sleep time of 2 seconds per loop iteration
-    sleep(20);
-
-    // File was downloaded?
-    $this->assertTrue(file_exists($file), "CSV {$file} was not downloaded.");
 
-    return $file;
+    // Wait for file to be downloaded
+    for ($i=1; $i<15; ++$i) {
+      sleep(2);
+      if (file_exists($file)) {
+        return $file;
+      }
+    }
+    // Timeout
+    $this->fail("CSV {$file} was not downloaded.");
   }
 
   /**
-   * Function to read CSV file and fire provided assertions.
+   * Read CSV file and fire provided assertions.
    *
-   * @params string $file         file path of CSV file.
-   * @params array  $checkHeaders check first row of csv
+   * @param string $file         file path of CSV file.
+   * @param array  $checkColumns check first row of csv
    *                              independent of index.
-   * @params array  $checkRows    array of header and rows according to row index
+   * @param array  $checkRows    array of header and rows according to row index
    *                              eg: array(
    *                                    1 => array(
       // Row index 1
@@ -88,11 +82,10 @@ class ExportCiviSeleniumTestCase extends CiviSeleniumTestCase {
    *                                      'Last Name'  => 'mayekar'
    *                                    ),
    *                                   );
-   * @params int   $rowCount count rows (excluding header row).
-   * @params array $settings used for override settings.
+   * @param int   $rowCount count rows (excluding header row).
+   * @param array $settings used for override settings.
    */
-  function reviewCSV($file, $checkColumns = array(
-    ), $checkRows = array(), $rowCount = 0, $settings = array()) {
+  public function reviewCSV($file, $checkColumns = array(), $checkRows = array(), $rowCount = 0, $settings = array()) {
     // Check file exists before proceed.
     $this->assertTrue(($file && file_exists($file)), "Not able to locate {$file}.");
 
@@ -160,4 +153,3 @@ class ExportCiviSeleniumTestCase extends CiviSeleniumTestCase {
     }
   }
 }
-