Skip to content

Commit

Permalink
Fix tests to the updated function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 6, 2022
1 parent 9375115 commit 0b83ca4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function summary(&$values): int {
* @throws \CRM_Core_Exception
* @throws \API_Exception
*/
public function import(&$values) {
public function import($values) {
$rowNumber = (int) $values[array_key_last($values)];

$this->_unparsedStreetAddressContacts = [];
Expand Down
12 changes: 1 addition & 11 deletions CRM/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1718,17 +1718,7 @@ public static function runImport($taskContext, $userJobID, $limit) {

while ($row = $dataSource->getRow()) {
$values = array_values($row);

try {
$parser->import($values);
}
catch (CiviCRM_API3_Exception $e) {
// When we catch errors here we are not adding to the errors array - mostly
// because that will become obsolete once https://github.com/civicrm/civicrm-core/pull/23292
// is merged and this will replace it as the main way to handle errors (ie. update the table
// and move on).
$parser->setImportStatus((int) $values[count($values) - 1], 'ERROR', $e->getMessage());
}
$parser->import($values);
}
$parser->doPostImportActions();
return TRUE;
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function testImportParserWithEmployeeOfRelationship(): void {
$parser->setUserJobID($userJobID);
$parser->init();

$this->assertEquals(CRM_Import_Parser::VALID, $parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), 'Return code from parser import was not as expected');
$this->assertEquals(CRM_Import_Parser::VALID, $parser->import($values), 'Return code from parser import was not as expected');
$this->callAPISuccessGetSingle('Contact', [
'first_name' => 'Alok',
'last_name' => 'Patel',
Expand Down Expand Up @@ -1623,7 +1623,7 @@ protected function runImport(array $originalValues, $onDuplicateAction, $expecte
$parser->setUserJobID($userJobID);
$parser->_dedupeRuleGroupID = $ruleGroupId;
$parser->init();
$result = $parser->import($onDuplicateAction, $values);
$result = $parser->import($values);
$dataSource = new CRM_Import_DataSource_CSV($userJobID);
if ($result === FALSE && $expectedResult !== FALSE) {
// Import is moving away from returning a status - this is a better way to check
Expand Down Expand Up @@ -1906,7 +1906,7 @@ public function testImportParserDoesNotMatchPrimaryToRelated(): void {
$parser = new CRM_Contact_Import_Parser_Contact();
$parser->setUserJobID($userJobID);
$parser->init();
$parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values);
$parser->import($values);
$this->callAPISuccessGetSingle('Contact', [
'first_name' => 'Bob',
'last_name' => 'Dobbs',
Expand Down Expand Up @@ -2137,17 +2137,17 @@ public function testImportParserWithExternalIdForRelationship(bool $isOrganizati
['5_a_b', 'external_identifier'],
['5_a_b', 'organization_name'],
];
$fields = array_keys($contactImportValues);

$values = array_values($contactImportValues);
$userJobID = $this->getUserJobID([
'mapper' => $mapper,
]);

$parser = new CRM_Contact_Import_Parser_Contact($fields);
$parser = new CRM_Contact_Import_Parser_Contact();
$parser->setUserJobID($userJobID);
$parser->init();

$parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values);
$parser->import($values);
$this->callAPISuccessGetCount('Contact', ['organization_name' => 'Big shop'], $isOrganizationProvided ? 2 : 0);
}

Expand Down

0 comments on commit 0b83ca4

Please sign in to comment.