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