From 69140e67e5fa23e015f5f37ba80fa4070ad7d007 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 4 Nov 2014 23:36:54 +1300 Subject: [PATCH] CRM-15203 test fixes to test for membership_payment creation --- .../CRM/Core/Payment/AuthorizeNetIPNTest.php | 1 - .../CRM/Core/Payment/PayPalProIPNTest.php | 6 +++-- tests/phpunit/CiviTest/CiviUnitTestCase.php | 26 ++++++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php index 94493a5aac..eac0b7e819 100644 --- a/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/AuthorizeNetIPNTest.php @@ -84,7 +84,6 @@ class CRM_Core_Payment_AuthorizeNetIPNTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('contribution', 'get', array('contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1)); $this->assertEquals(2, $contribution['count']); $this->assertEquals('second_one', $contribution['values'][1]['trxn_id']); - $this->markTestIncomplete('This is a test for CRM-15203 but that is currently NOT working (however, getting this far indicates CRM-15527 is fixed'); $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id'],)); $this->callAPISuccessGetSingle('line_item', array('contribution_id' => $contribution['values'][1]['id'], 'entity_table' => 'civicrm_membership')); } diff --git a/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php b/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php index 2067f2229d..bdc8c96325 100644 --- a/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php +++ b/tests/phpunit/CRM/Core/Payment/PayPalProIPNTest.php @@ -94,6 +94,7 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { */ function testIPNPaymentMembershipRecurSuccess() { $this->setupMembershipRecurringPaymentProcessorTransaction(); + $this->callAPISuccessGetSingle('membership_payment', array()); $paypalIPN = new CRM_Core_Payment_PayPalProIPN($this->getPaypalProRecurTransaction()); $paypalIPN->main(); $contribution = $this->callAPISuccess('contribution', 'getsingle', array('id' => $this->_contributionID)); @@ -110,9 +111,10 @@ class CRM_Core_Payment_PayPalProIPNTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('contribution', 'get', array('contribution_recur_id' => $this->_contributionRecurID, 'sequential' => 1)); $this->assertEquals(2, $contribution['count']); $this->assertEquals('secondone', $contribution['values'][1]['trxn_id']); - $this->markTestIncomplete('This is a test for CRM-15203 but that is currently NOT working (however, getting this far indicates CRM-15527 is fixed'); - $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id'],)); + $this->callAPISuccessGetCount('line_item', array('entity_id' => $this->ids['membership'], 'entity_table' => 'civicrm_membership'), 2); $this->callAPISuccessGetSingle('line_item', array('contribution_id' => $contribution['values'][1]['id'], 'entity_table' => 'civicrm_membership')); + $this->callAPISuccessGetSingle('membership_payment', array('contribution_id' => $contribution['values'][1]['id'],)); + } /** * CRM-13743 test IPN edge case where the first transaction fails and the second succeeds diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 5df53efacf..269a66b14f 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2972,19 +2972,33 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) * we don't have a good way to set up a recurring contribution with a membership so let's just do one then alter it */ function setupMembershipRecurringPaymentProcessorTransaction() { - $this->setupRecurringPaymentProcessorTransaction(); $this->ids['membership_type'] = $this->membershipTypeCreate(); + //create a contribution so our membership & contribution don't both have id = 1 + $this->contributionCreate($this->_contactID, 1, 'abcd', '345j'); + $this->setupRecurringPaymentProcessorTransaction(); + $this->ids['membership'] = $this->callAPISuccess('membership', 'create', array( 'contact_id' => $this->_contactID, 'membership_type_id' => $this->ids['membership_type'], 'contribution_recur_id' => $this->_contributionRecurID, - 'api.membership_payment.create' => array('contribution_id' => $this->_contributionID), 'format.only_id' => TRUE, )); - CRM_Core_DAO::executeQuery( - "UPDATE civicrm_line_item SET entity_table = 'civicrm_membership', entity_id = {$this->ids['membership']} - WHERE entity_id = {$this->_contributionID} AND entity_table = 'civicrm_contribution'" - ); + //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"); + + $this->callAPISuccess('line_item', 'create', array( + 'entity_table' => 'civicrm_membership', + 'entity_id' => $this->ids['membership'], + 'contribution_id' => $this->_contributionID, + 'label' => 'General', + 'qty' => 1, + 'unit_price' => 200, + 'line_total' => 200, + 'financial_type_id' => 1, + 'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', array('return' => 'id', 'label' => 'Membership Amount')), + 'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', array('return' => 'id', 'label' => 'General')), + )); + $this->callAPISuccess('membership_payment', 'create', array('contribution_id' => $this->_contributionID, 'membership_id' => $this->ids['membership'])); } /** -- 2.25.1