Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 TO |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
31 | * Test APIv3 civicrm_membership_payment* functions | |
32 | * | |
6c6e6187 TO |
33 | * @package CiviCRM_APIv3 |
34 | * @subpackage API_Member | |
6a488035 | 35 | */ |
6a488035 TO |
36 | class api_v3_MembershipPaymentTest extends CiviUnitTestCase { |
37 | protected $_apiversion = 3; | |
38 | protected $_contactID; | |
39 | protected $_contributionTypeID; | |
40 | protected $_membershipTypeID; | |
41 | protected $_membershipStatusID; | |
42 | protected $_contribution = array(); | |
92915c55 | 43 | |
00be9182 | 44 | public function setUp() { |
6a488035 | 45 | parent::setUp(); |
fb0190bb | 46 | $this->useTransaction(TRUE); |
6a488035 TO |
47 | |
48 | $this->_contactID = $this->organizationCreate(NULL); | |
75638074 | 49 | $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); |
6a488035 TO |
50 | $this->_membershipStatusID = $this->membershipStatusCreate('test status'); |
51 | $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name'); | |
52 | $params = array( | |
53 | 'contact_id' => $this->_contactID, | |
54 | 'currency' => 'USD', | |
55 | 'financial_type_id' => 1, | |
56 | 'contribution_status_id' => 1, | |
57 | 'contribution_page_id' => NULL, | |
58 | 'payment_instrument_id' => 1, | |
59 | 'source' => 'STUDENT', | |
60 | 'receive_date' => '20080522000000', | |
61 | 'receipt_date' => '20080522000000', | |
62 | 'total_amount' => 200.00, | |
63 | 'trxn_id' => '22ereerwww322323', | |
64 | 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70', | |
65 | 'thankyou_date' => '20080522', | |
6a488035 TO |
66 | ); |
67 | ||
6c6e6187 | 68 | $this->_contribution = $this->callAPISuccess('contribution', 'create', $params); |
6a488035 TO |
69 | } |
70 | ||
6a488035 TO |
71 | ///////////////// civicrm_membership_payment_create methods |
72 | ||
73 | /** | |
74 | * Test civicrm_membership_payment_create with empty params. | |
75 | */ | |
76 | public function testCreateEmptyParams() { | |
771f3245 | 77 | $this->callAPIFailure('membership_payment', 'create', array(), 'Mandatory key(s) missing from params array: membership_id, contribution_id'); |
6a488035 TO |
78 | } |
79 | ||
80 | /** | |
81 | * Test civicrm_membership_payment_create - success expected. | |
82 | */ | |
83 | public function testCreate() { | |
e4d5f1e2 | 84 | $contactId = $this->individualCreate(); |
6a488035 | 85 | |
6a488035 TO |
86 | $params = array( |
87 | 'contact_id' => $contactId, | |
88 | 'membership_type_id' => $this->_membershipTypeID, | |
89 | 'join_date' => '2006-01-21', | |
90 | 'start_date' => '2006-01-21', | |
91 | 'end_date' => '2006-12-21', | |
92 | 'source' => 'Payment', | |
93 | 'is_override' => 1, | |
94 | 'status_id' => $this->_membershipStatusID, | |
6a488035 TO |
95 | ); |
96 | ||
771f3245 | 97 | $membership = $this->callAPISuccess('membership', 'create', $params); |
6a488035 TO |
98 | |
99 | $params = array( | |
100 | 'contribution_id' => $this->_contribution['id'], | |
101 | 'membership_id' => $membership['id'], | |
6a488035 | 102 | ); |
771f3245 | 103 | $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
104 | $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__); |
105 | $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__); | |
106 | ||
107 | } | |
108 | ||
109 | ||
110 | ///////////////// civicrm_membershipPayment_get methods | |
111 | ||
112 | /** | |
113 | * Test civicrm_membershipPayment_get with wrong params type. | |
114 | */ | |
115 | public function testGetWrongParamsType() { | |
116 | $params = 'eeee'; | |
771f3245 | 117 | $GetWrongParamsType = $this->callAPIFailure('membership_payment', 'get', $params, 'Input variable `params` is not an array'); |
6a488035 TO |
118 | } |
119 | ||
120 | /** | |
121 | * Test civicrm_membershipPayment_get - success expected. | |
122 | */ | |
123 | public function testGet() { | |
e4d5f1e2 | 124 | $contactId = $this->individualCreate(); |
6a488035 TO |
125 | $params = array( |
126 | 'contact_id' => $contactId, | |
127 | 'membership_type_id' => $this->_membershipTypeID, | |
128 | 'source' => 'Payment', | |
129 | 'is_override' => 1, | |
130 | 'status_id' => $this->_membershipStatusID, | |
6a488035 | 131 | ); |
771f3245 | 132 | |
133 | $membership = $this->callAPISuccess('membership', 'create', $params); | |
6a488035 TO |
134 | |
135 | $params = array( | |
136 | 'contribution_id' => $this->_contribution['id'], | |
771f3245 | 137 | 'membership_id' => $membership['id'], |
6a488035 | 138 | ); |
771f3245 | 139 | $this->callAPISuccess('membership_payment', 'create', $params); |
6a488035 | 140 | |
771f3245 | 141 | $result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__); |
142 | $this->assertEquals($result['values'][$result['id']]['membership_id'], $params['membership_id'], 'Check Membership Id'); | |
143 | $this->assertEquals($result['values'][$result['id']]['contribution_id'], $params['contribution_id'], 'Check Contribution Id'); | |
6a488035 | 144 | } |
96025800 | 145 | |
6a488035 | 146 | } |