From: Eileen McNaughton Date: Fri, 10 Jun 2022 02:06:46 +0000 (+1200) Subject: Fix for failing test in master X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7cd963e4bcd1390cf5c1a150fd6bd0c27d496469;p=civicrm-core.git Fix for failing test in master --- diff --git a/CRM/Member/Import/Parser/Membership.php b/CRM/Member/Import/Parser/Membership.php index 4f77042947..fa70d863f2 100644 --- a/CRM/Member/Import/Parser/Membership.php +++ b/CRM/Member/Import/Parser/Membership.php @@ -85,6 +85,8 @@ class CRM_Member_Import_Parser_Membership extends CRM_Import_Parser { * * @param array $values * The array of values belonging to this line. + * + * @throws \CRM_Core_Exception */ public function validateValues($values): void { $params = $this->getMappedRow($values); @@ -102,6 +104,10 @@ class CRM_Member_Import_Parser_Membership extends CRM_Import_Parser { if (empty($params['start_date']) && empty($params['join_date'])) { $errors[] = 'Membership Start Date is required to create a memberships.'; } + //fix for CRM-2219 Update Membership + if ($this->isUpdateExisting() && !empty($params['is_override']) && empty($params['status_id'])) { + $errors[] = 'Required parameter missing: Status'; + } if ($errors) { throw new CRM_Core_Exception('Invalid value for field(s) : ' . implode(',', $errors)); } @@ -142,20 +148,15 @@ class CRM_Member_Import_Parser_Membership extends CRM_Import_Parser { //format params to meet api v2 requirements. //@todo find a way to test removing this formatting - $formatError = $this->membership_format_params($formatValues, $formatted, TRUE); + $this->membership_format_params($formatValues, $formatted, TRUE); - if ($this->isUpdateExisting()) { + if (!$this->isUpdateExisting()) { $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($formatted, NULL, 'Membership' ); } else { - //fix for CRM-2219 Update Membership - // onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE - if (!empty($formatted['is_override']) && empty($formatted['status_id'])) { - throw new CRM_Core_Exception('Required parameter missing: Status', CRM_Import_Parser::ERROR); - } if (!empty($formatValues['membership_id'])) { $dao = new CRM_Member_BAO_Membership(); diff --git a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php index e80b3abfed..bd9c7cc520 100644 --- a/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php @@ -167,8 +167,6 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { /** * Test overriding a membership but not providing status. - * - * @throws \CRM_Core_Exception */ public function testImportOverriddenMembershipButWithoutStatus(): void { $this->individualCreate(['email' => 'anthony_anderson2@civicrm.org']); @@ -178,7 +176,6 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { 'onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE, ])); $membershipImporter->init(); - $membershipImporter->_contactType = 'Individual'; $importValues = [ 'anthony_anderson2@civicrm.org', @@ -186,18 +183,21 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { date('Y-m-d'), TRUE, ]; + try { + $membershipImporter->validateValues($importValues); + $this->fail('validation error expected.'); + } + catch (CRM_Core_Exception $e) { + $this->assertContains('Required parameter missing: Status', $e->getMessage()); + return; + } - $importResponse = $membershipImporter->import($importValues); - $this->assertEquals(CRM_Import_Parser::ERROR, $importResponse); - $this->assertContains('Required parameter missing: Status', $importValues); } /** * Test that the passed in status is respected. - * - * @throws \CRM_Core_Exception */ - public function testImportOverriddenMembershipWithStatus() { + public function testImportOverriddenMembershipWithStatus(): void { $this->individualCreate(['email' => 'anthony_anderson3@civicrm.org']); $membershipImporter = $this->createImportObject([ 'email', @@ -259,7 +259,7 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { 'abc', ]; try { - $importResponse = $membershipImporter->validateValues($importValues); + $membershipImporter->validateValues($importValues); } catch (CRM_Core_Exception $e) { $this->assertEquals('Invalid value for field(s) : Status Override End Date', $e->getMessage()); @@ -272,9 +272,8 @@ class CRM_Member_Import_Parser_MembershipTest extends CiviUnitTestCase { /** * Test that memberships can still be imported if the status is renamed. * - * @throws \CRM_Core_Exception */ - public function testImportMembershipWithRenamedStatus() { + public function testImportMembershipWithRenamedStatus(): void { $this->individualCreate(['email' => 'anthony_anderson3@civicrm.org']); $this->callAPISuccess('MembershipStatus', 'get', [