| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 6 | | This work is published under the GNU AGPLv3 license with some | |
| 7 | | permitted exceptions and without any warranty. For full license | |
| 8 | | and copyright information, see https://civicrm.org/licensing | |
| 9 | +--------------------------------------------------------------------+ |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Test APIv3 civicrm_membership_payment* functions |
| 14 | * |
| 15 | * @package CiviCRM_APIv3 |
| 16 | * @subpackage API_Member |
| 17 | * @group headless |
| 18 | */ |
| 19 | class api_v3_MembershipPaymentTest extends CiviUnitTestCase { |
| 20 | protected $_apiversion = 3; |
| 21 | protected $_contactID; |
| 22 | protected $_contributionTypeID; |
| 23 | protected $_membershipTypeID; |
| 24 | protected $_membershipStatusID; |
| 25 | protected $_contribution = []; |
| 26 | |
| 27 | public function setUp() { |
| 28 | parent::setUp(); |
| 29 | $this->useTransaction(TRUE); |
| 30 | |
| 31 | $this->_contactID = $this->organizationCreate(NULL); |
| 32 | $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); |
| 33 | $this->_membershipStatusID = $this->membershipStatusCreate('test status'); |
| 34 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name'); |
| 35 | $params = [ |
| 36 | 'contact_id' => $this->_contactID, |
| 37 | 'currency' => 'USD', |
| 38 | 'financial_type_id' => 1, |
| 39 | 'contribution_status_id' => 1, |
| 40 | 'contribution_page_id' => NULL, |
| 41 | 'payment_instrument_id' => 1, |
| 42 | 'source' => 'STUDENT', |
| 43 | 'receive_date' => '20080522000000', |
| 44 | 'receipt_date' => '20080522000000', |
| 45 | 'total_amount' => 200.00, |
| 46 | 'trxn_id' => '22ereerwww322323', |
| 47 | 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', |
| 48 | 'thankyou_date' => '20080522', |
| 49 | ]; |
| 50 | |
| 51 | $this->_contribution = $this->callAPISuccess('contribution', 'create', $params); |
| 52 | } |
| 53 | |
| 54 | ///////////////// civicrm_membership_payment_create methods |
| 55 | |
| 56 | /** |
| 57 | * Test civicrm_membership_payment_create with empty params. |
| 58 | */ |
| 59 | public function testCreateEmptyParams() { |
| 60 | $this->callAPIFailure('membership_payment', 'create', [], 'Mandatory key(s) missing from params array: membership_id, contribution_id'); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Test civicrm_membership_payment_create - success expected. |
| 65 | */ |
| 66 | public function testCreate() { |
| 67 | $contactId = $this->individualCreate(); |
| 68 | |
| 69 | $params = [ |
| 70 | 'contact_id' => $contactId, |
| 71 | 'membership_type_id' => $this->_membershipTypeID, |
| 72 | 'join_date' => '2006-01-21', |
| 73 | 'start_date' => '2006-01-21', |
| 74 | 'end_date' => '2006-12-21', |
| 75 | 'source' => 'Payment', |
| 76 | 'is_override' => 1, |
| 77 | 'status_id' => $this->_membershipStatusID, |
| 78 | ]; |
| 79 | |
| 80 | $membership = $this->callAPISuccess('membership', 'create', $params); |
| 81 | |
| 82 | $params = [ |
| 83 | 'contribution_id' => $this->_contribution['id'], |
| 84 | 'membership_id' => $membership['id'], |
| 85 | ]; |
| 86 | $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__); |
| 87 | $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__); |
| 88 | $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__); |
| 89 | |
| 90 | } |
| 91 | |
| 92 | ///////////////// civicrm_membershipPayment_get methods |
| 93 | |
| 94 | /** |
| 95 | * Test civicrm_membershipPayment_get - success expected. |
| 96 | */ |
| 97 | public function testGet() { |
| 98 | $contactId = $this->individualCreate(); |
| 99 | $params = [ |
| 100 | 'contact_id' => $contactId, |
| 101 | 'membership_type_id' => $this->_membershipTypeID, |
| 102 | 'source' => 'Payment', |
| 103 | 'is_override' => 1, |
| 104 | 'status_id' => $this->_membershipStatusID, |
| 105 | ]; |
| 106 | |
| 107 | $membership = $this->callAPISuccess('membership', 'create', $params); |
| 108 | |
| 109 | $params = [ |
| 110 | 'contribution_id' => $this->_contribution['id'], |
| 111 | 'membership_id' => $membership['id'], |
| 112 | ]; |
| 113 | $this->callAPISuccess('membership_payment', 'create', $params); |
| 114 | |
| 115 | $result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__); |
| 116 | $this->assertEquals($result['values'][$result['id']]['membership_id'], $params['membership_id'], 'Check Membership Id'); |
| 117 | $this->assertEquals($result['values'][$result['id']]['contribution_id'], $params['contribution_id'], 'Check Contribution Id'); |
| 118 | } |
| 119 | |
| 120 | } |