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