Skip to content

Commit

Permalink
Fix test set up to user Order api
Browse files Browse the repository at this point in the history
Note this includes the order api ensuring that the contribution_recur_id is passed through to
any created memberships
  • Loading branch information
eileenmcnaughton committed Jul 6, 2021
1 parent 8e336ac commit 677df21
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
3 changes: 3 additions & 0 deletions api/v3/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ function civicrm_api3_order_create(array $params): array {

case 'membership':
$entityParams['status_id'] = 'Pending';
if (!empty($params['contribution_recur_id'])) {
$entityParams['contribution_recur_id'] = $params['contribution_recur_id'];
}
break;

default:
Expand Down
10 changes: 10 additions & 0 deletions tests/phpunit/CRM/Core/Payment/PayPalIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ class CRM_Core_Payment_PayPalIPNTest extends CiviUnitTestCase {
protected $_paymentProcessorID;
protected $_customFieldID;

/**
* Should financials be checked after the test but before tear down.
*
* Ideally all tests (or at least all that call any financial api calls ) should do this but there
* are some test data issues and some real bugs currently blockinng.
*
* @var bool
*/
protected $isValidateFinancialsOnPostAssert = TRUE;

/**
* Set up function.
*/
Expand Down
44 changes: 16 additions & 28 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use Civi\Api4\CustomField;
use Civi\Api4\CustomGroup;
use Civi\Api4\LineItem;
use Civi\Api4\OptionGroup;
use Civi\Api4\RelationshipType;
use Civi\Payment\System;
Expand Down Expand Up @@ -1058,10 +1059,8 @@ public function pledgeDelete($pledgeId) {
*
* @return int
* id of created contribution
* @throws \CRM_Core_Exception
*/
public function contributionCreate($params) {

public function contributionCreate(array $params): int {
$params = array_merge([
'domain_id' => 1,
'receive_date' => date('Ymd'),
Expand Down Expand Up @@ -2551,10 +2550,8 @@ public function paymentProcessorCreate($params = []) {
*
* @param array $recurParams (Optional)
* @param array $contributionParams (Optional)
*
* @throws \CRM_Core_Exception
*/
public function setupRecurringPaymentProcessorTransaction($recurParams = [], $contributionParams = []) {
public function setupRecurringPaymentProcessorTransaction($recurParams = [], $contributionParams = []): void {
$this->ids['campaign'][0] = $this->callAPISuccess('Campaign', 'create', ['title' => 'get the money'])['id'];
$contributionParams = array_merge([
'total_amount' => '200',
Expand Down Expand Up @@ -2595,9 +2592,9 @@ public function setupRecurringPaymentProcessorTransaction($recurParams = [], $co
*
* @param array $params Optionally modify params for membership/recur (duration_unit/frequency_unit)
*
* @throws \CRM_Core_Exception
* @throws \API_Exception
*/
public function setupMembershipRecurringPaymentProcessorTransaction($params = []) {
public function setupMembershipRecurringPaymentProcessorTransaction($params = []): void {
$membershipParams = $recurParams = [];
if (!empty($params['duration_unit'])) {
$membershipParams['duration_unit'] = $params['duration_unit'];
Expand All @@ -2619,41 +2616,32 @@ public function setupMembershipRecurringPaymentProcessorTransaction($params = []
]);
}

$this->ids['membership'] = $this->callAPISuccess('Membership', 'create', [
'contact_id' => $this->_contactID,
'membership_type_id' => $this->ids['membership_type'],
'format.only_id' => TRUE,
'source' => 'Payment',
'skipLineItem' => TRUE,
]);
$this->setupRecurringPaymentProcessorTransaction($recurParams, [
'line_items' => [
[
'line_item' => [
[
'entity_table' => 'civicrm_membership',
'entity_id' => $this->ids['membership'],
'label' => 'General',
'qty' => 1,
'unit_price' => 200,
'line_total' => 200,
'financial_type_id' => 1,
'price_field_id' => $this->callAPISuccess('price_field', 'getvalue', [
'return' => 'id',
'label' => 'Membership Amount',
'options' => ['limit' => 1, 'sort' => 'id DESC'],
]),
'price_field_value_id' => $this->callAPISuccess('price_field_value', 'getvalue', [
'return' => 'id',
'label' => 'General',
'options' => ['limit' => 1, 'sort' => 'id DESC'],
]),
'membership_type_id' => $this->ids['membership_type'],
],
],
'params' => [
'contact_id' => $this->_contactID,
'membership_type_id' => $this->ids['membership_type'],
'source' => 'Payment',
],
],
],
]);
$this->callAPISuccess('Membership', 'create', ['id' => $this->ids['membership'], 'contribution_recur_id' => $this->_contributionRecurID]);
$this->ids['membership'] = LineItem::get()
->addWhere('contribution_id', '=', $this->ids['Contribution'][0])
->addWhere('entity_table', '=', 'civicrm_membership')
->addSelect('entity_id')
->execute()->first()['entity_id'];
}

/**
Expand Down

0 comments on commit 677df21

Please sign in to comment.