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