<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
*/
class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
- /*
- * Function to test csv import for each component.
- *
- * @params string $component component name ( Event, Contribution, Membership, Activity etc)
- * @params array $headers csv data headers
- * @params array $rows csv data rows
- * @params string $contactType contact type
- * @params string $mode import mode
- * @params array $fieldMapper select mapper fields while import
- * @params array $other other parameters
- * useMappingName : to reuse mapping
-
- * dateFormat : date format of data
- * checkMapperHeaders : to override default check mapper headers
- * saveMapping : save current mapping?
- * saveMappingName : to override mapping name
- *
- */
/**
- * @param $component
- * @param $headers
- * @param $rows
+ * Test csv import for each component.
+ *
+ * @param string $component
+ * Component name ( Event, Contribution, Membership, Activity etc).
+ * @param array $headers
+ * Csv data headers.
+ * @param array $rows
+ * Csv data rows.
* @param string $contactType
+ * Contact type.
* @param string $mode
+ * Import mode.
* @param array $fieldMapper
+ * Select mapper fields while import.
* @param array $other
+ * Other parameters.
+ * useMappingName : to reuse mapping
+ * dateFormat : date format of data
+ * checkMapperHeaders : to override default check mapper headers
+ * saveMapping : save current mapping?
+ * saveMappingName : to override mapping name
*/
- function importCSVComponent($component,
+ function importCSVComponent(
+ $component,
$headers,
$rows,
$contactType = 'Individual',
- $mode = 'Skip',
+ $mode = 'Skip',
$fieldMapper = array(),
- $other = array()
+ $other = array()
) {
// Go to contact import page.
- $this->open($this->sboxPath . $this->_getImportComponentUrl($component));
-
- $this->waitForPageToLoad($this->getTimeoutMsec());
-
- // check for upload field.
- $this->waitForElementPresent("uploadFile");
+ $this->openCiviPage($this->_getImportComponentUrl($component), 'reset=1', "uploadFile");
// Create csv file of sample data.
$csvFile = $this->webtestCreateCSV($headers, $rows);
}
}
- /*
- * Function to test contact import.
- *
- * @params array $headers csv data headers
- * @params array $rows csv data rows
- * @params string $contactType contact type
- * @params string $mode import mode
- * @params array $fieldMapper select mapper fields while import
- * @params array $other other parameters
- * contactSubtype : import for selected Contact Subtype
-
- * useMappingName : to reuse mapping
- * dateFormat : date format of data
- * checkMapperHeaders : to override default check mapper headers
- * saveMapping : save current mapping?
- * saveMappingName : to override mapping name
- * createGroup : create new group?
- * createGroupName : to override new Group name
- * createTag : create new tag?
- * createTagName : to override new Tag name
- * selectGroup : select existing group for contacts
- * selectTag : select existing tag for contacts
- * callbackImportSummary : function to override default import summary assertions
- *
- * @params string $type import type (csv/sql)
- * @todo:currently only supports csv, need to work on sql import
-
- */
/**
- * @param $headers
- * @param $rows
+ * Test contact import.
+ *
+ * @param array $headers
+ * Csv data headers.
+ * @param array $rows
+ * Csv data rows.
* @param string $contactType
+ * Contact type.
* @param string $mode
+ * Import mode.
* @param array $fieldMapper
+ * Select mapper fields while import.
* @param array $other
+ * Other parameters.
+ * contactSubtype : import for selected Contact Subtype
+ * useMappingName : to reuse mapping
+ * dateFormat : date format of data
+ * checkMapperHeaders : to override default check mapper headers
+ * saveMapping : save current mapping?
+ * saveMappingName : to override mapping name
+ * createGroup : create new group?
+ * createGroupName : to override new Group name
+ * createTag : create new tag?
+ * createTagName : to override new Tag name
+ * selectGroup : select existing group for contacts
+ * selectTag : select existing tag for contacts
+ * callbackImportSummary : function to override default import summary assertions
+ *
* @param string $type
+ * Import type (csv/sql).
+ * @todo:currently only supports csv, need to work on sql import
*/
- function importContacts($headers, $rows, $contactType = 'Individual', $mode = 'Skip', $fieldMapper = array(
- ), $other = array(), $type = 'csv') {
+ public function importContacts($headers, $rows, $contactType = 'Individual', $mode = 'Skip', $fieldMapper = array(), $other = array(), $type = 'csv') {
// Go to contact import page.
$this->openCiviPage("import/contact", "reset=1", "uploadFile");
// Select contact subtype
if (isset($other['contactSubtype'])) {
- if ($contactType != 'Individual') {
- // 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: this is bad, using sleep to wait for AJAX
- // Need to use a better way to wait for contact subtypes to repopulate
- sleep(5);
- }
- $this->waitForElementPresent("subType");
- $this->select('subType', 'label=' . $other['contactSubtype']);
+ $this->waitForElementPresent("xpath=//div[@id='common-form-controls']/table/tbody/tr[1]/td[2]/span");
+ $this->select('subType', $other['contactSubtype']);
}
if (isset($other['dedupe'])) {
}
// Submit form.
- $this->click('_qf_DataSource_upload');
- $this->waitForPageToLoad($this->getTimeoutMsec());
+ $this->clickLink('_qf_DataSource_upload');
if (isset($other['checkMapperHeaders'])) {
$checkMapperHeaders = $other['checkMapperHeaders'];
$this->waitForPageToLoad($this->getTimeoutMsec());
// Check confirmation alert.
- $this->assertTrue((bool)preg_match("/^Are you sure you want to Import now[\s\S]$/", $this->getConfirmation()));
+ $this->assertTrue((bool) preg_match("/^Are you sure you want to Import now[\s\S]$/", $this->getConfirmation()));
$this->chooseOkOnNextConfirmation();
$this->waitForPageToLoad($this->getTimeoutMsec());
}
if (!empty($other['callbackImportSummary']) && is_callable(array(
- $this, $other['callbackImportSummary']))) {
+ $this,
+ $other['callbackImportSummary']
+ ))
+ ) {
$callbackImportSummary = $other['callbackImportSummary'];
$this->$callbackImportSummary($originalHeaders, $originalRows, $checkSummary);
}
}
}
- /*
- * Helper function to get the import url of the component.
- *
- * @params string $component component name
- *
- * @return string import url
-
- */
/**
- * @param $component
+ * Helper function to get the import url of the component.
+ * @param string $component
+ * Component name.
*
- * @return mixed
+ * @return string
+ * import url
*/
- function _getImportComponentUrl($component) {
-
+ private function _getImportComponentUrl($component) {
$importComponentUrl = array(
- 'Event' => 'civicrm/event/import?reset=1',
- 'Contribution' => 'civicrm/contribute/import?reset=1',
- 'Membership' => 'civicrm/member/import?reset=1',
- 'Activity' => 'civicrm/import/activity?reset=1',
+ 'Event' => 'event/import',
+ 'Contribution' => 'contribute/import',
+ 'Membership' => 'member/import',
+ 'Activity' => 'import/activity',
);
return $importComponentUrl[$component];
}
- /*
- * Helper function to get the import url of the component.
- *
- * @params string $component component name
- *
- * @return string import url
-
- */
/**
* @param $component
* @param $contactType
*
- * @return mixed
+ * @return string
*/
- function _getImportComponentContactType($component, $contactType) {
+ public function _getImportComponentContactType($component, $contactType) {
$importComponentMode = array(
- 'Event' => array('Individual' => 'CIVICRM_QFID_1_8',
+ 'Event' => array(
+ 'Individual' => 'CIVICRM_QFID_1_8',
'Household' => 'CIVICRM_QFID_2_10',
'Organization' => 'CIVICRM_QFID_4_12',
),
return $importComponentMode[$component][$contactType];
}
- /*
- * Helper function to check import mapping fields.
- *
- * @params array $headers field headers
- * @params array $rows field rows
- * @params array $checkMapperHeaders override default mapper headers
- */
/**
- * @param $headers
- * @param $rows
+ * Helper function to check import mapping fields.
+ * @param array $headers
+ * @param array $rows
* @param null $existingMapping
* @param array $checkMapperHeaders
* @param string $headerSelector
*/
- function _checkImportMapperData($headers, $rows, $existingMapping = NULL, $checkMapperHeaders = array(
- ), $headerSelector = 'th') {
+ public function _checkImportMapperData($headers, $rows, $existingMapping = NULL, $checkMapperHeaders = array(), $headerSelector = 'th') {
if (empty($checkMapperHeaders)) {
$checkMapperHeaders = array(
}
}
- /*
- * Helper function to get imported contact ids.
- *
- * @params array $rows fields rows
- * @params string $contactType contact type
-
- *
- * @return array $contactIds imported contact ids
- */
/**
- * @param $rows
+ * Helper function to get imported contact ids.
+ *
+ * @param array $rows
* @param string $contactType
*
* @return array
+ * imported contact ids
*/
- function _getImportedContactIds($rows, $contactType = 'Individual') {
+ public function _getImportedContactIds($rows, $contactType = 'Individual') {
$contactIds = array();
foreach ($rows as $row) {
return $contactIds;
}
- /*
- * Helper function to format headers and rows for contact relationship data.
- *
- * @params array $headers data headers
- * @params string $rows data rows
- */
/**
- * @param $headers
- * @param $rows
+ * Helper function to format headers and rows for contact relationship data.
+ *
+ * @param array $headers
+ * @param array $rows
*/
- function _formatContactCSVdata(&$headers, &$rows) {
+ public function _formatContactCSVdata(&$headers, &$rows) {
if (!isset($headers['contact_relationships'])) {
return;
}
}
}
}
-