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 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(
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);
335 $params = array('join_date' => date('m/d/Y', $unixNow),
336 'start_date' => date('m/d/Y', $unixNow),
337 'end_date' => date('m/d/Y',
340 'membership_type_id' => array('23', '13'),
343 $obj = new CRM_Member_Form_Membership
;
344 $rc = $obj->formRule($params, $files, $obj);
345 $this->assertType('array', $rc,
346 'In line ' . __LINE__
348 $this->assertTrue(array_key_exists('end_date', $rc),
349 'In line ' . __LINE__
354 * Test CRM_Member_Form_Membership::formRule() with a parameter
355 * that has an override and no status
357 function testFormRuleOverrideNoStatus() {
359 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
360 $params = array('join_date' => date('m/d/Y', $unixNow),
361 'membership_type_id' => array('23', '13'),
362 'is_override' => TRUE,
365 $obj = new CRM_Member_Form_Membership
;
366 $rc = $obj->formRule($params, $files, $obj);
367 $this->assertType('array', $rc,
368 'In line ' . __LINE__
370 $this->assertTrue(array_key_exists('status_id', $rc),
371 'In line ' . __LINE__
376 * Test CRM_Member_Form_Membership::formRule() with a join date
377 * of one month from now and a rolling membership type
379 function testFormRuleRollingJoin1MonthFromNow() {
381 $unix1MFmNow = $unixNow +
(31 * 24 * 60 * 60);
382 $params = array('join_date' => date('m/d/Y', $unix1MFmNow),
385 'membership_type_id' => array('23', '3'),
388 $obj = new CRM_Member_Form_Membership
;
389 $rc = $obj->formRule($params, $files, $obj);
391 // Should have found no valid membership status
392 $this->assertType('array', $rc,
393 'In line ' . __LINE__
395 $this->assertTrue(array_key_exists('_qf_default', $rc),
396 'In line ' . __LINE__
401 * Test CRM_Member_Form_Membership::formRule() with a join date
402 * of today and a rolling membership type
404 function testFormRuleRollingJoinToday() {
406 $params = array('join_date' => date('m/d/Y', $unixNow),
409 'membership_type_id' => array('23', '3'),
412 $obj = new CRM_Member_Form_Membership
;
413 $rc = $obj->formRule($params, $files, $obj);
415 // Should have found New membership status
416 $this->assertTrue($rc, 'In line ' . __LINE__
);
420 * Test CRM_Member_Form_Membership::formRule() with a join date
421 * of one month ago and a rolling membership type
423 function testFormRuleRollingJoin1MonthAgo() {
425 $unix1MAgo = $unixNow - (31 * 24 * 60 * 60);
426 $params = array('join_date' => date('m/d/Y', $unix1MAgo),
429 'membership_type_id' => array('23', '3'),
432 $obj = new CRM_Member_Form_Membership
;
433 $rc = $obj->formRule($params, $files, $obj);
435 // Should have found New membership status
436 $this->assertTrue($rc, 'In line ' . __LINE__
);
440 * Test CRM_Member_Form_Membership::formRule() with a join date
441 * of six months ago and a rolling membership type
443 function testFormRuleRollingJoin6MonthsAgo() {
445 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
446 $params = array('join_date' => date('m/d/Y', $unix6MAgo),
449 'membership_type_id' => array('23', '3'),
452 $obj = new CRM_Member_Form_Membership
;
453 $rc = $obj->formRule($params, $files, $obj);
455 // Should have found Current membership status
456 $this->assertTrue($rc, 'In line ' . __LINE__
);
460 * Test CRM_Member_Form_Membership::formRule() with a join date
461 * of one year+ ago and a rolling membership type
463 function testFormRuleRollingJoin1YearAgo() {
465 $unix1YAgo = $unixNow - (370 * 24 * 60 * 60);
466 $params = array('join_date' => date('m/d/Y', $unix1YAgo),
469 'membership_type_id' => array('23', '3'),
472 $obj = new CRM_Member_Form_Membership
;
473 $rc = $obj->formRule($params, $files, $obj);
475 // Should have found Grace membership status
476 $this->assertTrue($rc, 'In line ' . __LINE__
);
480 * Test CRM_Member_Form_Membership::formRule() with a join date
481 * of two years ago and a rolling membership type
483 function testFormRuleRollingJoin2YearsAgo() {
485 $unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60);
486 $params = array('join_date' => date('m/d/Y', $unix2YAgo),
489 'membership_type_id' => array('23', '3'),
492 $obj = new CRM_Member_Form_Membership
;
493 $rc = $obj->formRule($params, $files, $obj);
495 // Should have found Expired membership status
496 $this->assertTrue($rc, 'In line ' . __LINE__
);
500 * Test CRM_Member_Form_Membership::formRule() with a join date
501 * of six months ago and a fixed membership type
503 function testFormRuleFixedJoin6MonthsAgo() {
505 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
506 $params = array('join_date' => date('m/d/Y', $unix6MAgo),
509 'membership_type_id' => array('23', '7'),
512 $obj = new CRM_Member_Form_Membership
;
513 $rc = $obj->formRule($params, $files, $obj);
515 // Should have found Current membership status
516 $this->assertTrue($rc, 'In line ' . __LINE__
);
519 // class CRM_Member_Form_MembershipTest