From f03241bece66a2c2fd105e8b3d507f3840c62879 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 3 Aug 2019 13:46:15 +1200 Subject: [PATCH] Add test cover for Member_BAO_Query auto_renew field This adds test coverage to demonstrate that the auto_renew field in the Member_BAO_Query::defaultReturnProperties achieves nothing. auto_renew is NOT returned for the export - regardless of it's presence. It IS returned for getRows but tha is calculated there now in the query object. Once this is merged I will put up the commit to remove auto_renew from defaultReturnProperties --- tests/phpunit/CRM/Export/BAO/ExportTest.php | 43 ++++++----- .../CRM/Member/Selector/SearchTest.php | 74 +++++++++++++++++++ tests/phpunit/CiviTest/CiviUnitTestCase.php | 3 + 3 files changed, 100 insertions(+), 20 deletions(-) create mode 100644 tests/phpunit/CRM/Member/Selector/SearchTest.php diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 3774933f25..8572390530 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -187,8 +187,9 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { 'selectAll' => TRUE, 'ids' => $this->membershipIDs, 'exportMode' => CRM_Export_Form_Select::MEMBER_EXPORT, - 'componentClause' => 'civicrm_membership.id IN ( ' . implode(',', $this->membershipIDs) . ')', + 'componentClause' => 'civicrm_membership.id IN ( ' . $this->ids['membership'] . ')', ]); + $membership = $this->callAPISuccessGetSingle('Membership', ['id' => $this->ids['membership']]); $row = $this->csv->fetchOne(); $expected = [ @@ -275,22 +276,23 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { 'Membership Type' => 'General', 'Test' => '', 'Is Pay Later' => '', - 'Member Since' => '2007-01-21', - 'Membership Start Date' => '2007-01-21', - 'Membership Expiration Date' => '2007-12-21', + 'Member Since' => $membership['join_date'], + 'Membership Start Date' => $membership['start_date'], + 'Membership Expiration Date' => $membership['end_date'], 'Source' => 'Payment', - 'Membership Status' => 'Expired', + 'Membership Status' => 'New', 'Membership ID' => '2', 'Primary Member ID' => '', 'max_related' => '', - 'membership_recur_id' => '', + 'membership_recur_id' => 1, 'Campaign ID' => '', 'member_is_override' => '', + // Nothing is returned for auto-renew - this is incorrect based on the intent - but we are adding a test to confirm not fix here. 'member_auto_renew' => '', - 'Total Amount' => '100.00', - 'Contribution Status' => 'Completed', + 'Total Amount' => '200.00', + 'Contribution Status' => 'Pending', 'Date Received' => '2019-07-25 07:34:23', - 'Payment Method' => 'Credit Card', + 'Payment Method' => 'Check', 'Transaction ID' => '', ]; $this->assertExpectedOutput($expected, $row); @@ -398,21 +400,22 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $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', [ - '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]], - ]); + + $this->_contactID = $this->contactIDs[0]; + $this->_invoiceID = 1234; + $this->_contributionPageID = NULL; + $this->_paymentProcessorID = $this->paymentProcessorCreate(); + $this->setupMembershipRecurringPaymentProcessorTransaction(); + + $membershipID = $this->callAPISuccessGetValue('Membership', ['return' => 'id', 'contact_id' => $this->_contactID, 'options' => ['limit' => 1, 'sort' => 'id DESC']]); + + $this->membershipIDs[] = $membershipID; } /** * Set up data to test case export. + * + * @throws \CRM_Core_Exception */ public function setupCaseExportData() { $contactID1 = $this->individualCreate(); diff --git a/tests/phpunit/CRM/Member/Selector/SearchTest.php b/tests/phpunit/CRM/Member/Selector/SearchTest.php new file mode 100644 index 0000000000..ee3f3604ca --- /dev/null +++ b/tests/phpunit/CRM/Member/Selector/SearchTest.php @@ -0,0 +1,74 @@ +_contactID = $this->individualCreate(); + $this->_invoiceID = 1234; + $this->_contributionPageID = NULL; + $this->_paymentProcessorID = $this->paymentProcessorCreate(); + $this->setupMembershipRecurringPaymentProcessorTransaction(); + $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_contactID]); + $membershipID = $membership['id']; + $params = []; + $selector = new CRM_Member_Selector_Search($params); + $rows = $selector->getRows(CRM_Core_Permission::VIEW, 0, 25, NULL); + $this->assertEquals([ + 'contact_id' => $this->_contactID, + 'membership_id' => $membershipID, + 'contact_type' => '
', + 'sort_name' => 'Anderson, Anthony', + 'membership_type' => 'General', + 'join_date' => date('Y-m-d'), + 'membership_start_date' => date('Y-m-d'), + 'membership_end_date' => $membership['end_date'], + 'membership_source' => 'Payment', + 'member_is_test' => '0', + 'owner_membership_id' => NULL, + 'membership_status' => 'New', + 'member_campaign_id' => NULL, + 'campaign' => NULL, + 'campaign_id' => NULL, + 'checkbox' => 'mark_x_1', + 'action' => 'ViewEditRenew...', + 'auto_renew' => 1, + ], $rows[0]); + $this->assertCount(1, $rows); + } + +} diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 31e8091bc8..957a716325 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2396,6 +2396,7 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 'contribution_page_id' => $this->_contributionPageID, 'payment_processor_id' => $this->_paymentProcessorID, 'is_test' => 0, + 'receive_date' => '2019-07-25 07:34:23', 'skipCleanMoney' => TRUE, ], $contributionParams); $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', array_merge(array( @@ -2439,6 +2440,7 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 'financial_type_id' => 1, 'invoice_id' => 'abcd', 'trxn_id' => 345, + 'receive_date' => '2019-07-25 07:34:23', )); } $this->setupRecurringPaymentProcessorTransaction($recurParams); @@ -2448,6 +2450,7 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) 'membership_type_id' => $this->ids['membership_type'], 'contribution_recur_id' => $this->_contributionRecurID, 'format.only_id' => TRUE, + 'source' => 'Payment', )); //CRM-15055 creates line items we don't want so get rid of them so we can set up our own line items CRM_Core_DAO::executeQuery("TRUNCATE civicrm_line_item"); -- 2.25.1