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
{
41 'name_a_b' => 'Relation 1',
42 'name_b_a' => 'Relation 2',
43 'contact_type_a' => 'Individual',
44 'contact_type_b' => 'Organization',
48 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
49 $this->_orgContactID
= $this->organizationCreate();
50 $this->_indiviContactID
= $this->individualCreate();
51 $this->_financialTypeId
= 1;
52 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
56 * Tears down the fixture, for example, closes a network connection.
57 * This method is called after a test is executed.
61 $this->relationshipTypeDelete($this->_relationshipTypeId
);
62 $this->membershipStatusDelete($this->_membershipStatusID
);
63 $this->contactDelete($this->_orgContactID
);
64 $this->contactDelete($this->_indiviContactID
);
67 /* check function add()
73 'name' => 'test type',
75 'description' => NULL,
77 'duration_unit' => 'year',
78 'member_of_contact_id' => $this->_orgContactID
,
79 'period_type' => 'fixed',
80 'duration_interval' => 1,
81 'financial_type_id' => $this->_financialTypeId
,
82 'relationship_type_id' => $this->_relationshipTypeId
,
83 'visibility' => 'Public',
86 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
88 $membership = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $this->_orgContactID
,
89 'name', 'member_of_contact_id',
90 'Database check on updated membership record.'
93 $this->assertEquals($membership, 'test type', 'Verify membership type name.');
94 $this->membershipTypeDelete(array('id' => $membershipType->id
));
97 /* check function retrive()
100 function testRetrieve() {
104 'description' => NULL,
106 'minimum_fee' => 100,
107 'duration_unit' => 'year',
108 'period_type' => 'fixed',
109 'member_of_contact_id' => $this->_orgContactID
,
110 'duration_interval' => 1,
111 'financial_type_id' => $this->_financialTypeId
,
112 'relationship_type_id' => $this->_relationshipTypeId
,
113 'visibility' => 'Public',
115 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
117 $params = array('name' => 'General');
119 $result = CRM_Member_BAO_MembershipType
::retrieve($params, $default);
120 $this->assertEquals($result->name
, 'General', 'Verify membership type name.');
121 $this->membershipTypeDelete(array('id' => $membershipType->id
));
124 /* check function isActive()
127 function testSetIsActive() {
131 'description' => NULL,
133 'minimum_fee' => 100,
134 'duration_unit' => 'year',
135 'period_type' => 'fixed',
136 'duration_interval' => 1,
137 'member_of_contact_id' => $this->_orgContactID
,
138 'financial_type_id' => $this->_financialTypeId
,
139 'relationship_type_id' => $this->_relationshipTypeId
,
140 'visibility' => 'Public',
143 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
145 CRM_Member_BAO_MembershipType
::setIsActive($membership->id
, 0);
147 $isActive = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $membership->id
,
149 'Database check on membership type status.'
152 $this->assertEquals($isActive, 0, 'Verify membership type status.');
153 $this->membershipTypeDelete(array('id' => $membership->id
));
156 /* check function del()
163 'description' => NULL,
164 'minimum_fee' => 100,
166 'duration_unit' => 'year',
167 'period_type' => 'fixed',
168 'member_of_contact_id' => $this->_orgContactID
,
169 'duration_interval' => 1,
170 'financial_type_id' => $this->_financialTypeId
,
171 'relationship_type_id' => $this->_relationshipTypeId
,
172 'visibility' => 'Public',
175 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
177 $result = CRM_Member_BAO_MembershipType
::del($membership->id
);
179 $this->assertEquals($result, TRUE, 'Verify membership deleted.');
182 /* check function convertDayFormat( )
185 function testConvertDayFormat() {
189 'description' => NULL,
190 'minimum_fee' => 100,
192 'duration_unit' => 'year',
193 'period_type' => 'fixed',
194 'member_of_contact_id' => $this->_orgContactID
,
195 'fixed_period_start_day' => 1213,
196 'fixed_period_rollover_day' => 1214,
197 'duration_interval' => 1,
198 'financial_type_id' => $this->_financialTypeId
,
199 'relationship_type_id' => $this->_relationshipTypeId
,
200 'visibility' => 'Public',
203 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
204 $membershipType[$membership->id
] = $params;
206 CRM_Member_BAO_MembershipType
::convertDayFormat($membershipType);
208 $this->assertEquals($membershipType[$membership->id
]['fixed_period_rollover_day'], 'Dec 14', 'Verify memberFixed Period Rollover Day.');
209 $this->membershipTypeDelete(array('id' => $membership->id
));
212 /* check function getMembershipTypes( )
215 function testGetMembershipTypes() {
219 'description' => NULL,
220 'minimum_fee' => 100,
222 'duration_unit' => 'year',
223 'member_of_contact_id' => $this->_orgContactID
,
224 'period_type' => 'fixed',
225 'duration_interval' => 1,
226 'financial_type_id' => $this->_financialTypeId
,
227 'relationship_type_id' => $this->_relationshipTypeId
,
228 'visibility' => 'Public',
231 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
232 $result = CRM_Member_BAO_MembershipType
::getMembershipTypes();
233 $this->assertEquals($result[$membership->id
], 'General', 'Verify membership types.');
234 $this->membershipTypeDelete(array('id' => $membership->id
));
237 /* check function getMembershipTypeDetails( )
240 function testGetMembershipTypeDetails() {
244 'description' => NULL,
245 'minimum_fee' => 100,
247 'duration_unit' => 'year',
248 'period_type' => 'fixed',
249 'member_of_contact_id' => $this->_orgContactID
,
250 'duration_interval' => 1,
251 'financial_type_id' => $this->_financialTypeId
,
252 'relationship_type_id' => $this->_relationshipTypeId
,
253 'visibility' => 'Public',
256 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
257 $result = CRM_Member_BAO_MembershipType
::getMembershipTypeDetails($membership->id
);
259 $this->assertEquals($result['name'], 'General', 'Verify membership type details.');
260 $this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.');
261 $this->membershipTypeDelete(array('id' => $membership->id
));
264 /* check function getDatesForMembershipType( )
267 function testGetDatesForMembershipType() {
271 'description' => NULL,
272 'minimum_fee' => 100,
274 'duration_unit' => 'year',
275 'member_of_contact_id' => $this->_orgContactID
,
276 'period_type' => 'rolling',
277 'duration_interval' => 1,
278 'financial_type_id' => $this->_financialTypeId
,
279 'relationship_type_id' => $this->_relationshipTypeId
,
280 'visibility' => 'Public',
283 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
285 $membershipDates = CRM_Member_BAO_MembershipType
::getDatesForMembershipType($membership->id
);
286 $this->assertEquals($membershipDates['start_date'], date('Ymd'), 'Verify membership types details.');
287 $this->membershipTypeDelete(array('id' => $membership->id
));
290 /* check function getRenewalDatesForMembershipType( )
293 function testGetRenewalDatesForMembershipType() {
298 'description' => NULL,
299 'minimum_fee' => 100,
300 'duration_unit' => 'year',
301 'member_of_contact_id' => $this->_orgContactID
,
302 'period_type' => 'rolling',
303 'duration_interval' => 1,
304 'financial_type_id' => $this->_financialTypeId
,
305 'relationship_type_id' => $this->_relationshipTypeId
,
306 'visibility' => 'Public',
309 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
312 'contact_id' => $this->_indiviContactID
,
313 'membership_type_id' => $membershipType->id
,
314 'join_date' => '20060121000000',
315 'start_date' => '20060121000000',
316 'end_date' => '20070120000000',
317 'source' => 'Payment',
319 'status_id' => $this->_membershipStatusID
,
322 $membership = CRM_Member_BAO_Membership
::create($params, $ids);
324 $membershipRenewDates = CRM_Member_BAO_MembershipType
::getRenewalDatesForMembershipType($membership->id
);
326 $this->assertEquals($membershipRenewDates['start_date'], '20060121', 'Verify membership renewal start date.');
327 $this->assertEquals($membershipRenewDates['end_date'], '20080120', 'Verify membership renewal end date.');
329 $this->membershipDelete($membership->id
);
330 $this->membershipTypeDelete(array('id' => $membershipType->id
));
333 /* check function getMembershipTypesByOrg( )
336 function testGetMembershipTypesByOrg() {
340 'description' => NULL,
342 'minimum_fee' => 100,
343 'duration_unit' => 'year',
344 'member_of_contact_id' => $this->_orgContactID
,
345 'period_type' => 'rolling',
346 'duration_interval' => 1,
347 'financial_type_id' => $this->_financialTypeId
,
348 'relationship_type_id' => $this->_relationshipTypeId
,
349 'visibility' => 'Public',
352 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
354 $result = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg($this->_orgContactID
);
355 $this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.');
357 $result = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg(501);
358 $this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.');
360 $this->membershipTypeDelete(array('id' => $membershipType->id
));