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; | |
22 | protected $_contributionTypeID; | |
23 | protected $_membershipTypeID; | |
24 | protected $_membershipStatusID; | |
9099cab3 | 25 | protected $_contribution = []; |
92915c55 | 26 | |
00be9182 | 27 | public function setUp() { |
6a488035 | 28 | parent::setUp(); |
fb0190bb | 29 | $this->useTransaction(TRUE); |
6a488035 TO |
30 | |
31 | $this->_contactID = $this->organizationCreate(NULL); | |
9099cab3 | 32 | $this->_membershipTypeID = $this->membershipTypeCreate(['member_of_contact_id' => $this->_contactID]); |
6a488035 TO |
33 | $this->_membershipStatusID = $this->membershipStatusCreate('test status'); |
34 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name'); | |
9099cab3 | 35 | $params = [ |
6a488035 TO |
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', | |
9099cab3 | 49 | ]; |
6a488035 | 50 | |
6c6e6187 | 51 | $this->_contribution = $this->callAPISuccess('contribution', 'create', $params); |
6a488035 TO |
52 | } |
53 | ||
6a488035 TO |
54 | ///////////////// civicrm_membership_payment_create methods |
55 | ||
56 | /** | |
57 | * Test civicrm_membership_payment_create with empty params. | |
58 | */ | |
59 | public function testCreateEmptyParams() { | |
9099cab3 | 60 | $this->callAPIFailure('membership_payment', 'create', [], 'Mandatory key(s) missing from params array: membership_id, contribution_id'); |
6a488035 TO |
61 | } |
62 | ||
63 | /** | |
64 | * Test civicrm_membership_payment_create - success expected. | |
65 | */ | |
66 | public function testCreate() { | |
e4d5f1e2 | 67 | $contactId = $this->individualCreate(); |
6a488035 | 68 | |
9099cab3 | 69 | $params = [ |
6a488035 TO |
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, | |
9099cab3 | 78 | ]; |
6a488035 | 79 | |
771f3245 | 80 | $membership = $this->callAPISuccess('membership', 'create', $params); |
6a488035 | 81 | |
9099cab3 | 82 | $params = [ |
6a488035 TO |
83 | 'contribution_id' => $this->_contribution['id'], |
84 | 'membership_id' => $membership['id'], | |
9099cab3 | 85 | ]; |
771f3245 | 86 | $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
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 | ||
6a488035 TO |
92 | ///////////////// civicrm_membershipPayment_get methods |
93 | ||
6a488035 TO |
94 | /** |
95 | * Test civicrm_membershipPayment_get - success expected. | |
96 | */ | |
97 | public function testGet() { | |
e4d5f1e2 | 98 | $contactId = $this->individualCreate(); |
9099cab3 | 99 | $params = [ |
6a488035 TO |
100 | 'contact_id' => $contactId, |
101 | 'membership_type_id' => $this->_membershipTypeID, | |
102 | 'source' => 'Payment', | |
103 | 'is_override' => 1, | |
104 | 'status_id' => $this->_membershipStatusID, | |
9099cab3 | 105 | ]; |
771f3245 | 106 | |
107 | $membership = $this->callAPISuccess('membership', 'create', $params); | |
6a488035 | 108 | |
9099cab3 | 109 | $params = [ |
6a488035 | 110 | 'contribution_id' => $this->_contribution['id'], |
771f3245 | 111 | 'membership_id' => $membership['id'], |
9099cab3 | 112 | ]; |
771f3245 | 113 | $this->callAPISuccess('membership_payment', 'create', $params); |
6a488035 | 114 | |
771f3245 | 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'); | |
6a488035 | 118 | } |
96025800 | 119 | |
6a488035 | 120 | } |