Fix for failing test in master
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 10 Jun 2022 02:06:46 +0000 (14:06 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 10 Jun 2022 02:06:46 +0000 (14:06 +1200)
CRM/Member/Import/Parser/Membership.php
tests/phpunit/CRM/Member/Import/Parser/MembershipTest.php

index 4f770429471377366e895397693b454ce305113c..fa70d863f29b17bdb934beaf278e1722962d85f8 100644 (file)
@@ -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();
index e80b3abfed3b086e22f6da8cb04567dd54afc2f8..bd9c7cc520384c07a80b491791d456ae7b1b95c2 100644 (file)
@@ -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', [