4 * File for the MembershipTest class
8 * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
9 * @copyright Copyright CiviCRM LLC (C) 2009
10 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
11 * GNU Affero General Public License version 3
14 * This file is part of CiviCRM
16 * CiviCRM is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Affero General Public License
18 * as published by the Free Software Foundation; either version 3 of
19 * the License, or (at your option) any later version.
21 * CiviCRM is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public
27 * License along with this program. If not, see
28 * <http://www.gnu.org/licenses/>.
32 * Include class definitions
34 require_once 'CiviTest/CiviUnitTestCase.php';
36 require_once 'HTML/QuickForm/Page.php';
39 * Test APIv2 civicrm_activity_* functions
43 class CRM_Member_Form_MembershipTest
extends CiviUnitTestCase
{
46 * Test setup for every test
48 * Connect to the database, truncate the tables that will be used
49 * and redirect stdin to a temporary file
51 public function setUp() {
52 // Connect to the database
57 'civicrm_address_format',
61 'civicrm_financial_account',
62 'civicrm_financial_trxn',
65 'civicrm_location_type',
66 'civicrm_mail_settings',
69 'civicrm_option_group',
70 'civicrm_payment_processor',
71 'civicrm_payment_processor_type',
72 'civicrm_preferences_date',
73 'civicrm_worldregion',
76 'civicrm_prevnext_cache',
77 'civicrm_action_mapping',
79 'civicrm_acl_entity_role',
81 'civicrm_acl_contact_cache',
82 'civicrm_relationship_type',
83 'civicrm_saved_search',
84 'civicrm_contact_type',
85 'civicrm_mailing_component',
86 'civicrm_mailing_bounce_type',
87 'civicrm_mailing_bounce_pattern',
88 'civicrm_financial_type',
91 'civicrm_premiums_product',
92 'civicrm_sms_provider',
93 'civicrm_membership_status',
95 'civicrm_campaign_group',
97 'civicrm_participant_status_type',
98 'civicrm_event_carts',
99 'civicrm_dedupe_rule_group',
100 'civicrm_dedupe_rule',
101 'civicrm_dedupe_exception',
103 'civicrm_case_contact',
105 'civicrm_tell_friend',
106 'civicrm_pledge_block',
107 'civicrm_queue_item',
108 'civicrm_report_instance',
110 'civicrm_price_set_entity',
115 'civicrm_custom_group',
116 'civicrm_custom_field',
119 'civicrm_entity_batch',
120 'civicrm_entity_file',
121 'civicrm_entity_financial_trxn',
124 'civicrm_mapping_field',
127 'civicrm_option_value',
129 'civicrm_state_province',
138 'civicrm_dashboard_contact',
140 'civicrm_subscription_history',
141 'civicrm_group_contact_cache',
142 'civicrm_group_nesting',
143 'civicrm_group_organization',
144 'civicrm_relationship',
145 'civicrm_mailing_event_subscribe',
146 'civicrm_mailing_event_confirm',
147 'civicrm_contribution_recur',
148 'civicrm_contribution_page',
149 'civicrm_contribution_widget',
151 'civicrm_activity_contact',
152 'civicrm_case_activity',
154 'civicrm_price_field',
156 'civicrm_entity_tag',
157 'civicrm_msg_template',
161 'civicrm_action_schedule',
162 'civicrm_action_log',
164 'civicrm_mailing_group',
165 'civicrm_mailing_trackable_url',
166 'civicrm_mailing_job',
167 'civicrm_mailing_recipients',
168 'civicrm_mailing_spool',
169 'civicrm_mailing_event_queue',
170 'civicrm_mailing_event_bounce',
171 'civicrm_mailing_event_delivered',
172 'civicrm_mailing_event_forward',
173 'civicrm_mailing_event_opened',
174 'civicrm_mailing_event_reply',
175 'civicrm_mailing_event_trackable_url_open',
176 'civicrm_mailing_event_unsubscribe',
177 'civicrm_membership_type',
178 'civicrm_membership',
179 'civicrm_membership_block',
180 'civicrm_membership_log',
181 'civicrm_price_field_value',
186 'civicrm_group_contact',
187 'civicrm_contribution',
188 'civicrm_contribution_product',
189 'civicrm_contribution_soft',
190 'civicrm_membership_payment',
192 'civicrm_participant',
193 'civicrm_participant_payment',
194 'civicrm_events_in_carts',
195 'civicrm_pledge_payment',
200 $op = new PHPUnit_Extensions_Database_Operation_Insert();
201 $op->execute($this->_dbconn
,
202 $this->createFlatXMLDataSet(
203 dirname(__FILE__
) . '/dataset/data.xml'
209 * Test CRM_Member_Form_Membership::buildQuickForm()
211 //function testCRMMemberFormMembershipBuildQuickForm()
213 // throw new PHPUnit_Framework_IncompleteTestError( "not implemented" );
217 * Test CRM_Member_Form_Membership::formRule() with a parameter
218 * that has an empty contact_select_id value
220 function testFormRuleEmptyContact() {
222 'contact_select_id' => 0,
223 'membership_type_id' => array(),
226 $obj = new CRM_Member_Form_Membership
;
227 $rc = $obj->formRule($params, $files, $obj);
228 $this->assertType('array', $rc,
229 'In line ' . __LINE__
231 $this->assertTrue(array_key_exists('membership_type_id', $rc),
232 'In line ' . __LINE__
235 $params['membership_type_id'] = array(1 => 3);
236 $rc = $obj->formRule($params, $files, $obj);
237 $this->assertType('array', $rc,
238 'In line ' . __LINE__
240 $this->assertTrue(array_key_exists('join_date', $rc),
241 'In line ' . __LINE__
246 * Test CRM_Member_Form_Membership::formRule() with a parameter
247 * that has an start date before the join date and a rolling
250 function testFormRuleRollingEarlyStart() {
252 $ymdNow = date('m/d/Y', $unixNow);
253 $unixYesterday = $unixNow - (24 * 60 * 60);
254 $ymdYesterday = date('m/d/Y', $unixYesterday);
256 'join_date' => $ymdNow,
257 'start_date' => $ymdYesterday,
259 'membership_type_id' => array('23', '3'),
262 $obj = new CRM_Member_Form_Membership
;
263 $rc = call_user_func(array('CRM_Member_Form_Membership', 'formRule'),
264 $params, $files, $obj
266 $this->assertType('array', $rc,
267 'In line ' . __LINE__
269 $this->assertTrue(array_key_exists('start_date', $rc),
270 'In line ' . __LINE__
275 * Test CRM_Member_Form_Membership::formRule() with a parameter
276 * that has an end date before the start date and a rolling
279 function testFormRuleRollingEarlyEnd() {
281 $ymdNow = date('m/d/Y', $unixNow);
282 $unixYesterday = $unixNow - (24 * 60 * 60);
283 $ymdYesterday = date('m/d/Y', $unixYesterday);
285 'join_date' => $ymdNow,
286 'start_date' => $ymdNow,
287 'end_date' => $ymdYesterday,
288 'membership_type_id' => array('23', '3'),
291 $obj = new CRM_Member_Form_Membership
;
292 $rc = $obj->formRule($params, $files, $obj);
293 $this->assertType('array', $rc,
294 'In line ' . __LINE__
296 $this->assertTrue(array_key_exists('end_date', $rc),
297 'In line ' . __LINE__
302 * Test CRM_Member_Form_Membership::formRule() with a parameter
303 * that has an end date but no start date and a rolling
306 function testFormRuleRollingEndNoStart() {
308 $ymdNow = date('m/d/Y', $unixNow);
309 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
310 $ymdYearFromNow = date('m/d/Y', $unixYearFromNow);
312 'join_date' => $ymdNow,
314 'end_date' => $ymdYearFromNow,
315 'membership_type_id' => array('23', '3'),
318 $obj = new CRM_Member_Form_Membership
;
319 $rc = $obj->formRule($params, $files, $obj);
320 $this->assertType('array', $rc,
321 'In line ' . __LINE__
323 $this->assertTrue(array_key_exists('start_date', $rc),
324 'In line ' . __LINE__
329 * Test CRM_Member_Form_Membership::formRule() with a parameter
330 * that has an end date and a lifetime membership type
332 function testFormRuleRollingLifetimeEnd() {
334 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
336 'join_date' => date('m/d/Y', $unixNow),
337 'start_date' => date('m/d/Y', $unixNow),
338 'end_date' => date('m/d/Y',
341 'membership_type_id' => array('23', '13'),
344 $obj = new CRM_Member_Form_Membership
;
345 $rc = $obj->formRule($params, $files, $obj);
346 $this->assertType('array', $rc);
347 $this->assertTrue(array_key_exists('status_id', $rc));
351 * Test CRM_Member_Form_Membership::formRule() with a parameter
352 * that has an override and no status
354 function testFormRuleOverrideNoStatus() {
356 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
357 $params = array('join_date' => date('m/d/Y', $unixNow),
358 'membership_type_id' => array('23', '13'),
359 'is_override' => TRUE,
362 $obj = new CRM_Member_Form_Membership
;
363 $rc = $obj->formRule($params, $files, $obj);
364 $this->assertType('array', $rc,
365 'In line ' . __LINE__
367 $this->assertTrue(array_key_exists('status_id', $rc),
368 'In line ' . __LINE__
373 * Test CRM_Member_Form_Membership::formRule() with a join date
374 * of one month from now and a rolling membership type
376 function testFormRuleRollingJoin1MonthFromNow() {
378 $unix1MFmNow = $unixNow +
(31 * 24 * 60 * 60);
379 $params = array('join_date' => date('m/d/Y', $unix1MFmNow),
382 'membership_type_id' => array('23', '3'),
385 $obj = new CRM_Member_Form_Membership
;
386 $rc = $obj->formRule($params, $files, $obj);
388 // Should have found no valid membership status
389 $this->assertType('array', $rc,
390 'In line ' . __LINE__
392 $this->assertTrue(array_key_exists('_qf_default', $rc),
393 'In line ' . __LINE__
398 * Test CRM_Member_Form_Membership::formRule() with a join date
399 * of today and a rolling membership type
401 function testFormRuleRollingJoinToday() {
403 $params = array('join_date' => date('m/d/Y', $unixNow),
406 'membership_type_id' => array('23', '3'),
409 $obj = new CRM_Member_Form_Membership
;
410 $rc = $obj->formRule($params, $files, $obj);
412 // Should have found New membership status
413 $this->assertTrue($rc, 'In line ' . __LINE__
);
417 * Test CRM_Member_Form_Membership::formRule() with a join date
418 * of one month ago and a rolling membership type
420 function testFormRuleRollingJoin1MonthAgo() {
422 $unix1MAgo = $unixNow - (31 * 24 * 60 * 60);
423 $params = array('join_date' => date('m/d/Y', $unix1MAgo),
426 'membership_type_id' => array('23', '3'),
429 $obj = new CRM_Member_Form_Membership
;
430 $rc = $obj->formRule($params, $files, $obj);
432 // Should have found New membership status
433 $this->assertTrue($rc, 'In line ' . __LINE__
);
437 * Test CRM_Member_Form_Membership::formRule() with a join date
438 * of six months ago and a rolling membership type
440 function testFormRuleRollingJoin6MonthsAgo() {
442 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
443 $params = array('join_date' => date('m/d/Y', $unix6MAgo),
446 'membership_type_id' => array('23', '3'),
449 $obj = new CRM_Member_Form_Membership
;
450 $rc = $obj->formRule($params, $files, $obj);
452 // Should have found Current membership status
453 $this->assertTrue($rc, 'In line ' . __LINE__
);
457 * Test CRM_Member_Form_Membership::formRule() with a join date
458 * of one year+ ago and a rolling membership type
460 function testFormRuleRollingJoin1YearAgo() {
462 $unix1YAgo = $unixNow - (370 * 24 * 60 * 60);
463 $params = array('join_date' => date('m/d/Y', $unix1YAgo),
466 'membership_type_id' => array('23', '3'),
469 $obj = new CRM_Member_Form_Membership
;
470 $rc = $obj->formRule($params, $files, $obj);
472 // Should have found Grace membership status
473 $this->assertTrue($rc, 'In line ' . __LINE__
);
477 * Test CRM_Member_Form_Membership::formRule() with a join date
478 * of two years ago and a rolling membership type
480 function testFormRuleRollingJoin2YearsAgo() {
482 $unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60);
483 $params = array('join_date' => date('m/d/Y', $unix2YAgo),
486 'membership_type_id' => array('23', '3'),
489 $obj = new CRM_Member_Form_Membership
;
490 $rc = $obj->formRule($params, $files, $obj);
492 // Should have found Expired membership status
493 $this->assertTrue($rc, 'In line ' . __LINE__
);
497 * Test CRM_Member_Form_Membership::formRule() with a join date
498 * of six months ago and a fixed membership type
500 function testFormRuleFixedJoin6MonthsAgo() {
502 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
503 $params = array('join_date' => date('m/d/Y', $unix6MAgo),
506 'membership_type_id' => array('23', '7'),
509 $obj = new CRM_Member_Form_Membership
;
510 $rc = $obj->formRule($params, $files, $obj);
512 // Should have found Current membership status
513 $this->assertTrue($rc, 'In line ' . __LINE__
);
516 // class CRM_Member_Form_MembershipTest