X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FWebTest%2FImport%2FImportCiviSeleniumTestCase.php;h=bec67830bbe8314942ae0f11b2b9a4cebed4c90e;hb=7c71caf73155420cbb2d37c4b4eca7485018f499;hp=0e2c0e3354506b91f5bf1f7215cf0175cc54f322;hpb=2c53a8f729f160b603efc6e8f5eb03c118df6ed3;p=civicrm-core.git diff --git a/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php b/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php index 0e2c0e3354..bec67830bb 100644 --- a/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php +++ b/tests/phpunit/WebTest/Import/ImportCiviSeleniumTestCase.php @@ -26,26 +26,30 @@ require_once 'CiviTest/CiviSeleniumTestCase.php'; require_once 'CRM/Utils/Array.php'; + +/** + * Class ImportCiviSeleniumTestCase + */ 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 - * - */ + /** + * 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, $headers, $rows, @@ -56,12 +60,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { ) { // 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); @@ -159,36 +158,34 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { } } - /* - * 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 - - */ - function importContacts($headers, $rows, $contactType = 'Individual', $mode = 'Skip', $fieldMapper = array( - ), $other = array(), $type = 'csv') { + /** + * 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') { // Go to contact import page. $this->openCiviPage("import/contact", "reset=1", "uploadFile"); @@ -229,15 +226,8 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { // 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'])) { @@ -267,8 +257,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { } // Submit form. - $this->click('_qf_DataSource_upload'); - $this->waitForPageToLoad($this->getTimeoutMsec()); + $this->clickLink('_qf_DataSource_upload'); if (isset($other['checkMapperHeaders'])) { $checkMapperHeaders = $other['checkMapperHeaders']; @@ -426,37 +415,33 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { } } - /* - * Helper function to get the import url of the component. - * - * @params string $component component name - * - * @return string import url - - */ - function _getImportComponentUrl($component) { - + /** + * Helper function to get the import url of the component. + * @param string $component component name + * + * @return string import url + */ + 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 string + */ 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', ), @@ -475,15 +460,15 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { 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 - */ - function _checkImportMapperData($headers, $rows, $existingMapping = NULL, $checkMapperHeaders = array( - ), $headerSelector = 'th') { + /** + * 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') { if (empty($checkMapperHeaders)) { $checkMapperHeaders = array( @@ -516,15 +501,14 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { } } - /* - * Helper function to get imported contact ids. - * - * @params array $rows fields rows - * @params string $contactType contact type - - * - * @return array $contactIds imported contact ids - */ + /** + * Helper function to get imported contact ids. + * + * @param array $rows + * @param string $contactType + * + * @return array $contactIds imported contact ids + */ function _getImportedContactIds($rows, $contactType = 'Individual') { $contactIds = array(); @@ -563,12 +547,12 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase { return $contactIds; } - /* - * Helper function to format headers and rows for contact relationship data. - * - * @params array $headers data headers - * @params string $rows data rows - */ + /** + * Helper function to format headers and rows for contact relationship data. + * + * @param array $headers + * @param array $rows + */ function _formatContactCSVdata(&$headers, &$rows) { if (!isset($headers['contact_relationships'])) { return;