3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Class CRM_Member_BAO_MembershipTypeTest
34 class CRM_Member_BAO_MembershipTypeTest
extends CiviUnitTestCase
{
40 'name' => 'MembershipType BAOs',
41 'description' => 'Test all Member_BAO_MembershipType methods.',
42 'group' => 'CiviCRM BAO Tests',
51 'name_a_b' => 'Relation 1',
52 'name_b_a' => 'Relation 2',
53 'contact_type_a' => 'Individual',
54 'contact_type_b' => 'Organization',
58 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
59 $this->_orgContactID
= $this->organizationCreate();
60 $this->_indiviContactID
= $this->individualCreate();
61 $this->_financialTypeId
= 1;
62 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
66 * Tears down the fixture, for example, closes a network connection.
67 * This method is called after a test is executed.
71 $this->relationshipTypeDelete($this->_relationshipTypeId
);
72 $this->membershipStatusDelete($this->_membershipStatusID
);
73 $this->contactDelete($this->_orgContactID
);
74 $this->contactDelete($this->_indiviContactID
);
77 /* check function add()
83 'name' => 'test type',
85 'description' => NULL,
87 'duration_unit' => 'year',
88 'member_of_contact_id' => $this->_orgContactID
,
89 'period_type' => 'fixed',
90 'duration_interval' => 1,
91 'financial_type_id' => $this->_financialTypeId
,
92 'relationship_type_id' => $this->_relationshipTypeId
,
93 'visibility' => 'Public',
96 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
98 $membership = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $this->_orgContactID
,
99 'name', 'member_of_contact_id',
100 'Database check on updated membership record.'
103 $this->assertEquals($membership, 'test type', 'Verify membership type name.');
104 $this->membershipTypeDelete(array('id' => $membershipType->id
));
107 /* check function retrive()
110 function testRetrieve() {
114 'description' => NULL,
116 'minimum_fee' => 100,
117 'duration_unit' => 'year',
118 'period_type' => 'fixed',
119 'member_of_contact_id' => $this->_orgContactID
,
120 'duration_interval' => 1,
121 'financial_type_id' => $this->_financialTypeId
,
122 'relationship_type_id' => $this->_relationshipTypeId
,
123 'visibility' => 'Public',
125 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
127 $params = array('name' => 'General');
129 $result = CRM_Member_BAO_MembershipType
::retrieve($params, $default);
130 $this->assertEquals($result->name
, 'General', 'Verify membership type name.');
131 $this->membershipTypeDelete(array('id' => $membershipType->id
));
134 /* check function isActive()
137 function testSetIsActive() {
141 'description' => NULL,
143 'minimum_fee' => 100,
144 'duration_unit' => 'year',
145 'period_type' => 'fixed',
146 'duration_interval' => 1,
147 'member_of_contact_id' => $this->_orgContactID
,
148 'financial_type_id' => $this->_financialTypeId
,
149 'relationship_type_id' => $this->_relationshipTypeId
,
150 'visibility' => 'Public',
153 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
155 CRM_Member_BAO_MembershipType
::setIsActive($membership->id
, 0);
157 $isActive = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $membership->id
,
159 'Database check on membership type status.'
162 $this->assertEquals($isActive, 0, 'Verify membership type status.');
163 $this->membershipTypeDelete(array('id' => $membership->id
));
166 /* check function del()
173 'description' => NULL,
174 'minimum_fee' => 100,
176 'duration_unit' => 'year',
177 'period_type' => 'fixed',
178 'member_of_contact_id' => $this->_orgContactID
,
179 'duration_interval' => 1,
180 'financial_type_id' => $this->_financialTypeId
,
181 'relationship_type_id' => $this->_relationshipTypeId
,
182 'visibility' => 'Public',
185 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
187 $result = CRM_Member_BAO_MembershipType
::del($membership->id
);
189 $this->assertEquals($result, TRUE, 'Verify membership deleted.');
192 /* check function convertDayFormat( )
195 function testConvertDayFormat() {
199 'description' => NULL,
200 'minimum_fee' => 100,
202 'duration_unit' => 'year',
203 'period_type' => 'fixed',
204 'member_of_contact_id' => $this->_orgContactID
,
205 'fixed_period_start_day' => 1213,
206 'fixed_period_rollover_day' => 1214,
207 'duration_interval' => 1,
208 'financial_type_id' => $this->_financialTypeId
,
209 'relationship_type_id' => $this->_relationshipTypeId
,
210 'visibility' => 'Public',
213 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
214 $membershipType[$membership->id
] = $params;
216 CRM_Member_BAO_MembershipType
::convertDayFormat($membershipType);
218 $this->assertEquals($membershipType[$membership->id
]['fixed_period_rollover_day'], 'Dec 14', 'Verify memberFixed Period Rollover Day.');
219 $this->membershipTypeDelete(array('id' => $membership->id
));
222 /* check function getMembershipTypes( )
225 function testGetMembershipTypes() {
229 'description' => NULL,
230 'minimum_fee' => 100,
232 'duration_unit' => 'year',
233 'member_of_contact_id' => $this->_orgContactID
,
234 'period_type' => 'fixed',
235 'duration_interval' => 1,
236 'financial_type_id' => $this->_financialTypeId
,
237 'relationship_type_id' => $this->_relationshipTypeId
,
238 'visibility' => 'Public',
241 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
242 $result = CRM_Member_BAO_MembershipType
::getMembershipTypes();
243 $this->assertEquals($result[$membership->id
], 'General', 'Verify membership types.');
244 $this->membershipTypeDelete(array('id' => $membership->id
));
247 /* check function getMembershipTypeDetails( )
250 function testGetMembershipTypeDetails() {
254 'description' => NULL,
255 'minimum_fee' => 100,
257 'duration_unit' => 'year',
258 'period_type' => 'fixed',
259 'member_of_contact_id' => $this->_orgContactID
,
260 'duration_interval' => 1,
261 'financial_type_id' => $this->_financialTypeId
,
262 'relationship_type_id' => $this->_relationshipTypeId
,
263 'visibility' => 'Public',
266 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
267 $result = CRM_Member_BAO_MembershipType
::getMembershipTypeDetails($membership->id
);
269 $this->assertEquals($result['name'], 'General', 'Verify membership type details.');
270 $this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.');
271 $this->membershipTypeDelete(array('id' => $membership->id
));
274 /* check function getDatesForMembershipType( )
277 function testGetDatesForMembershipType() {
281 'description' => NULL,
282 'minimum_fee' => 100,
284 'duration_unit' => 'year',
285 'member_of_contact_id' => $this->_orgContactID
,
286 'period_type' => 'rolling',
287 'duration_interval' => 1,
288 'financial_type_id' => $this->_financialTypeId
,
289 'relationship_type_id' => $this->_relationshipTypeId
,
290 'visibility' => 'Public',
293 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
295 $membershipDates = CRM_Member_BAO_MembershipType
::getDatesForMembershipType($membership->id
);
296 $this->assertEquals($membershipDates['start_date'], date('Ymd'), 'Verify membership types details.');
297 $this->membershipTypeDelete(array('id' => $membership->id
));
300 /* check function getRenewalDatesForMembershipType( )
303 function testGetRenewalDatesForMembershipType() {
308 'description' => NULL,
309 'minimum_fee' => 100,
310 'duration_unit' => 'year',
311 'member_of_contact_id' => $this->_orgContactID
,
312 'period_type' => 'rolling',
313 'duration_interval' => 1,
314 'financial_type_id' => $this->_financialTypeId
,
315 'relationship_type_id' => $this->_relationshipTypeId
,
316 'visibility' => 'Public',
319 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
322 'contact_id' => $this->_indiviContactID
,
323 'membership_type_id' => $membershipType->id
,
324 'join_date' => '20060121000000',
325 'start_date' => '20060121000000',
326 'end_date' => '20070120000000',
327 'source' => 'Payment',
329 'status_id' => $this->_membershipStatusID
,
332 $membership = CRM_Member_BAO_Membership
::create($params, $ids);
334 $membershipRenewDates = CRM_Member_BAO_MembershipType
::getRenewalDatesForMembershipType($membership->id
);
336 $this->assertEquals($membershipRenewDates['start_date'], '20060121', 'Verify membership renewal start date.');
337 $this->assertEquals($membershipRenewDates['end_date'], '20080120', 'Verify membership renewal end date.');
339 $this->membershipDelete($membership->id
);
340 $this->membershipTypeDelete(array('id' => $membershipType->id
));
343 /* check function getMembershipTypesByOrg( )
346 function testGetMembershipTypesByOrg() {
350 'description' => NULL,
352 'minimum_fee' => 100,
353 'duration_unit' => 'year',
354 'member_of_contact_id' => $this->_orgContactID
,
355 'period_type' => 'rolling',
356 'duration_interval' => 1,
357 'financial_type_id' => $this->_financialTypeId
,
358 'relationship_type_id' => $this->_relationshipTypeId
,
359 'visibility' => 'Public',
362 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
364 $result = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg($this->_orgContactID
);
365 $this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.');
367 $result = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg(501);
368 $this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.');
370 $this->membershipTypeDelete(array('id' => $membershipType->id
));