3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 * File for the MembershipTest class
33 * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
37 * Include class definitions
39 require_once 'CiviTest/CiviUnitTestCase.php';
41 require_once 'HTML/QuickForm/Page.php';
44 * Test CRM_Member_Form_Membership functions.
48 class CRM_Member_Form_MembershipTest
extends CiviUnitTestCase
{
51 * Assume empty database with just civicrm_data.
53 protected $_individualId;
54 protected $_contribution;
55 protected $_financialTypeId = 1;
56 protected $_apiversion;
57 protected $_entity = 'Membership';
59 protected $_ids = array();
60 protected $_paymentProcessorID;
63 * Parameters to create payment processor.
67 protected $_processorParams = array();
70 * ID of created membership.
74 protected $_membershipID;
77 * Payment instrument mapping.
81 protected $paymentInstruments = array();
84 * Test setup for every test.
86 * Connect to the database, truncate the tables that will be used
87 * and redirect stdin to a temporary file.
89 public function setUp() {
90 $this->_apiversion
= 3;
93 $this->_individualId
= $this->individualCreate();
94 $this->_paymentProcessorID
= $this->processorCreate();
96 $op = new PHPUnit_Extensions_Database_Operation_Insert();
97 $op->execute($this->_dbconn
,
98 $this->createFlatXMLDataSet(
99 dirname(__FILE__
) . '/dataset/data.xml'
103 $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
104 $this->paymentInstruments
= $instruments['values'];
108 * Clean up after each test.
110 public function tearDown() {
111 $this->quickCleanUpFinancialEntities();
114 'civicrm_relationship',
115 'civicrm_membership_type',
116 'civicrm_membership',
119 $this->callAPISuccess('contact', 'delete', array('id' => 17, 'skip_undelete' => TRUE));
120 $this->callAPISuccess('contact', 'delete', array('id' => 23, 'skip_undelete' => TRUE));
121 $this->callAPISuccess('relationship_type', 'delete', array('id' => 20));
125 * Test CRM_Member_Form_Membership::buildQuickForm()
127 //function testCRMMemberFormMembershipBuildQuickForm()
129 // throw new PHPUnit_Framework_IncompleteTestError( "not implemented" );
133 * Test CRM_Member_Form_Membership::formRule() with a parameter
134 * that has an empty contact_select_id value
136 public function testFormRuleEmptyContact() {
138 'contact_select_id' => 0,
139 'membership_type_id' => array(),
142 $obj = new CRM_Member_Form_Membership();
143 $rc = $obj->formRule($params, $files, $obj);
144 $this->assertType('array', $rc);
145 $this->assertTrue(array_key_exists('membership_type_id', $rc));
147 $params['membership_type_id'] = array(1 => 3);
148 $rc = $obj->formRule($params, $files, $obj);
149 $this->assertType('array', $rc);
150 $this->assertTrue(array_key_exists('join_date', $rc));
154 * Test that form rule fails if start date is before join date.
156 * Test CRM_Member_Form_Membership::formRule() with a parameter
157 * that has an start date before the join date and a rolling
160 public function testFormRuleRollingEarlyStart() {
162 $ymdNow = date('m/d/Y', $unixNow);
163 $unixYesterday = $unixNow - (24 * 60 * 60);
164 $ymdYesterday = date('m/d/Y', $unixYesterday);
166 'join_date' => $ymdNow,
167 'start_date' => $ymdYesterday,
169 'membership_type_id' => array('23', '15'),
172 $obj = new CRM_Member_Form_Membership();
173 $rc = call_user_func(array('CRM_Member_Form_Membership', 'formRule'),
174 $params, $files, $obj
176 $this->assertType('array', $rc);
177 $this->assertTrue(array_key_exists('start_date', $rc));
181 * Test CRM_Member_Form_Membership::formRule() with a parameter
182 * that has an end date before the start date and a rolling
185 public function testFormRuleRollingEarlyEnd() {
187 $ymdNow = date('m/d/Y', $unixNow);
188 $unixYesterday = $unixNow - (24 * 60 * 60);
189 $ymdYesterday = date('m/d/Y', $unixYesterday);
191 'join_date' => $ymdNow,
192 'start_date' => $ymdNow,
193 'end_date' => $ymdYesterday,
194 'membership_type_id' => array('23', '15'),
197 $obj = new CRM_Member_Form_Membership();
198 $rc = $obj->formRule($params, $files, $obj);
199 $this->assertType('array', $rc,
200 'In line ' . __LINE__
202 $this->assertTrue(array_key_exists('end_date', $rc),
203 'In line ' . __LINE__
208 * Test CRM_Member_Form_Membership::formRule() with end date but no start date and a rolling membership type.
210 public function testFormRuleRollingEndNoStart() {
212 $ymdNow = date('m/d/Y', $unixNow);
213 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
214 $ymdYearFromNow = date('m/d/Y', $unixYearFromNow);
216 'join_date' => $ymdNow,
218 'end_date' => $ymdYearFromNow,
219 'membership_type_id' => array('23', '15'),
222 $obj = new CRM_Member_Form_Membership();
223 $rc = $obj->formRule($params, $files, $obj);
224 $this->assertType('array', $rc,
225 'In line ' . __LINE__
227 $this->assertTrue(array_key_exists('start_date', $rc),
228 'In line ' . __LINE__
233 * Test CRM_Member_Form_Membership::formRule() with a parameter
234 * that has an end date and a lifetime membership type
236 public function testFormRuleRollingLifetimeEnd() {
238 $unixYearFromNow = $unixNow +
(365 * 24 * 60 * 60);
240 'join_date' => date('m/d/Y', $unixNow),
241 'start_date' => date('m/d/Y', $unixNow),
242 'end_date' => date('m/d/Y',
245 'membership_type_id' => array('23', '25'),
248 $obj = new CRM_Member_Form_Membership();
249 $rc = $obj->formRule($params, $files, $obj);
250 $this->assertType('array', $rc);
251 $this->assertTrue(array_key_exists('status_id', $rc));
255 * Test CRM_Member_Form_Membership::formRule() with a parameter
256 * that has an override and no status
258 public function testFormRuleOverrideNoStatus() {
261 'join_date' => date('m/d/Y', $unixNow),
262 'membership_type_id' => array('23', '25'),
263 'is_override' => TRUE,
266 $obj = new CRM_Member_Form_Membership();
267 $rc = $obj->formRule($params, $files, $obj);
268 $this->assertType('array', $rc);
269 $this->assertTrue(array_key_exists('status_id', $rc));
273 * Test CRM_Member_Form_Membership::formRule() with a join date
274 * of one month from now and a rolling membership type
276 public function testFormRuleRollingJoin1MonthFromNow() {
278 $unix1MFmNow = $unixNow +
(31 * 24 * 60 * 60);
280 'join_date' => date('m/d/Y', $unix1MFmNow),
283 'membership_type_id' => array('23', '15'),
286 $obj = new CRM_Member_Form_Membership();
287 $rc = $obj->formRule($params, $files, $obj);
289 // Should have found no valid membership status.
290 $this->assertType('array', $rc);
291 $this->assertTrue(array_key_exists('_qf_default', $rc));
295 * Test CRM_Member_Form_Membership::formRule() with a join date of today and a rolling membership type.
297 public function testFormRuleRollingJoinToday() {
300 'join_date' => date('m/d/Y', $unixNow),
303 'membership_type_id' => array('23', '15'),
306 $obj = new CRM_Member_Form_Membership();
307 $rc = $obj->formRule($params, $files, $obj);
309 // Should have found New membership status
310 $this->assertTrue($rc, 'In line ' . __LINE__
);
314 * Test CRM_Member_Form_Membership::formRule() with a join date
315 * of one month ago and a rolling membership type
317 public function testFormRuleRollingJoin1MonthAgo() {
319 $unix1MAgo = $unixNow - (31 * 24 * 60 * 60);
321 'join_date' => date('m/d/Y', $unix1MAgo),
324 'membership_type_id' => array('23', '15'),
327 $obj = new CRM_Member_Form_Membership();
328 $rc = $obj->formRule($params, $files, $obj);
330 // Should have found New membership status.
331 $this->assertTrue($rc);
335 * Test CRM_Member_Form_Membership::formRule() with a join date of six months ago and a rolling membership type.
337 public function testFormRuleRollingJoin6MonthsAgo() {
339 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
341 'join_date' => date('m/d/Y', $unix6MAgo),
344 'membership_type_id' => array('23', '15'),
347 $obj = new CRM_Member_Form_Membership();
348 $rc = $obj->formRule($params, $files, $obj);
350 // Should have found Current membership status.
351 $this->assertTrue($rc);
355 * Test CRM_Member_Form_Membership::formRule() with a join date
356 * of one year+ ago and a rolling membership type
358 public function testFormRuleRollingJoin1YearAgo() {
360 $unix1YAgo = $unixNow - (370 * 24 * 60 * 60);
362 'join_date' => date('m/d/Y', $unix1YAgo),
365 'membership_type_id' => array('23', '15'),
368 $obj = new CRM_Member_Form_Membership();
369 $rc = $obj->formRule($params, $files, $obj);
371 // Should have found Grace membership status
372 $this->assertTrue($rc, 'In line ' . __LINE__
);
376 * Test CRM_Member_Form_Membership::formRule() with a join date
377 * of two years ago and a rolling membership type
379 public function testFormRuleRollingJoin2YearsAgo() {
381 $unix2YAgo = $unixNow - (2 * 365 * 24 * 60 * 60);
383 'join_date' => date('m/d/Y', $unix2YAgo),
386 'membership_type_id' => array('23', '15'),
389 $obj = new CRM_Member_Form_Membership();
390 $rc = $obj->formRule($params, $files, $obj);
392 // Should have found Expired membership status
393 $this->assertTrue($rc, 'In line ' . __LINE__
);
397 * Test CRM_Member_Form_Membership::formRule() with a join date
398 * of six months ago and a fixed membership type
400 public function testFormRuleFixedJoin6MonthsAgo() {
402 $unix6MAgo = $unixNow - (180 * 24 * 60 * 60);
404 'join_date' => date('m/d/Y', $unix6MAgo),
407 'membership_type_id' => array('23', '7'),
410 $obj = new CRM_Member_Form_Membership();
411 $rc = $obj->formRule($params, $files, $obj);
413 // Should have found Current membership status
414 $this->assertTrue($rc);
418 * Test the submit function of the membership form.
420 public function testSubmit() {
421 $form = new CRM_Member_Form_Membership();
422 $this->createLoggedInUser();
424 'cid' => $this->_individualId
,
425 'join_date' => date('m/d/Y', time()),
428 'membership_type_id' => array('25'),
433 'total_amount' => '50.00',
434 'financial_type_id' => '2', //Member dues, see data.xml
435 'soft_credit_type_id' => '',
436 'soft_credit_contact_id' => '',
437 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
438 'receipt_text_signup' => 'Thank you text',
439 'payment_processor_id' => $this->_paymentProcessorID
,
440 'credit_card_number' => '4111111111111111',
442 'credit_card_exp_date' => array(
444 'Y' => '2019', // TODO: Future proof
446 'credit_card_type' => 'Visa',
447 'billing_first_name' => 'Test',
448 'billing_middlename' => 'Last',
449 'billing_street_address-5' => '10 Test St',
450 'billing_city-5' => 'Test',
451 'billing_state_province_id-5' => '1003',
452 'billing_postal_code-5' => '90210',
453 'billing_country_id-5' => '1228',
455 $form->submit($params);
456 // TODO: This will still fail right now.
457 //$this->callAPISuccessGetCount('Membership', array('contact_id' => $this->_individualId), 1);
461 // class CRM_Member_Form_MembershipTest