3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
{
36 public function setUp() {
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.
59 public function tearDown() {
60 $this->relationshipTypeDelete($this->_relationshipTypeId
);
61 $this->membershipStatusDelete($this->_membershipStatusID
);
62 $this->contactDelete($this->_orgContactID
);
63 $this->contactDelete($this->_indiviContactID
);
67 * check function add()
70 public function testAdd() {
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
));
98 * check function retrive()
101 public function testRetrieve() {
105 'description' => NULL,
107 'minimum_fee' => 100,
108 'duration_unit' => 'year',
109 'period_type' => 'fixed',
110 'member_of_contact_id' => $this->_orgContactID
,
111 'duration_interval' => 1,
112 'financial_type_id' => $this->_financialTypeId
,
113 'relationship_type_id' => $this->_relationshipTypeId
,
114 'visibility' => 'Public',
116 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
118 $params = array('name' => 'General');
120 $result = CRM_Member_BAO_MembershipType
::retrieve($params, $default);
121 $this->assertEquals($result->name
, 'General', 'Verify membership type name.');
122 $this->membershipTypeDelete(array('id' => $membershipType->id
));
126 * check function isActive()
129 public function testSetIsActive() {
133 'description' => NULL,
135 'minimum_fee' => 100,
136 'duration_unit' => 'year',
137 'period_type' => 'fixed',
138 'duration_interval' => 1,
139 'member_of_contact_id' => $this->_orgContactID
,
140 'financial_type_id' => $this->_financialTypeId
,
141 'relationship_type_id' => $this->_relationshipTypeId
,
142 'visibility' => 'Public',
145 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
147 CRM_Member_BAO_MembershipType
::setIsActive($membership->id
, 0);
149 $isActive = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $membership->id
,
151 'Database check on membership type status.'
154 $this->assertEquals($isActive, 0, 'Verify membership type status.');
155 $this->membershipTypeDelete(array('id' => $membership->id
));
159 * check function del()
162 public function testdel() {
166 'description' => NULL,
167 'minimum_fee' => 100,
169 'duration_unit' => 'year',
170 'period_type' => 'fixed',
171 'member_of_contact_id' => $this->_orgContactID
,
172 'duration_interval' => 1,
173 'financial_type_id' => $this->_financialTypeId
,
174 'relationship_type_id' => $this->_relationshipTypeId
,
175 'visibility' => 'Public',
178 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
180 $result = CRM_Member_BAO_MembershipType
::del($membership->id
);
182 $this->assertEquals($result, TRUE, 'Verify membership deleted.');
186 * check function convertDayFormat( )
189 public function testConvertDayFormat() {
193 'description' => NULL,
194 'minimum_fee' => 100,
196 'duration_unit' => 'year',
197 'period_type' => 'fixed',
198 'member_of_contact_id' => $this->_orgContactID
,
199 'fixed_period_start_day' => 1213,
200 'fixed_period_rollover_day' => 1214,
201 'duration_interval' => 1,
202 'financial_type_id' => $this->_financialTypeId
,
203 'relationship_type_id' => $this->_relationshipTypeId
,
204 'visibility' => 'Public',
207 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
208 $membershipType[$membership->id
] = $params;
210 CRM_Member_BAO_MembershipType
::convertDayFormat($membershipType);
212 $this->assertEquals($membershipType[$membership->id
]['fixed_period_rollover_day'], 'Dec 14', 'Verify memberFixed Period Rollover Day.');
213 $this->membershipTypeDelete(array('id' => $membership->id
));
217 * check function getMembershipTypes( )
220 public function testGetMembershipTypes() {
224 'description' => NULL,
225 'minimum_fee' => 100,
227 'duration_unit' => 'year',
228 'member_of_contact_id' => $this->_orgContactID
,
229 'period_type' => 'fixed',
230 'duration_interval' => 1,
231 'financial_type_id' => $this->_financialTypeId
,
232 'relationship_type_id' => $this->_relationshipTypeId
,
233 'visibility' => 'Public',
236 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
237 $result = CRM_Member_BAO_MembershipType
::getMembershipTypes();
238 $this->assertEquals($result[$membership->id
], 'General', 'Verify membership types.');
239 $this->membershipTypeDelete(array('id' => $membership->id
));
243 * check function getMembershipTypeDetails( )
246 public function testGetMembershipTypeDetails() {
250 'description' => NULL,
251 'minimum_fee' => 100,
253 'duration_unit' => 'year',
254 'period_type' => 'fixed',
255 'member_of_contact_id' => $this->_orgContactID
,
256 'duration_interval' => 1,
257 'financial_type_id' => $this->_financialTypeId
,
258 'relationship_type_id' => $this->_relationshipTypeId
,
259 'visibility' => 'Public',
262 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
263 $result = CRM_Member_BAO_MembershipType
::getMembershipTypeDetails($membership->id
);
265 $this->assertEquals($result['name'], 'General', 'Verify membership type details.');
266 $this->assertEquals($result['duration_unit'], 'year', 'Verify membership types details.');
267 $this->membershipTypeDelete(array('id' => $membership->id
));
271 * check function getDatesForMembershipType( )
274 public function testGetDatesForMembershipType() {
278 'description' => NULL,
279 'minimum_fee' => 100,
281 'duration_unit' => 'year',
282 'member_of_contact_id' => $this->_orgContactID
,
283 'period_type' => 'rolling',
284 'duration_interval' => 1,
285 'financial_type_id' => $this->_financialTypeId
,
286 'relationship_type_id' => $this->_relationshipTypeId
,
287 'visibility' => 'Public',
290 $membership = CRM_Member_BAO_MembershipType
::add($params, $ids);
292 $membershipDates = CRM_Member_BAO_MembershipType
::getDatesForMembershipType($membership->id
);
293 $this->assertEquals($membershipDates['start_date'], date('Ymd'), 'Verify membership types details.');
294 $this->membershipTypeDelete(array('id' => $membership->id
));
298 * check function getRenewalDatesForMembershipType( )
301 public function testGetRenewalDatesForMembershipType() {
306 'description' => NULL,
307 'minimum_fee' => 100,
308 'duration_unit' => 'year',
309 'member_of_contact_id' => $this->_orgContactID
,
310 'period_type' => 'rolling',
311 'duration_interval' => 1,
312 'financial_type_id' => $this->_financialTypeId
,
313 'relationship_type_id' => $this->_relationshipTypeId
,
314 'visibility' => 'Public',
317 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
320 'contact_id' => $this->_indiviContactID
,
321 'membership_type_id' => $membershipType->id
,
322 'join_date' => '20060121000000',
323 'start_date' => '20060121000000',
324 'end_date' => '20070120000000',
325 'source' => 'Payment',
327 'status_id' => $this->_membershipStatusID
,
330 $membership = CRM_Member_BAO_Membership
::create($params, $ids);
332 $membershipRenewDates = CRM_Member_BAO_MembershipType
::getRenewalDatesForMembershipType($membership->id
);
334 $this->assertEquals($membershipRenewDates['start_date'], '20060121', 'Verify membership renewal start date.');
335 $this->assertEquals($membershipRenewDates['end_date'], '20080120', 'Verify membership renewal end date.');
337 $this->membershipDelete($membership->id
);
338 $this->membershipTypeDelete(array('id' => $membershipType->id
));
342 * check function getMembershipTypesByOrg( )
345 public function testGetMembershipTypesByOrg() {
349 'description' => NULL,
351 'minimum_fee' => 100,
352 'duration_unit' => 'year',
353 'member_of_contact_id' => $this->_orgContactID
,
354 'period_type' => 'rolling',
355 'duration_interval' => 1,
356 'financial_type_id' => $this->_financialTypeId
,
357 'relationship_type_id' => $this->_relationshipTypeId
,
358 'visibility' => 'Public',
361 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
363 $result = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg($this->_orgContactID
);
364 $this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.');
366 $result = CRM_Member_BAO_MembershipType
::getMembershipTypesByOrg(501);
367 $this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.');
369 $this->membershipTypeDelete(array('id' => $membershipType->id
));