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);
357 '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 public function testFormRuleRollingJoin1MonthFromNow() {
378 $unix1MFmNow = $unixNow +
(31 * 24 * 60 * 60);
380 'join_date' => date('m/d/Y', $unix1MFmNow),
383 'membership_type_id' => array('23', '3'),
386 $obj = new CRM_Member_Form_Membership();
387 $rc = $obj->formRule($params, $files, $obj);
389 // Should have found no valid membership status
390 $this->assertType('array', $rc,
391 'In line ' . __LINE__
393 $this->assertTrue(array_key_exists('_qf_default', $rc),
394 'In line ' . __LINE__
399 * Test CRM_Member_Form_Membership::formRule() with a join date
400 * of today and a rolling membership type
402 public function testFormRuleRollingJoinToday() {
405 'join_date' => date('m/d/Y', $unixNow),
408 'membership_type_id' => array('23', '3'),
411 $obj = new CRM_Member_Form_Membership();
412 $rc = $obj->formRule($params, $files, $obj);
414 // Should have found New membership status
415 $this->assertTrue($rc, 'In line ' . __LINE__
);
419 * Test CRM_Member_Form_Membership::formRule() with a join date
420 * of one month ago and a rolling membership type
422 public function testFormRuleRollingJoin1MonthAgo() {
424 $unix1MAgo = $unixNow - (31 * 24 * 60 * 60);
426 '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 public function testFormRuleRollingJoin6MonthsAgo() {
445 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
447 'join_date' => date('m/d/Y', $unix6MAgo),
450 'membership_type_id' => array('23', '3'),
453 $obj = new CRM_Member_Form_Membership();
454 $rc = $obj->formRule($params, $files, $obj);
456 // Should have found Current membership status
457 $this->assertTrue($rc, 'In line ' . __LINE__
);
461 * Test CRM_Member_Form_Membership::formRule() with a join date
462 * of one year+ ago and a rolling membership type
464 public function testFormRuleRollingJoin1YearAgo() {
466 $unix1YAgo = $unixNow - (370 * 24 * 60 * 60);
468 'join_date' => date('m/d/Y', $unix1YAgo),
471 'membership_type_id' => array('23', '3'),
474 $obj = new CRM_Member_Form_Membership();
475 $rc = $obj->formRule($params, $files, $obj);
477 // Should have found Grace membership status
478 $this->assertTrue($rc, 'In line ' . __LINE__
);
482 * Test CRM_Member_Form_Membership::formRule() with a join date
483 * of two years ago and a rolling membership type
485 public function testFormRuleRollingJoin2YearsAgo() {
487 $unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60);
489 'join_date' => date('m/d/Y', $unix2YAgo),
492 'membership_type_id' => array('23', '3'),
495 $obj = new CRM_Member_Form_Membership();
496 $rc = $obj->formRule($params, $files, $obj);
498 // Should have found Expired membership status
499 $this->assertTrue($rc, 'In line ' . __LINE__
);
503 * Test CRM_Member_Form_Membership::formRule() with a join date
504 * of six months ago and a fixed membership type
506 public function testFormRuleFixedJoin6MonthsAgo() {
508 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
510 'join_date' => date('m/d/Y', $unix6MAgo),
513 'membership_type_id' => array('23', '7'),
516 $obj = new CRM_Member_Form_Membership();
517 $rc = $obj->formRule($params, $files, $obj);
519 // Should have found Current membership status
520 $this->assertTrue($rc, 'In line ' . __LINE__
);
524 // class CRM_Member_Form_MembershipTest