From 017bd2275f44f3fff1b3ff71bfea91982df1562a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 3 May 2022 11:59:54 +1200 Subject: [PATCH] [REF] [Import] [Trivial] Minor test fixes This just fixes some of the import parser tests to be more realistic - notably ensuring the userJobID is set - which is now required, and making the params for setting that up more flexible within the test class --- .../CRM/Contact/Import/Parser/ContactTest.php | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 0bd3695705..8b6030c3b7 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -38,7 +38,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \CRM_Core_Exception */ public function tearDown(): void { - $this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_email'], TRUE); + $this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_email', 'civicrm_user_job'], TRUE); parent::tearDown(); } @@ -59,7 +59,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { $fields = array_keys($contactImportValues); $values = array_values($contactImportValues); $parser = new CRM_Contact_Import_Parser_Contact($fields, []); - $parser->_contactType = 'Individual'; + $parser->setUserJobID($this->getUserJobID()); $parser->init(); $this->mapRelationshipFields($fields, $parser->getAllFields()); @@ -70,22 +70,21 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { ], [ NULL, NULL, - "Organization", + 'Organization', ], [ NULL, NULL, - "organization_name", + 'organization_name', ], [], [], [], [], []); - - $parser->_contactType = 'Individual'; + $parser->setUserJobID($this->getUserJobID()); $parser->_onDuplicate = CRM_Import_Parser::DUPLICATE_UPDATE; $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->callAPISuccess("Contact", "get", [ - "first_name" => "Alok", - "last_name" => "Patel", - "organization_name" => "Agileware", + 'first_name' => 'Alok', + 'last_name' => 'Patel', + 'organization_name' => 'Agileware', ]); } @@ -921,7 +920,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { } $values = array_values($originalValues); $parser = new CRM_Contact_Import_Parser_Contact($fields, $mapperLocType); - $parser->_contactType = 'Individual'; + $parser->setUserJobID($this->getUserJobID()); $parser->_dedupeRuleGroupID = $ruleGroupId; $parser->_onDuplicate = $onDuplicateAction; $parser->init(); @@ -967,15 +966,17 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase { * @throws \API_Exception * @throws \Civi\API\Exception\UnauthorizedException */ - protected function getUserJobID() { - $userJobID = UserJob::create()->setValues([ + protected function getUserJobID($submittedValues = []) { + return UserJob::create()->setValues([ 'metadata' => [ - 'submitted_values' => ['contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL], + 'submitted_values' => array_merge([ + 'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL, + 'contactSubType' => '', + ], $submittedValues), ], 'status_id:name' => 'draft', 'type_id:name' => 'contact_import', ])->execute()->first()['id']; - return $userJobID; } } -- 2.25.1