Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | /** |
29 | * Test APIv3 civicrm_membership_payment* functions | |
30 | * | |
6c6e6187 TO |
31 | * @package CiviCRM_APIv3 |
32 | * @subpackage API_Member | |
acb109b7 | 33 | * @group headless |
6a488035 | 34 | */ |
6a488035 TO |
35 | class api_v3_MembershipPaymentTest extends CiviUnitTestCase { |
36 | protected $_apiversion = 3; | |
37 | protected $_contactID; | |
38 | protected $_contributionTypeID; | |
39 | protected $_membershipTypeID; | |
40 | protected $_membershipStatusID; | |
41 | protected $_contribution = array(); | |
92915c55 | 42 | |
00be9182 | 43 | public function setUp() { |
6a488035 | 44 | parent::setUp(); |
fb0190bb | 45 | $this->useTransaction(TRUE); |
6a488035 TO |
46 | |
47 | $this->_contactID = $this->organizationCreate(NULL); | |
75638074 | 48 | $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); |
6a488035 TO |
49 | $this->_membershipStatusID = $this->membershipStatusCreate('test status'); |
50 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name'); | |
51 | $params = array( | |
52 | 'contact_id' => $this->_contactID, | |
53 | 'currency' => 'USD', | |
54 | 'financial_type_id' => 1, | |
55 | 'contribution_status_id' => 1, | |
56 | 'contribution_page_id' => NULL, | |
57 | 'payment_instrument_id' => 1, | |
58 | 'source' => 'STUDENT', | |
59 | 'receive_date' => '20080522000000', | |
60 | 'receipt_date' => '20080522000000', | |
61 | 'total_amount' => 200.00, | |
62 | 'trxn_id' => '22ereerwww322323', | |
63 | 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', | |
64 | 'thankyou_date' => '20080522', | |
6a488035 TO |
65 | ); |
66 | ||
6c6e6187 | 67 | $this->_contribution = $this->callAPISuccess('contribution', 'create', $params); |
6a488035 TO |
68 | } |
69 | ||
6a488035 TO |
70 | ///////////////// civicrm_membership_payment_create methods |
71 | ||
72 | /** | |
73 | * Test civicrm_membership_payment_create with empty params. | |
74 | */ | |
75 | public function testCreateEmptyParams() { | |
771f3245 | 76 | $this->callAPIFailure('membership_payment', 'create', array(), 'Mandatory key(s) missing from params array: membership_id, contribution_id'); |
6a488035 TO |
77 | } |
78 | ||
79 | /** | |
80 | * Test civicrm_membership_payment_create - success expected. | |
81 | */ | |
82 | public function testCreate() { | |
e4d5f1e2 | 83 | $contactId = $this->individualCreate(); |
6a488035 | 84 | |
6a488035 TO |
85 | $params = array( |
86 | 'contact_id' => $contactId, | |
87 | 'membership_type_id' => $this->_membershipTypeID, | |
88 | 'join_date' => '2006-01-21', | |
89 | 'start_date' => '2006-01-21', | |
90 | 'end_date' => '2006-12-21', | |
91 | 'source' => 'Payment', | |
92 | 'is_override' => 1, | |
93 | 'status_id' => $this->_membershipStatusID, | |
6a488035 TO |
94 | ); |
95 | ||
771f3245 | 96 | $membership = $this->callAPISuccess('membership', 'create', $params); |
6a488035 TO |
97 | |
98 | $params = array( | |
99 | 'contribution_id' => $this->_contribution['id'], | |
100 | 'membership_id' => $membership['id'], | |
6a488035 | 101 | ); |
771f3245 | 102 | $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
103 | $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__); |
104 | $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__); | |
105 | ||
106 | } | |
107 | ||
108 | ||
109 | ///////////////// civicrm_membershipPayment_get methods | |
110 | ||
111 | /** | |
112 | * Test civicrm_membershipPayment_get with wrong params type. | |
113 | */ | |
114 | public function testGetWrongParamsType() { | |
115 | $params = 'eeee'; | |
771f3245 | 116 | $GetWrongParamsType = $this->callAPIFailure('membership_payment', 'get', $params, 'Input variable `params` is not an array'); |
6a488035 TO |
117 | } |
118 | ||
119 | /** | |
120 | * Test civicrm_membershipPayment_get - success expected. | |
121 | */ | |
122 | public function testGet() { | |
e4d5f1e2 | 123 | $contactId = $this->individualCreate(); |
6a488035 TO |
124 | $params = array( |
125 | 'contact_id' => $contactId, | |
126 | 'membership_type_id' => $this->_membershipTypeID, | |
127 | 'source' => 'Payment', | |
128 | 'is_override' => 1, | |
129 | 'status_id' => $this->_membershipStatusID, | |
6a488035 | 130 | ); |
771f3245 | 131 | |
132 | $membership = $this->callAPISuccess('membership', 'create', $params); | |
6a488035 TO |
133 | |
134 | $params = array( | |
135 | 'contribution_id' => $this->_contribution['id'], | |
771f3245 | 136 | 'membership_id' => $membership['id'], |
6a488035 | 137 | ); |
771f3245 | 138 | $this->callAPISuccess('membership_payment', 'create', $params); |
6a488035 | 139 | |
771f3245 | 140 | $result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__); |
141 | $this->assertEquals($result['values'][$result['id']]['membership_id'], $params['membership_id'], 'Check Membership Id'); | |
142 | $this->assertEquals($result['values'][$result['id']]['contribution_id'], $params['contribution_id'], 'Check Contribution Id'); | |
6a488035 | 143 | } |
96025800 | 144 | |
6a488035 | 145 | } |