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_mailing_component',
85 'civicrm_mailing_bounce_type',
86 'civicrm_mailing_bounce_pattern',
87 'civicrm_financial_type',
90 'civicrm_premiums_product',
91 'civicrm_sms_provider',
92 'civicrm_membership_status',
94 'civicrm_campaign_group',
96 'civicrm_participant_status_type',
97 'civicrm_event_carts',
98 'civicrm_dedupe_rule_group',
99 'civicrm_dedupe_rule',
100 'civicrm_dedupe_exception',
102 'civicrm_case_contact',
104 'civicrm_tell_friend',
105 'civicrm_pledge_block',
106 'civicrm_queue_item',
107 'civicrm_report_instance',
109 'civicrm_price_set_entity',
114 'civicrm_custom_group',
115 'civicrm_custom_field',
118 'civicrm_entity_batch',
119 'civicrm_entity_file',
120 'civicrm_entity_financial_trxn',
123 'civicrm_mapping_field',
126 'civicrm_option_value',
128 'civicrm_state_province',
137 'civicrm_dashboard_contact',
139 'civicrm_subscription_history',
140 'civicrm_group_contact_cache',
141 'civicrm_group_nesting',
142 'civicrm_group_organization',
143 'civicrm_relationship',
144 'civicrm_mailing_event_subscribe',
145 'civicrm_mailing_event_confirm',
146 'civicrm_contribution_recur',
147 'civicrm_contribution_page',
148 'civicrm_contribution_widget',
150 'civicrm_activity_contact',
151 'civicrm_case_activity',
153 'civicrm_price_field',
155 'civicrm_entity_tag',
156 'civicrm_msg_template',
160 'civicrm_action_schedule',
161 'civicrm_action_log',
163 'civicrm_mailing_group',
164 'civicrm_mailing_trackable_url',
165 'civicrm_mailing_job',
166 'civicrm_mailing_recipients',
167 'civicrm_mailing_spool',
168 'civicrm_mailing_event_queue',
169 'civicrm_mailing_event_bounce',
170 'civicrm_mailing_event_delivered',
171 'civicrm_mailing_event_forward',
172 'civicrm_mailing_event_opened',
173 'civicrm_mailing_event_reply',
174 'civicrm_mailing_event_trackable_url_open',
175 'civicrm_mailing_event_unsubscribe',
176 'civicrm_membership_type',
177 'civicrm_membership',
178 'civicrm_membership_block',
179 'civicrm_membership_log',
180 'civicrm_price_field_value',
185 'civicrm_group_contact',
186 'civicrm_contribution',
187 'civicrm_contribution_product',
188 'civicrm_contribution_soft',
189 'civicrm_membership_payment',
191 'civicrm_participant',
192 'civicrm_participant_payment',
193 'civicrm_events_in_carts',
194 'civicrm_pledge_payment',
199 $op = new PHPUnit_Extensions_Database_Operation_Insert();
200 $op->execute($this->_dbconn
,
201 $this->createFlatXMLDataSet(
202 dirname(__FILE__
) . '/dataset/data.xml'
208 * Test CRM_Member_Form_Membership::buildQuickForm()
210 //function testCRMMemberFormMembershipBuildQuickForm()
212 // throw new PHPUnit_Framework_IncompleteTestError( "not implemented" );
216 * Test CRM_Member_Form_Membership::formRule() with a parameter
217 * that has an empty contact_select_id value
219 public function testFormRuleEmptyContact() {
221 'contact_select_id' => 0,
222 'membership_type_id' => array(),
225 $obj = new CRM_Member_Form_Membership
;
226 $rc = $obj->formRule($params, $files, $obj);
227 $this->assertType('array', $rc,
228 'In line ' . __LINE__
230 $this->assertTrue(array_key_exists('membership_type_id', $rc),
231 'In line ' . __LINE__
234 $params['membership_type_id'] = array(1 => 3);
235 $rc = $obj->formRule($params, $files, $obj);
236 $this->assertType('array', $rc,
237 'In line ' . __LINE__
239 $this->assertTrue(array_key_exists('join_date', $rc),
240 'In line ' . __LINE__
245 * Test CRM_Member_Form_Membership::formRule() with a parameter
246 * that has an start date before the join date and a rolling
249 public function testFormRuleRollingEarlyStart() {
251 $ymdNow = date('m/d/Y', $unixNow);
252 $unixYesterday = $unixNow - (24 * 60 * 60);
253 $ymdYesterday = date('m/d/Y', $unixYesterday);
255 'join_date' => $ymdNow,
256 'start_date' => $ymdYesterday,
258 'membership_type_id' => array('23', '3'),
261 $obj = new CRM_Member_Form_Membership
;
262 $rc = call_user_func(array('CRM_Member_Form_Membership', 'formRule'),
263 $params, $files, $obj
265 $this->assertType('array', $rc,
266 'In line ' . __LINE__
268 $this->assertTrue(array_key_exists('start_date', $rc),
269 'In line ' . __LINE__
274 * Test CRM_Member_Form_Membership::formRule() with a parameter
275 * that has an end date before the start date and a rolling
278 public function testFormRuleRollingEarlyEnd() {
280 $ymdNow = date('m/d/Y', $unixNow);
281 $unixYesterday = $unixNow - (24 * 60 * 60);
282 $ymdYesterday = date('m/d/Y', $unixYesterday);
284 'join_date' => $ymdNow,
285 'start_date' => $ymdNow,
286 'end_date' => $ymdYesterday,
287 'membership_type_id' => array('23', '3'),
290 $obj = new CRM_Member_Form_Membership
;
291 $rc = $obj->formRule($params, $files, $obj);
292 $this->assertType('array', $rc,
293 'In line ' . __LINE__
295 $this->assertTrue(array_key_exists('end_date', $rc),
296 'In line ' . __LINE__
301 * Test CRM_Member_Form_Membership::formRule() with a parameter
302 * that has an end date but no start date and a rolling
305 public function testFormRuleRollingEndNoStart() {
307 $ymdNow = date('m/d/Y', $unixNow);
308 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
309 $ymdYearFromNow = date('m/d/Y', $unixYearFromNow);
311 'join_date' => $ymdNow,
313 'end_date' => $ymdYearFromNow,
314 'membership_type_id' => array('23', '3'),
317 $obj = new CRM_Member_Form_Membership
;
318 $rc = $obj->formRule($params, $files, $obj);
319 $this->assertType('array', $rc,
320 'In line ' . __LINE__
322 $this->assertTrue(array_key_exists('start_date', $rc),
323 'In line ' . __LINE__
328 * Test CRM_Member_Form_Membership::formRule() with a parameter
329 * that has an end date and a lifetime membership type
331 public function testFormRuleRollingLifetimeEnd() {
333 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
335 '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 $this->assertTrue(array_key_exists('status_id', $rc));
350 * Test CRM_Member_Form_Membership::formRule() with a parameter
351 * that has an override and no status
353 public function testFormRuleOverrideNoStatus() {
355 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
356 $params = array('join_date' => date('m/d/Y', $unixNow),
357 'membership_type_id' => array('23', '13'),
358 'is_override' => TRUE,
361 $obj = new CRM_Member_Form_Membership
;
362 $rc = $obj->formRule($params, $files, $obj);
363 $this->assertType('array', $rc,
364 'In line ' . __LINE__
366 $this->assertTrue(array_key_exists('status_id', $rc),
367 'In line ' . __LINE__
372 * Test CRM_Member_Form_Membership::formRule() with a join date
373 * of one month from now and a rolling membership type
375 public function testFormRuleRollingJoin1MonthFromNow() {
377 $unix1MFmNow = $unixNow +
(31 * 24 * 60 * 60);
378 $params = array('join_date' => date('m/d/Y', $unix1MFmNow),
381 'membership_type_id' => array('23', '3'),
384 $obj = new CRM_Member_Form_Membership
;
385 $rc = $obj->formRule($params, $files, $obj);
387 // Should have found no valid membership status
388 $this->assertType('array', $rc,
389 'In line ' . __LINE__
391 $this->assertTrue(array_key_exists('_qf_default', $rc),
392 'In line ' . __LINE__
397 * Test CRM_Member_Form_Membership::formRule() with a join date
398 * of today and a rolling membership type
400 public function testFormRuleRollingJoinToday() {
402 $params = array('join_date' => date('m/d/Y', $unixNow),
405 'membership_type_id' => array('23', '3'),
408 $obj = new CRM_Member_Form_Membership
;
409 $rc = $obj->formRule($params, $files, $obj);
411 // Should have found New membership status
412 $this->assertTrue($rc, 'In line ' . __LINE__
);
416 * Test CRM_Member_Form_Membership::formRule() with a join date
417 * of one month ago and a rolling membership type
419 public function testFormRuleRollingJoin1MonthAgo() {
421 $unix1MAgo = $unixNow - (31 * 24 * 60 * 60);
422 $params = array('join_date' => date('m/d/Y', $unix1MAgo),
425 'membership_type_id' => array('23', '3'),
428 $obj = new CRM_Member_Form_Membership
;
429 $rc = $obj->formRule($params, $files, $obj);
431 // Should have found New membership status
432 $this->assertTrue($rc, 'In line ' . __LINE__
);
436 * Test CRM_Member_Form_Membership::formRule() with a join date
437 * of six months ago and a rolling membership type
439 public function testFormRuleRollingJoin6MonthsAgo() {
441 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
442 $params = array('join_date' => date('m/d/Y', $unix6MAgo),
445 'membership_type_id' => array('23', '3'),
448 $obj = new CRM_Member_Form_Membership
;
449 $rc = $obj->formRule($params, $files, $obj);
451 // Should have found Current membership status
452 $this->assertTrue($rc, 'In line ' . __LINE__
);
456 * Test CRM_Member_Form_Membership::formRule() with a join date
457 * of one year+ ago and a rolling membership type
459 public function testFormRuleRollingJoin1YearAgo() {
461 $unix1YAgo = $unixNow - (370 * 24 * 60 * 60);
462 $params = array('join_date' => date('m/d/Y', $unix1YAgo),
465 'membership_type_id' => array('23', '3'),
468 $obj = new CRM_Member_Form_Membership
;
469 $rc = $obj->formRule($params, $files, $obj);
471 // Should have found Grace membership status
472 $this->assertTrue($rc, 'In line ' . __LINE__
);
476 * Test CRM_Member_Form_Membership::formRule() with a join date
477 * of two years ago and a rolling membership type
479 public function testFormRuleRollingJoin2YearsAgo() {
481 $unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60);
482 $params = array('join_date' => date('m/d/Y', $unix2YAgo),
485 'membership_type_id' => array('23', '3'),
488 $obj = new CRM_Member_Form_Membership
;
489 $rc = $obj->formRule($params, $files, $obj);
491 // Should have found Expired membership status
492 $this->assertTrue($rc, 'In line ' . __LINE__
);
496 * Test CRM_Member_Form_Membership::formRule() with a join date
497 * of six months ago and a fixed membership type
499 public function testFormRuleFixedJoin6MonthsAgo() {
501 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
502 $params = array('join_date' => date('m/d/Y', $unix6MAgo),
505 'membership_type_id' => array('23', '7'),
508 $obj = new CRM_Member_Form_Membership
;
509 $rc = $obj->formRule($params, $files, $obj);
511 // Should have found Current membership status
512 $this->assertTrue($rc, 'In line ' . __LINE__
);
515 // class CRM_Member_Form_MembershipTest