<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
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 $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}";
@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
* '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}.");
}
}
}
-