Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | |
e9479dcf EM |
28 | /** |
29 | * Class CRM_Member_BAO_MembershipTypeTest | |
acb109b7 | 30 | * @group headless |
e9479dcf | 31 | */ |
6a488035 | 32 | class CRM_Member_BAO_MembershipTypeTest extends CiviUnitTestCase { |
6a488035 | 33 | |
00be9182 | 34 | public function setUp() { |
6a488035 TO |
35 | parent::setUp(); |
36 | ||
37 | //create relationship | |
38 | $params = array( | |
39 | 'name_a_b' => 'Relation 1', | |
40 | 'name_b_a' => 'Relation 2', | |
41 | 'contact_type_a' => 'Individual', | |
42 | 'contact_type_b' => 'Organization', | |
43 | 'is_reserved' => 1, | |
44 | 'is_active' => 1, | |
45 | ); | |
46 | $this->_relationshipTypeId = $this->relationshipTypeCreate($params); | |
47 | $this->_orgContactID = $this->organizationCreate(); | |
48 | $this->_indiviContactID = $this->individualCreate(); | |
e6ff1593 | 49 | $this->_financialTypeId = 1; |
6a488035 TO |
50 | $this->_membershipStatusID = $this->membershipStatusCreate('test status'); |
51 | } | |
52 | ||
53 | /** | |
54 | * Tears down the fixture, for example, closes a network connection. | |
55 | * This method is called after a test is executed. | |
6a488035 | 56 | */ |
00be9182 | 57 | public function tearDown() { |
6a488035 TO |
58 | $this->relationshipTypeDelete($this->_relationshipTypeId); |
59 | $this->membershipStatusDelete($this->_membershipStatusID); | |
6a488035 TO |
60 | $this->contactDelete($this->_orgContactID); |
61 | $this->contactDelete($this->_indiviContactID); | |
62 | } | |
63 | ||
87a890cc | 64 | /** |
65 | * check function add() | |
66 | * | |
67 | */ | |
00be9182 | 68 | public function testAdd() { |
6a488035 TO |
69 | $ids = array(); |
70 | $params = array( | |
71 | 'name' => 'test type', | |
72 | 'domain_id' => 1, | |
73 | 'description' => NULL, | |
74 | 'minimum_fee' => 10, | |
75 | 'duration_unit' => 'year', | |
76 | 'member_of_contact_id' => $this->_orgContactID, | |
77 | 'period_type' => 'fixed', | |
78 | 'duration_interval' => 1, | |
e6ff1593 | 79 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
80 | 'relationship_type_id' => $this->_relationshipTypeId, |
81 | 'visibility' => 'Public', | |
82 | ); | |
83 | ||
84 | $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); | |
85 | ||
86 | $membership = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $this->_orgContactID, | |
87 | 'name', 'member_of_contact_id', | |
88 | 'Database check on updated membership record.' | |
89 | ); | |
90 | ||
91 | $this->assertEquals($membership, 'test type', 'Verify membership type name.'); | |
92 | $this->membershipTypeDelete(array('id' => $membershipType->id)); | |
93 | } | |
94 | ||
87a890cc | 95 | /** |
96 | * check function retrive() | |
97 | * | |
98 | */ | |
00be9182 | 99 | public function testRetrieve() { |
6a488035 TO |
100 | $ids = array(); |
101 | $params = array( | |
102 | 'name' => 'General', | |
103 | 'description' => NULL, | |
104 | 'domain_id' => 1, | |
105 | 'minimum_fee' => 100, | |
106 | 'duration_unit' => 'year', | |
107 | 'period_type' => 'fixed', | |
108 | 'member_of_contact_id' => $this->_orgContactID, | |
109 | 'duration_interval' => 1, | |
e6ff1593 | 110 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
111 | 'relationship_type_id' => $this->_relationshipTypeId, |
112 | 'visibility' => 'Public', | |
113 | ); | |
114 | $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); | |
115 | ||
92915c55 | 116 | $params = array('name' => 'General'); |
6a488035 | 117 | $default = array(); |
92915c55 | 118 | $result = CRM_Member_BAO_MembershipType::retrieve($params, $default); |
6a488035 TO |
119 | $this->assertEquals($result->name, 'General', 'Verify membership type name.'); |
120 | $this->membershipTypeDelete(array('id' => $membershipType->id)); | |
121 | } | |
122 | ||
87a890cc | 123 | /** |
124 | * check function isActive() | |
125 | * | |
126 | */ | |
00be9182 | 127 | public function testSetIsActive() { |
6a488035 TO |
128 | $ids = array(); |
129 | $params = array( | |
130 | 'name' => 'General', | |
131 | 'description' => NULL, | |
132 | 'domain_id' => 1, | |
133 | 'minimum_fee' => 100, | |
134 | 'duration_unit' => 'year', | |
135 | 'period_type' => 'fixed', | |
136 | 'duration_interval' => 1, | |
137 | 'member_of_contact_id' => $this->_orgContactID, | |
e6ff1593 | 138 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
139 | 'relationship_type_id' => $this->_relationshipTypeId, |
140 | 'visibility' => 'Public', | |
141 | 'is_active' => 1, | |
142 | ); | |
143 | $membership = CRM_Member_BAO_MembershipType::add($params, $ids); | |
144 | ||
145 | CRM_Member_BAO_MembershipType::setIsActive($membership->id, 0); | |
146 | ||
147 | $isActive = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $membership->id, | |
148 | 'is_active', 'id', | |
149 | 'Database check on membership type status.' | |
150 | ); | |
151 | ||
152 | $this->assertEquals($isActive, 0, 'Verify membership type status.'); | |
153 | $this->membershipTypeDelete(array('id' => $membership->id)); | |
154 | } | |
155 | ||
87a890cc | 156 | /** |
157 | * check function del() | |
158 | * | |
159 | */ | |
00be9182 | 160 | public function testdel() { |
6a488035 TO |
161 | $ids = array(); |
162 | $params = array( | |
163 | 'name' => 'General', | |
164 | 'description' => NULL, | |
165 | 'minimum_fee' => 100, | |
166 | 'domain_id' => 1, | |
167 | 'duration_unit' => 'year', | |
168 | 'period_type' => 'fixed', | |
169 | 'member_of_contact_id' => $this->_orgContactID, | |
170 | 'duration_interval' => 1, | |
e6ff1593 | 171 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
172 | 'relationship_type_id' => $this->_relationshipTypeId, |
173 | 'visibility' => 'Public', | |
174 | 'is_active' => 1, | |
175 | ); | |
176 | $membership = CRM_Member_BAO_MembershipType::add($params, $ids); | |
177 | ||
178 | $result = CRM_Member_BAO_MembershipType::del($membership->id); | |
179 | ||
180 | $this->assertEquals($result, TRUE, 'Verify membership deleted.'); | |
181 | } | |
182 | ||
87a890cc | 183 | /** |
184 | * check function convertDayFormat( ) | |
185 | * | |
186 | */ | |
00be9182 | 187 | public function testConvertDayFormat() { |
6a488035 TO |
188 | $ids = array(); |
189 | $params = array( | |
190 | 'name' => 'General', | |
191 | 'description' => NULL, | |
192 | 'minimum_fee' => 100, | |
193 | 'domain_id' => 1, | |
194 | 'duration_unit' => 'year', | |
195 | 'period_type' => 'fixed', | |
196 | 'member_of_contact_id' => $this->_orgContactID, | |
197 | 'fixed_period_start_day' => 1213, | |
198 | 'fixed_period_rollover_day' => 1214, | |
199 | 'duration_interval' => 1, | |
e6ff1593 | 200 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
201 | 'relationship_type_id' => $this->_relationshipTypeId, |
202 | 'visibility' => 'Public', | |
203 | 'is_active' => 1, | |
204 | ); | |
205 | $membership = CRM_Member_BAO_MembershipType::add($params, $ids); | |
206 | $membershipType[$membership->id] = $params; | |
207 | ||
208 | CRM_Member_BAO_MembershipType::convertDayFormat($membershipType); | |
209 | ||
210 | $this->assertEquals($membershipType[$membership->id]['fixed_period_rollover_day'], 'Dec 14', 'Verify memberFixed Period Rollover Day.'); | |
211 | $this->membershipTypeDelete(array('id' => $membership->id)); | |
212 | } | |
213 | ||
87a890cc | 214 | /** |
215 | * check function getMembershipTypes( ) | |
216 | * | |
217 | */ | |
00be9182 | 218 | public function testGetMembershipTypes() { |
6a488035 TO |
219 | $ids = array(); |
220 | $params = array( | |
221 | 'name' => 'General', | |
222 | 'description' => NULL, | |
223 | 'minimum_fee' => 100, | |
224 | 'domain_id' => 1, | |
225 | 'duration_unit' => 'year', | |
226 | 'member_of_contact_id' => $this->_orgContactID, | |
227 | 'period_type' => 'fixed', | |
228 | 'duration_interval' => 1, | |
e6ff1593 | 229 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
230 | 'relationship_type_id' => $this->_relationshipTypeId, |
231 | 'visibility' => 'Public', | |
232 | 'is_active' => 1, | |
233 | ); | |
234 | $membership = CRM_Member_BAO_MembershipType::add($params, $ids); | |
235 | $result = CRM_Member_BAO_MembershipType::getMembershipTypes(); | |
236 | $this->assertEquals($result[$membership->id], 'General', 'Verify membership types.'); | |
237 | $this->membershipTypeDelete(array('id' => $membership->id)); | |
238 | } | |
239 | ||
87a890cc | 240 | /** |
241 | * check function getMembershipTypeDetails( ) | |
242 | * | |
243 | */ | |
00be9182 | 244 | public function testGetMembershipTypeDetails() { |
6a488035 TO |
245 | $ids = array(); |
246 | $params = array( | |
247 | 'name' => 'General', | |
248 | 'description' => NULL, | |
249 | 'minimum_fee' => 100, | |
250 | 'domain_id' => 1, | |
251 | 'duration_unit' => 'year', | |
252 | 'period_type' => 'fixed', | |
253 | 'member_of_contact_id' => $this->_orgContactID, | |
254 | 'duration_interval' => 1, | |
e6ff1593 | 255 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
256 | 'relationship_type_id' => $this->_relationshipTypeId, |
257 | 'visibility' => 'Public', | |
258 | 'is_active' => 1, | |
259 | ); | |
260 | $membership = CRM_Member_BAO_MembershipType::add($params, $ids); | |
261 | $result = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membership->id); | |
262 | ||
263 | $this->assertEquals($result['name'], 'General', 'Verify membership type details.'); | |
264 | $this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.'); | |
265 | $this->membershipTypeDelete(array('id' => $membership->id)); | |
266 | } | |
267 | ||
87a890cc | 268 | /** |
269 | * check function getDatesForMembershipType( ) | |
270 | * | |
271 | */ | |
00be9182 | 272 | public function testGetDatesForMembershipType() { |
6a488035 TO |
273 | $ids = array(); |
274 | $params = array( | |
275 | 'name' => 'General', | |
276 | 'description' => NULL, | |
277 | 'minimum_fee' => 100, | |
278 | 'domain_id' => 1, | |
279 | 'duration_unit' => 'year', | |
280 | 'member_of_contact_id' => $this->_orgContactID, | |
281 | 'period_type' => 'rolling', | |
282 | 'duration_interval' => 1, | |
e6ff1593 | 283 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
284 | 'relationship_type_id' => $this->_relationshipTypeId, |
285 | 'visibility' => 'Public', | |
286 | 'is_active' => 1, | |
287 | ); | |
288 | $membership = CRM_Member_BAO_MembershipType::add($params, $ids); | |
289 | ||
290 | $membershipDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->id); | |
291 | $this->assertEquals($membershipDates['start_date'], date('Ymd'), 'Verify membership types details.'); | |
292 | $this->membershipTypeDelete(array('id' => $membership->id)); | |
293 | } | |
294 | ||
87a890cc | 295 | /** |
296 | * check function getRenewalDatesForMembershipType( ) | |
297 | * | |
298 | */ | |
00be9182 | 299 | public function testGetRenewalDatesForMembershipType() { |
6a488035 TO |
300 | $ids = array(); |
301 | $params = array( | |
302 | 'name' => 'General', | |
303 | 'domain_id' => 1, | |
304 | 'description' => NULL, | |
305 | 'minimum_fee' => 100, | |
306 | 'duration_unit' => 'year', | |
307 | 'member_of_contact_id' => $this->_orgContactID, | |
308 | 'period_type' => 'rolling', | |
309 | 'duration_interval' => 1, | |
e6ff1593 | 310 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
311 | 'relationship_type_id' => $this->_relationshipTypeId, |
312 | 'visibility' => 'Public', | |
313 | 'is_active' => 1, | |
314 | ); | |
315 | $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); | |
316 | ||
317 | $params = array( | |
318 | 'contact_id' => $this->_indiviContactID, | |
319 | 'membership_type_id' => $membershipType->id, | |
320 | 'join_date' => '20060121000000', | |
321 | 'start_date' => '20060121000000', | |
322 | 'end_date' => '20070120000000', | |
323 | 'source' => 'Payment', | |
324 | 'is_override' => 1, | |
325 | 'status_id' => $this->_membershipStatusID, | |
326 | ); | |
327 | $ids = array(); | |
328 | $membership = CRM_Member_BAO_Membership::create($params, $ids); | |
329 | ||
330 | $membershipRenewDates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id); | |
331 | ||
332 | $this->assertEquals($membershipRenewDates['start_date'], '20060121', 'Verify membership renewal start date.'); | |
333 | $this->assertEquals($membershipRenewDates['end_date'], '20080120', 'Verify membership renewal end date.'); | |
334 | ||
335 | $this->membershipDelete($membership->id); | |
336 | $this->membershipTypeDelete(array('id' => $membershipType->id)); | |
337 | } | |
338 | ||
87a890cc | 339 | /** |
340 | * check function getMembershipTypesByOrg( ) | |
341 | * | |
342 | */ | |
00be9182 | 343 | public function testGetMembershipTypesByOrg() { |
6a488035 TO |
344 | $ids = array(); |
345 | $params = array( | |
346 | 'name' => 'General', | |
347 | 'description' => NULL, | |
348 | 'domain_id' => 1, | |
349 | 'minimum_fee' => 100, | |
350 | 'duration_unit' => 'year', | |
351 | 'member_of_contact_id' => $this->_orgContactID, | |
352 | 'period_type' => 'rolling', | |
353 | 'duration_interval' => 1, | |
e6ff1593 | 354 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
355 | 'relationship_type_id' => $this->_relationshipTypeId, |
356 | 'visibility' => 'Public', | |
357 | 'is_active' => 1, | |
358 | ); | |
359 | $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids); | |
360 | ||
4c50ac3a MW |
361 | $membershipTypesResult = civicrm_api3('MembershipType', 'get', array( |
362 | 'member_of_contact_id' => $this->_orgContactID, | |
c8eada29 MW |
363 | 'options' => array( |
364 | 'limit' => 0, | |
365 | ), | |
4c50ac3a MW |
366 | )); |
367 | $result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL); | |
6a488035 TO |
368 | $this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.'); |
369 | ||
4c50ac3a MW |
370 | $membershipTypesResult = civicrm_api3('MembershipType', 'get', array( |
371 | 'member_of_contact_id' => 501, | |
c8eada29 MW |
372 | 'options' => array( |
373 | 'limit' => 0, | |
374 | ), | |
4c50ac3a MW |
375 | )); |
376 | $result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL); | |
6a488035 TO |
377 | $this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.'); |
378 | ||
379 | $this->membershipTypeDelete(array('id' => $membershipType->id)); | |
380 | } | |
96025800 | 381 | |
6a488035 | 382 | } |