Add test for membership payment fields
authoreileen <emcnaughton@wikimedia.org>
Thu, 13 Dec 2018 05:17:33 +0000 (18:17 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 13 Dec 2018 05:17:33 +0000 (18:17 +1300)
tests/phpunit/CRM/Export/BAO/ExportTest.php

index 547dc90cf21dea73bb5db6bf33cb272e2f508715..f1615704466c9004d41ebe81ddf0da4387a37f2b 100644 (file)
@@ -130,6 +130,41 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
     CRM_Core_DAO::executeQuery($sql);
   }
 
+  /**
+   * Basic test to ensure the exportComponents function can export selected fields for contribution.
+   */
+  public function testExportComponentsMembership() {
+    $this->setUpMembershipExportData();
+    list($tableName) = CRM_Export_BAO_Export::exportComponents(
+      TRUE,
+      $this->membershipIDs,
+      [],
+      NULL,
+      NULL,
+      NULL,
+      CRM_Export_Form_Select::MEMBER_EXPORT,
+      'civicrm_membership.id IN ( ' . implode(',', $this->membershipIDs) . ')',
+      NULL,
+      FALSE,
+      FALSE,
+      array(
+        'exportOption' => CRM_Export_Form_Select::MEMBER_EXPORT,
+        'suppress_csv_for_testing' => TRUE,
+      )
+    );
+
+    $dao = CRM_Core_DAO::executeQuery('SELECT * from ' . $tableName);
+    $dao->fetch();
+    $this->assertEquals('100.00', $dao->componentpaymentfield_total_amount);
+    $this->assertEquals('Completed', $dao->componentpaymentfield_contribution_status);
+    $this->assertEquals('Credit Card', $dao->componentpaymentfield_payment_instrument);
+    $this->assertEquals(1, $dao->N);
+
+    // delete the export temp table and component table
+    $sql = "DROP TABLE IF EXISTS {$tableName}";
+    CRM_Core_DAO::executeQuery($sql);
+  }
+
   /**
    * Basic test to ensure the exportComponents function can export selected fields for contribution.
    */
@@ -244,7 +279,19 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
    */
   public function setUpMembershipExportData() {
     $this->setUpContactExportData();
+    // Create an extra so we don't get false passes due to 1
+    $this->contactMembershipCreate(['contact_id' => $this->contactIDs[0]]);
     $this->membershipIDs[] = $this->contactMembershipCreate(['contact_id' => $this->contactIDs[0]]);
+    $this->setUpContributionExportData();
+    $this->callAPISuccess('membership_payment', 'create', array(
+      'contribution_id' => $this->contributionIDs[0],
+      'membership_id' => $this->membershipIDs[0],
+    ));
+    $this->callAPISuccess('LineItem', 'get', [
+      'entity_table' =>'civicrm_membership',
+      'membership_id' => $this->membershipIDs[0],
+      'api.LineItem.create' => ['contribution_id' => $this->contributionIDs[0]],
+    ]);
   }
 
   /**