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_MembershipRenewalTest
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 * Membership type ID for annual fixed membership.
67 protected $membershipTypeAnnualFixedID;
70 * Parameters to create payment processor.
74 protected $_processorParams = array();
77 * ID of created membership.
81 protected $_membershipID;
84 * Payment instrument mapping.
88 protected $paymentInstruments = array();
91 * Test setup for every test.
93 * Connect to the database, truncate the tables that will be used
94 * and redirect stdin to a temporary file.
96 public function setUp() {
97 $this->_apiversion
= 3;
100 $this->_individualId
= $this->individualCreate();
101 $processor = $this->processorCreate();
102 $this->_paymentProcessorID
= $processor->id
;
104 $op = new PHPUnit_Extensions_Database_Operation_Insert();
105 $op->execute($this->_dbconn
,
106 $this->createFlatXMLDataSet(
107 dirname(__FILE__
) . '/dataset/data.xml'
110 $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array(
112 'name' => "AnnualFixed",
113 'member_of_contact_id' => 23,
114 'duration_unit' => "year",
115 'duration_interval' => 1,
116 'period_type' => "fixed",
117 'fixed_period_start_day' => "101",
118 'fixed_period_rollover_day' => "1231",
119 'relationship_type_id' => 20,
120 'financial_type_id' => 2,
122 $this->membershipTypeAnnualFixedID
= $membershipTypeAnnualFixed['id'];
123 $membership = $this->callAPISuccess('Membership', 'create', array(
124 'contact_id' => $this->_individualId
,
125 'membership_type_id' => $this->membershipTypeAnnualFixedID
,
127 $this->_membershipID
= $membership['id'];
129 $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
130 $this->paymentInstruments
= $instruments['values'];
134 * Clean up after each test.
136 public function tearDown() {
137 $this->quickCleanUpFinancialEntities();
140 'civicrm_relationship',
141 'civicrm_membership_type',
142 'civicrm_membership',
146 $this->callAPISuccess('contact', 'delete', array('id' => 17, 'skip_undelete' => TRUE));
147 $this->callAPISuccess('contact', 'delete', array('id' => 23, 'skip_undelete' => TRUE));
148 $this->callAPISuccess('relationship_type', 'delete', array('id' => 20));
152 * Test CRM_Member_Form_Membership::buildQuickForm()
154 //function testCRMMemberFormMembershipBuildQuickForm()
156 // throw new PHPUnit_Framework_IncompleteTestError( "not implemented" );
160 * Test the submit function of the membership form.
162 public function testSubmit() {
163 $form = $this->getForm();
164 $this->createLoggedInUser();
166 'cid' => $this->_individualId
,
167 'join_date' => date('m/d/Y', time()),
170 // This format reflects the 23 being the organisation & the 25 being the type.
171 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID
),
176 'total_amount' => '50.00',
177 'financial_type_id' => '2', //Member dues, see data.xml
178 'soft_credit_type_id' => '',
179 'soft_credit_contact_id' => '',
180 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
181 'receipt_text_signup' => 'Thank you text',
182 'payment_processor_id' => $this->_paymentProcessorID
,
183 'credit_card_number' => '4111111111111111',
185 'credit_card_exp_date' => array(
187 'Y' => '2024', // TODO: Future proof
189 'credit_card_type' => 'Visa',
190 'billing_first_name' => 'Test',
191 'billing_middlename' => 'Last',
192 'billing_street_address-5' => '10 Test St',
193 'billing_city-5' => 'Test',
194 'billing_state_province_id-5' => '1003',
195 'billing_postal_code-5' => '90210',
196 'billing_country_id-5' => '1228',
198 $form->_contactID
= $this->_individualId
;
200 $form->testSubmit($params);
201 $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId
));
202 $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId
), 0);
203 $contribution = $this->callAPISuccess('Contribution', 'get', array(
204 'contact_id' => $this->_individualId
,
208 $this->callAPISuccessGetCount('LineItem', array(
209 'entity_id' => $membership['id'],
210 'entity_table' => 'civicrm_membership',
211 'contribution_id' => $contribution['id'],
216 * Test the submit function of the membership form.
218 public function testSubmitRecur() {
219 $form = $this->getForm();
221 $this->callAPISuccess('MembershipType', 'create', array(
222 'id' => $this->membershipTypeAnnualFixedID
,
223 'duration_unit' => 'month',
224 'duration_interval' => 1,
225 'auto_renew' => TRUE,
228 $this->createLoggedInUser();
230 'cid' => $this->_individualId
,
232 'join_date' => date('m/d/Y', time()),
236 // This format reflects the 23 being the organisation & the 25 being the type.
237 'membership_type_id' => array(23, $this->membershipTypeAnnualFixedID
),
243 'total_amount' => '77.00',
244 'financial_type_id' => '2', //Member dues, see data.xml
245 'soft_credit_type_id' => 11,
246 'soft_credit_contact_id' => '',
247 'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
248 'receipt_text' => 'Thank you text',
249 'payment_processor_id' => $this->_paymentProcessorID
,
250 'credit_card_number' => '4111111111111111',
252 'credit_card_exp_date' => array(
254 'Y' => '2019', // TODO: Future proof
256 'credit_card_type' => 'Visa',
257 'billing_first_name' => 'Test',
258 'billing_middlename' => 'Last',
259 'billing_street_address-5' => '10 Test St',
260 'billing_city-5' => 'Test',
261 'billing_state_province_id-5' => '1003',
262 'billing_postal_code-5' => '90210',
263 'billing_country_id-5' => '1228',
265 $form->_mode
= 'test';
266 $form->_contactID
= $this->_individualId
;
268 $form->testSubmit($params);
269 $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId
));
270 //$this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
271 $contribution = $this->callAPISuccess('Contribution', 'get', array(
272 'contact_id' => $this->_individualId
,
276 $this->callAPISuccessGetCount('LineItem', array(
277 'entity_id' => $membership['id'],
278 'entity_table' => 'civicrm_membership',
279 'contribution_id' => $contribution['id'],
285 * Get a membership form object.
287 * We need to instantiate the form to run preprocess, which means we have to trick it about the request method.
289 * @return \CRM_Member_Form_MembershipRenewal
291 protected function getForm() {
292 $form = new CRM_Member_Form_MembershipRenewal();
293 $_SERVER['REQUEST_METHOD'] = 'GET';
294 $form->controller
= new CRM_Core_Controller();
296 $form->_mode
= 'test';
297 $form->_id
= $this->_membershipID
;