Skip to content

Commit

Permalink
Merge pull request #23523 from eileenmcnaughton/import_little
Browse files Browse the repository at this point in the history
Re-use code in test
  • Loading branch information
demeritcowboy authored May 20, 2022
2 parents 7b79a6f + a8f0bb9 commit 5e71c13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
1 change: 0 additions & 1 deletion CRM/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ abstract class CRM_Import_Parser {
*/
const CONTACT_INDIVIDUAL = 1, CONTACT_HOUSEHOLD = 2, CONTACT_ORGANIZATION = 4;


/**
* User job id.
*
Expand Down
22 changes: 5 additions & 17 deletions tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,22 +1014,7 @@ public function testImportGenders(): void {
['do_not_import'],
];
$csv = 'individual_genders.csv';
/* @var CRM_Import_DataSource_CSV $dataSource */
/* @var \CRM_Contact_Import_Parser_Contact $parser */
[$dataSource, $parser] = $this->getDataSourceAndParser($csv, $mapper, []);
while ($values = $dataSource->getRow()) {
try {
$parser->validateValues(array_values($values));
if ($values['expected'] !== 'Valid') {
$this->fail($values['gender'] . ' should not have been valid');
}
}
catch (CRM_Core_Exception $e) {
if ($values['expected'] !== 'Invalid') {
$this->fail($values['gender'] . ' should have been valid');
}
}
}
$this->validateMultiRowCsv($csv, $mapper, 'gender');

$this->importCSV($csv, $mapper);
$contacts = Contact::get()
Expand Down Expand Up @@ -1562,18 +1547,21 @@ protected function importCSV(string $csv, array $mapper, array $submittedValues
}

/**
* Validate a csv with multiple rows in it.
*
* @param string $csv
* @param array $mapper Mapping as entered on MapField form.
* e.g [['first_name']['email', 1]].
* @param string $field
* Name of the field whose data should be output in the error message.
* @param array $submittedValues
* Values submitted in the form process.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
private function validateMultiRowCsv(string $csv, array $mapper, string $field, $submittedValues): void {
private function validateMultiRowCsv(string $csv, array $mapper, string $field, $submittedValues = []): void {
/* @var CRM_Import_DataSource_CSV $dataSource */
/* @var \CRM_Contact_Import_Parser_Contact $parser */
[$dataSource, $parser] = $this->getDataSourceAndParser($csv, $mapper, $submittedValues);
Expand Down

0 comments on commit 5e71c13

Please sign in to comment.