Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
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'; | |
e9479dcf EM |
30 | |
31 | /** | |
32 | * Class api_v3_MembershipTypeTest | |
33 | */ | |
6a488035 TO |
34 | class api_v3_MembershipTypeTest extends CiviUnitTestCase { |
35 | protected $_contactID; | |
36 | protected $_contributionTypeID; | |
37 | protected $_apiversion; | |
38 | protected $_entity = 'MembershipType'; | |
b7c9bc4c | 39 | |
00be9182 | 40 | public function setUp() { |
6a488035 | 41 | parent::setUp(); |
31c45547 | 42 | $this->useTransaction(TRUE); |
6a488035 TO |
43 | $this->_apiversion = 3; |
44 | $this->_contactID = $this->organizationCreate(NULL); | |
45 | } | |
46 | ||
00be9182 | 47 | public function testGetWithoutId() { |
6a488035 TO |
48 | $params = array( |
49 | 'name' => '60+ Membership', | |
50 | 'description' => 'people above 60 are given health instructions', | |
3d6a42e8 | 51 | 'financial_type_id' => 1, |
6a488035 TO |
52 | 'minimum_fee' => '200', |
53 | 'duration_unit' => 'month', | |
54 | 'duration_interval' => '10', | |
55 | 'visibility' => 'public', | |
6a488035 TO |
56 | ); |
57 | ||
d63167fc | 58 | $membershiptype = $this->callAPISuccess('membership_type', 'get', $params); |
6a488035 TO |
59 | $this->assertEquals($membershiptype['count'], 0); |
60 | } | |
61 | ||
00be9182 | 62 | public function testGet() { |
75638074 | 63 | $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID)); |
6a488035 TO |
64 | |
65 | $params = array( | |
66 | 'id' => $id, | |
6a488035 | 67 | ); |
d63167fc | 68 | $membershiptype = $this->callAPIAndDocument('membership_type', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
69 | $this->assertEquals($membershiptype['values'][$id]['name'], 'General', 'In line ' . __LINE__ . " id is " . $id); |
70 | $this->assertEquals($membershiptype['values'][$id]['member_of_contact_id'], $this->_contactID, 'In line ' . __LINE__); | |
3d6a42e8 | 71 | $this->assertEquals($membershiptype['values'][$id]['financial_type_id'], 1, 'In line ' . __LINE__); |
6a488035 TO |
72 | $this->assertEquals($membershiptype['values'][$id]['duration_unit'], 'year', 'In line ' . __LINE__); |
73 | $this->assertEquals($membershiptype['values'][$id]['duration_interval'], '1', 'In line ' . __LINE__); | |
74 | $this->assertEquals($membershiptype['values'][$id]['period_type'], 'rolling', 'In line ' . __LINE__); | |
75 | $this->membershipTypeDelete($params); | |
76 | } | |
77 | ||
78 | ///////////////// civicrm_membership_type_create methods | |
00be9182 | 79 | public function testCreateWithEmptyParams() { |
d0e1eff2 | 80 | $membershiptype = $this->callAPIFailure('membership_type', 'create', array()); |
6a488035 TO |
81 | $this->assertEquals($membershiptype['error_message'], |
82 | 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name' | |
83 | ); | |
84 | } | |
85 | ||
00be9182 | 86 | public function testCreateWithoutMemberOfContactId() { |
6a488035 TO |
87 | $params = array( |
88 | 'name' => '60+ Membership', | |
89 | 'description' => 'people above 60 are given health instructions', | |
3d6a42e8 | 90 | 'financial_type_id' => 1, |
6a488035 TO |
91 | 'domain_id' => '1', |
92 | 'minimum_fee' => '200', | |
93 | 'duration_unit' => 'month', | |
94 | 'duration_interval' => '10', | |
95 | 'period_type' => 'rolling', | |
96 | 'visibility' => 'public', | |
6a488035 TO |
97 | ); |
98 | ||
d63167fc | 99 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params, |
100 | 'Mandatory key(s) missing from params array: member_of_contact_id' | |
101 | ); | |
6a488035 TO |
102 | } |
103 | ||
00be9182 | 104 | public function testCreateWithoutContributionTypeId() { |
6a488035 TO |
105 | $params = array( |
106 | 'name' => '70+ Membership', | |
107 | 'description' => 'people above 70 are given health instructions', | |
108 | 'member_of_contact_id' => $this->_contactID, | |
109 | 'domain_id' => '1', | |
110 | 'minimum_fee' => '200', | |
111 | 'duration_unit' => 'month', | |
112 | 'duration_interval' => '10', | |
113 | 'period_type' => 'rolling', | |
d63167fc | 114 | 'visibility' => 'public', ); |
d0e1eff2 | 115 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); |
6a488035 TO |
116 | $this->assertEquals($membershiptype['error_message'], |
117 | 'Mandatory key(s) missing from params array: financial_type_id' | |
118 | ); | |
119 | } | |
120 | ||
00be9182 | 121 | public function testCreateWithoutDurationUnit() { |
6a488035 TO |
122 | $params = array( |
123 | 'name' => '80+ Membership', | |
124 | 'description' => 'people above 80 are given health instructions', | |
125 | 'member_of_contact_id' => $this->_contactID, | |
3d6a42e8 | 126 | 'financial_type_id' => 1, |
6a488035 TO |
127 | 'domain_id' => '1', |
128 | 'minimum_fee' => '200', | |
129 | 'duration_interval' => '10', | |
d63167fc | 130 | 'visibility' => 'public', ); |
6a488035 | 131 | |
d0e1eff2 | 132 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); |
6a488035 TO |
133 | $this->assertEquals($membershiptype['error_message'], |
134 | 'Mandatory key(s) missing from params array: duration_unit' | |
135 | ); | |
136 | } | |
137 | ||
00be9182 | 138 | public function testCreateWithoutDurationInterval() { |
6a488035 TO |
139 | $params = array( |
140 | 'name' => '70+ Membership', | |
141 | 'description' => 'people above 70 are given health instructions', | |
142 | 'member_of_contact_id' => $this->_contactID, | |
143 | 'domain_id' => '1', | |
144 | 'minimum_fee' => '200', | |
145 | 'duration_unit' => 'month', | |
146 | 'period_type' => 'rolling', | |
d63167fc | 147 | 'visibility' => 'public', ); |
d0e1eff2 | 148 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); |
6a488035 TO |
149 | $this->assertEquals($membershiptype['error_message'], |
150 | 'Mandatory key(s) missing from params array: financial_type_id, duration_interval' | |
151 | ); | |
152 | } | |
153 | ||
00be9182 | 154 | public function testCreateWithoutNameandDomainIDandDurationUnit() { |
6a488035 TO |
155 | $params = array( |
156 | 'description' => 'people above 50 are given health instructions', | |
157 | 'member_of_contact_id' => $this->_contactID, | |
3d6a42e8 | 158 | 'financial_type_id' => 1, |
6a488035 TO |
159 | 'minimum_fee' => '200', |
160 | 'duration_interval' => '10', | |
161 | 'period_type' => 'rolling', | |
d63167fc | 162 | 'visibility' => 'public', ); |
6a488035 | 163 | |
d0e1eff2 | 164 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); |
6a488035 TO |
165 | $this->assertEquals($membershiptype['error_message'], |
166 | 'Mandatory key(s) missing from params array: domain_id, duration_unit, name' | |
167 | ); | |
168 | } | |
169 | ||
00be9182 | 170 | public function testCreateWithoutName() { |
6a488035 TO |
171 | $params = array( |
172 | 'description' => 'people above 50 are given health instructions', | |
173 | 'member_of_contact_id' => $this->_contactID, | |
3d6a42e8 | 174 | 'financial_type_id' => 1, |
6a488035 TO |
175 | 'domain_id' => '1', |
176 | 'minimum_fee' => '200', | |
177 | 'duration_unit' => 'month', | |
178 | 'duration_interval' => '10', | |
179 | 'period_type' => 'rolling', | |
d63167fc | 180 | 'visibility' => 'public', ); |
6a488035 | 181 | |
d0e1eff2 | 182 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); |
6a488035 TO |
183 | $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: name'); |
184 | } | |
185 | ||
00be9182 | 186 | public function testCreate() { |
6a488035 TO |
187 | $params = array( |
188 | 'name' => '40+ Membership', | |
189 | 'description' => 'people above 40 are given health instructions', | |
190 | 'member_of_contact_id' => $this->_contactID, | |
3d6a42e8 | 191 | 'financial_type_id' => 1, |
6a488035 TO |
192 | 'domain_id' => '1', |
193 | 'minimum_fee' => '200', | |
194 | 'duration_unit' => 'month', | |
195 | 'duration_interval' => '10', | |
196 | 'period_type' => 'rolling', | |
197 | 'visibility' => 'public', | |
6a488035 TO |
198 | ); |
199 | ||
d63167fc | 200 | $membershiptype = $this->callAPIAndDocument('membership_type', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
201 | $this->assertNotNull($membershiptype['values']); |
202 | $this->membershipTypeDelete(array('id' => $membershiptype['id'])); | |
203 | } | |
204 | ||
6a488035 | 205 | |
00be9182 | 206 | public function testUpdateWithEmptyParams() { |
6a488035 | 207 | $params = array(); |
d0e1eff2 | 208 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); |
6a488035 | 209 | $this->assertEquals($membershiptype['error_message'], |
d0e1eff2 | 210 | 'Mandatory key(s) missing from params array: domain_id, member_of_contact_id, financial_type_id, duration_unit, duration_interval, name' |
6a488035 TO |
211 | ); |
212 | } | |
213 | ||
00be9182 | 214 | public function testUpdateWithoutId() { |
6a488035 TO |
215 | $params = array( |
216 | 'name' => '60+ Membership', | |
217 | 'description' => 'people above 60 are given health instructions', | |
218 | 'member_of_contact_id' => $this->_contactID, | |
3d6a42e8 | 219 | 'financial_type_id' => 1, |
6a488035 TO |
220 | 'minimum_fee' => '1200', |
221 | 'duration_unit' => 'month', | |
222 | 'duration_interval' => '10', | |
223 | 'period_type' => 'rolling', | |
d63167fc | 224 | 'visibility' => 'public', ); |
6a488035 | 225 | |
d0e1eff2 | 226 | $membershiptype = $this->callAPIFailure('membership_type', 'create', $params); |
6a488035 TO |
227 | $this->assertEquals($membershiptype['error_message'], 'Mandatory key(s) missing from params array: domain_id'); |
228 | } | |
229 | ||
00be9182 | 230 | public function testUpdate() { |
75638074 | 231 | $id = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID, 'financial_type_id' => 2)); |
6a488035 TO |
232 | $newMembOrgParams = array( |
233 | 'organization_name' => 'New membership organisation', | |
234 | 'contact_type' => 'Organization', | |
d63167fc | 235 | 'visibility' => 1, ); |
6a488035 TO |
236 | |
237 | // create a new contact to update this membership type to | |
238 | $newMembOrgID = $this->organizationCreate($newMembOrgParams); | |
239 | ||
240 | $params = array( | |
241 | 'id' => $id, | |
242 | 'name' => 'Updated General', | |
243 | 'member_of_contact_id' => $newMembOrgID, | |
244 | 'duration_unit' => 'month', | |
245 | 'duration_interval' => '10', | |
246 | 'period_type' => 'fixed', | |
d63167fc | 247 | 'domain_id' => 1, ); |
3d6a42e8 | 248 | |
d63167fc | 249 | $this->callAPISuccess('membership_type', 'update', $params); |
6a488035 TO |
250 | |
251 | $this->getAndCheck($params, $id, $this->_entity); | |
252 | } | |
253 | ||
00be9182 | 254 | public function testDeleteNotExists() { |
6a488035 TO |
255 | $params = array( |
256 | 'id' => 'doesNotExist', | |
6a488035 | 257 | ); |
d63167fc | 258 | $membershiptype = $this->callAPIFailure('membership_type', 'delete', $params, |
259 | 'Error while deleting membership type. id : ' . $params['id'] | |
260 | ); | |
6a488035 TO |
261 | } |
262 | ||
00be9182 | 263 | public function testDelete() { |
3d6a42e8 | 264 | $orgID = $this->organizationCreate(NULL); |
75638074 | 265 | $membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $orgID)); |
3d6a42e8 | 266 | $params = array( |
6a488035 | 267 | 'id' => $membershipTypeID, |
6a488035 TO |
268 | ); |
269 | ||
d63167fc | 270 | $result = $this->callAPIAndDocument('membership_type', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
271 | } |
272 | } |