Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up test to create line_items & memberships accurately #10029

Merged
merged 1 commit into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4532,6 +4532,8 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re

// CRM-8141 update the membership type with the value recorded in log when membership created/renewed
// this picks up membership type changes during renewals
// @todo this is almost certainly an obsolete sql call, the pre-change
// membership is accessible via $this->_relatedObjects
$sql = "
SELECT membership_type_id
FROM civicrm_membership_log
Expand Down
72 changes: 41 additions & 31 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2100,17 +2100,18 @@ public function testRepeatTransactionTestRecurId() {
}
/**
* CRM-19945 Tests repeattransaction is using a completed contribution for the template.
*
* ( Tests membership is renewed after repeattransaction. )
*/
public function testRepeatTransactionUsesCompleted() {
list($originalContribution, $membership) = $this->setUpAutoRenewMembership();

$this->callAPISuccess('contribution', 'create', array(
'contact_id' => $originalContribution['values'][1]['contact_id'],
'financial_type_id' => $originalContribution['values'][1]['financial_type_id'],
'total_amount' => $originalContribution['values'][1]['total_amount'],
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => "Failed",
'contact_id' => $originalContribution['values'][1]['contact_id'],
'financial_type_id' => $originalContribution['values'][1]['financial_type_id'],
'total_amount' => $originalContribution['values'][1]['total_amount'],
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => "Failed",
));

$this->callAPISuccess('membership', 'create', array(
Expand All @@ -2119,18 +2120,22 @@ public function testRepeatTransactionUsesCompleted() {
'status_id' => 4,
));

$this->callAPISuccess('contribution', 'repeattransaction', array(
$contribution = $this->callAPISuccess('contribution', 'repeattransaction', array(
'contribution_recur_id' => $originalContribution['values'][1]['contribution_recur_id'],
'contribution_status_id' => 'Completed',
'trxn_id' => uniqid(),
'trxn_id' => 'bobsled',
));

$membershipStatus = $this->callAPISuccess('membership', 'getvalue', array(
$membershipStatusId = $this->callAPISuccess('membership', 'getvalue', array(
'id' => $membership['id'],
'return' => 'status_id',
));

$this->assertEquals('1', $membershipStatus);
$this->assertEquals('New', CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'status_id', $membershipStatusId));

$lineItem = $this->callAPISuccessGetSingle('LineItem', array('contribution_id' => $contribution['id']));
$this->assertEquals('civicrm_membership', $lineItem['entity_table']);
$this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id']));
$this->quickCleanUpFinancialEntities();
$this->contactDelete($originalContribution['values'][1]['contact_id']);
}
Expand Down Expand Up @@ -3251,17 +3256,17 @@ protected function setUpRecurringContribution($generalParams = array(), $recurPa
*/
protected function setUpAutoRenewMembership($generalParams = array(), $recurParams = array()) {
$newContact = $this->callAPISuccess('Contact', 'create', array(
'contact_type' => 'Individual',
'sort_name' => 'McTesterson, Testy',
'display_name' => 'Testy McTesterson',
'preferred_language' => 'en_US',
'preferred_mail_format' => 'Both',
'first_name' => 'Testy',
'last_name' => 'McTesterson',
'contact_is_deleted' => '0',
'email_id' => '4',
'email' => 'tmctesterson@example.com',
'on_hold' => '0',
'contact_type' => 'Individual',
'sort_name' => 'McTesterson, Testy',
'display_name' => 'Testy McTesterson',
'preferred_language' => 'en_US',
'preferred_mail_format' => 'Both',
'first_name' => 'Testy',
'last_name' => 'McTesterson',
'contact_is_deleted' => '0',
'email_id' => '4',
'email' => 'tmctesterson@example.com',
'on_hold' => '0',
));
$membershipType = $this->callAPISuccess('MembershipType', 'create', array(
'domain_id' => "Default Domain Name",
Expand All @@ -3284,6 +3289,17 @@ protected function setUpAutoRenewMembership($generalParams = array(), $recurPara
'frequency_unit' => 'month',
'payment_processor_id' => $this->paymentProcessorID,
), $generalParams, $recurParams));

$membership = $this->callAPISuccess('membership', 'create', array(
'contact_id' => $newContact['id'],
'contribution_recur_id' => $contributionRecur['id'],
'financial_type_id' => "Member Dues",
'membership_type_id' => $membershipType['id'],
'num_terms' => 1,
'skipLineItem' => TRUE,
));

CRM_Price_BAO_LineItem::getLineItemArray($this->_params, NULL, 'membership', $membershipType['id']);
$originalContribution = $this->callAPISuccess('contribution', 'create', array_merge(
$this->_params,
array(
Expand All @@ -3294,18 +3310,12 @@ protected function setUpAutoRenewMembership($generalParams = array(), $recurPara
'invoice_id' => uniqid(),
), $generalParams)
);
$membership = $this->callAPISuccess('membership', 'create', array(
'contact_id' => $newContact['id'],
'contribution_recur_id' => $contributionRecur['id'],
'financial_type_id' => "Member Dues",
'membership_type_id' => $membershipType['id'],
'num_terms' => 1,
));
$lineItem = $this->callAPISuccess('LineItem', 'getsingle', array());
$this->assertEquals('civicrm_membership', $lineItem['entity_table']);
$membership = $this->callAPISuccess('Membership', 'getsingle', array('id' => $lineItem['entity_id']));
$this->callAPISuccess('LineItem', 'getsingle', array());
$this->callAPISuccessGetCount('MembershipPayment', array('membership_id' => $membership['id']), 1);

$this->callAPISuccess('MembershipPayment', 'create', array(
'contribution_id' => $originalContribution['id'],
'membership_id' => $membership['id'],
));
return array($originalContribution, $membership);
}
/**
Expand Down