4 * File for the EntryTest class
10 * This file is part of CiviCRM
12 * CiviCRM is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * CiviCRM is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
22 * You should have received a copy of the GNU Affero General Public
23 * License along with this program. If not, see
24 * <http://www.gnu.org/licenses/>.
28 * Test CRM/Member/BAO Membership Log add , delete functions
33 class CRM_Batch_Form_EntryTest
extends CiviUnitTestCase
{
36 * Membership type name used in test function.
40 protected $_membershipTypeName = NULL;
43 * Membership type id used in test function.
47 protected $_membershipTypeID = NULL;
50 * Contact id used in test function.
54 protected $_contactID = NULL;
56 * Contact id used in test function.
60 protected $_contactID2 = NULL;
63 * Contact id used in test function.
67 protected $_contactID3 = NULL;
70 * Contact id used in test function.
74 protected $_contactID4 = NULL;
76 public function setUp() {
80 'contact_type_a' => 'Individual',
81 'contact_type_b' => 'Organization',
82 'name_a_b' => 'Test Employee of',
83 'name_b_a' => 'Test Employer of',
85 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
86 $this->_orgContactID
= $this->organizationCreate();
87 $this->_financialTypeId
= 1;
88 $this->_membershipTypeName
= 'Mickey Mouse Club Member';
90 'name' => $this->_membershipTypeName
,
91 'description' => NULL,
92 'minimum_fee' => 1500,
93 'duration_unit' => 'year',
94 'member_of_contact_id' => $this->_orgContactID
,
95 'period_type' => 'fixed',
96 'duration_interval' => 1,
97 'financial_type_id' => $this->_financialTypeId
,
98 'relationship_type_id' => $this->_relationshipTypeId
,
99 'visibility' => 'Public',
101 'fixed_period_start_day' => 101,
102 'fixed_period_rollover_day' => 1231,
103 'domain_id' => CRM_Core_Config
::domainID(),
105 $membershipType = $this->callAPISuccess('membership_type', 'create', $params);
106 $this->_membershipTypeID
= $membershipType['id'];
108 $this->_orgContactID2
= $this->organizationCreate();
111 'duration_unit' => 'year',
112 'duration_interval' => 1,
113 'period_type' => 'rolling',
114 'member_of_contact_id' => $this->_orgContactID2
,
116 'financial_type_id' => 1,
119 'visibility' => 'Public',
121 $membershipType2 = $this->callAPISuccess('membership_type', 'create', $params);
122 $this->_membershipTypeID2
= $membershipType2['id'];
124 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
125 $this->_contactID
= $this->individualCreate();
126 $contact2Params = array(
127 'first_name' => 'Anthonita',
128 'middle_name' => 'J.',
129 'last_name' => 'Anderson',
132 'email' => 'b@c.com',
133 'contact_type' => 'Individual',
135 $this->_contactID2
= $this->individualCreate($contact2Params);
136 $this->_contactID3
= $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
137 $this->_contactID4
= $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
139 $session = CRM_Core_Session
::singleton();
140 $session->set('dateTypes', 1);
141 $this->_sethtmlGlobals();
146 * Tears down the fixture, for example, closes a network connection.
147 * This method is called after a test is executed.
149 public function tearDown() {
150 $this->quickCleanUpFinancialEntities();
151 $this->relationshipTypeDelete($this->_relationshipTypeId
);
152 if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID
))) {
153 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
155 if ($this->callAPISuccessGetCount('MembershipStatus', array('id' => $this->_membershipStatusID
))) {
156 $this->membershipStatusDelete($this->_membershipStatusID
);
158 $this->contactDelete($this->_contactID
);
159 $this->contactDelete($this->_contactID2
);
160 $this->contactDelete($this->_orgContactID
);
166 * @param string $thousandSeparator
168 * @dataProvider getThousandSeparators
170 public function testProcessMembership($thousandSeparator) {
171 $this->setCurrencySeparators($thousandSeparator);
173 $form = new CRM_Batch_Form_Entry();
174 $profileID = $this->callAPISuccessGetValue('UFGroup', ['return' => 'id', 'name' => 'membership_batch_entry']);
175 $form->_fields
= CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::VIEW
);
177 $params = $this->getMembershipData();
178 $this->assertTrue($form->testProcessMembership($params));
179 $result = $this->callAPISuccess('membership', 'get', array());
180 $this->assertEquals(3, $result['count']);
181 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
182 $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
183 $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
185 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
186 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][1]['end_date']);
187 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
188 $this->assertEquals('2013-12-01', $result['values'][3]['end_date']);
190 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
191 $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
192 $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
193 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
194 $result = $this->callAPISuccess('contribution', 'get', array('return' => array('total_amount', 'trxn_id')));
195 $this->assertEquals(3, $result['count']);
196 foreach ($result['values'] as $key => $contribution) {
197 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
198 'contribution_id' => $contribution['id'],
199 'return' => 'line_total',
201 )), $contribution['total_amount']);
202 $this->assertEquals(1500, $contribution['total_amount']);
203 $this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']);
208 * Test Contribution Import.
210 * @param $thousandSeparator
212 * @dataProvider getThousandSeparators
214 public function testProcessContribution($thousandSeparator) {
215 $this->setCurrencySeparators($thousandSeparator);
216 $this->offsetDefaultPriceSet();
217 $form = new CRM_Batch_Form_Entry();
218 $params = $this->getContributionData();
219 $this->assertTrue($form->testProcessContribution($params));
220 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
221 $this->assertEquals(2, $result['count']);
222 foreach ($result['values'] as $contribution) {
223 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
224 'contribution_id' => $contribution['id'],
225 'return' => 'line_total',
227 )), $contribution['total_amount']);
232 * CRM-18000 - Test start_date, end_date after renewal
234 public function testMembershipRenewalDates() {
235 $form = new CRM_Batch_Form_Entry();
236 foreach (array($this->_contactID
, $this->_contactID2
) as $contactID) {
237 $membershipParams = array(
238 'membership_type_id' => $this->_membershipTypeID2
,
239 'contact_id' => $contactID,
240 'start_date' => "01/01/2015",
241 'join_date' => "01/01/2010",
242 'end_date' => "12/31/2015",
244 $this->contactMembershipCreate($membershipParams);
247 $params = $this->getMembershipData();
248 //ensure membership renewal
249 $params['member_option'] = array(
253 $params['field'][1]['membership_type'] = array(0 => $this->_orgContactID2
, 1 => $this->_membershipTypeID2
);
254 $params['field'][1]['receive_date'] = date('Y-m-d');
256 // explicitly specify start and end dates
257 $params['field'][2]['membership_type'] = array(0 => $this->_orgContactID2
, 1 => $this->_membershipTypeID2
);
258 $params['field'][2]['membership_start_date'] = "2016-04-01";
259 $params['field'][2]['membership_end_date'] = "2017-03-31";
260 $params['field'][2]['receive_date'] = "2016-04-01";
262 $this->assertTrue($form->testProcessMembership($params));
263 $result = $this->callAPISuccess('membership', 'get', array());
265 // renewal dates should be from current if start_date and end_date is passed as NULL
266 $this->assertEquals(date('Y-m-d'), $result['values'][1]['start_date']);
267 $endDate = date("Y-m-d", strtotime(date("Y-m-d") . " +1 year -1 day"));
268 $this->assertEquals($endDate, $result['values'][1]['end_date']);
270 // verify if the modified dates asserts with the dates passed above
271 $this->assertEquals('2016-04-01', $result['values'][2]['start_date']);
272 $this->assertEquals('2017-03-31', $result['values'][2]['end_date']);
276 * Data provider for test process membership.
279 public function getMembershipData() {
283 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
284 'primary_contact_id' => array(
285 1 => $this->_contactID
,
286 2 => $this->_contactID2
,
287 3 => $this->_contactID3
,
291 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
292 'join_date' => '2013-07-22',
293 'membership_start_date' => NULL,
294 'membership_end_date' => NULL,
295 'membership_source' => NULL,
296 'financial_type' => 2,
297 'total_amount' => $this->formatMoneyInput(1500),
298 'receive_date' => '2013-07-24',
299 'receive_date_time' => NULL,
300 'payment_instrument' => 1,
301 'trxn_id' => 'TX101',
302 'check_number' => NULL,
303 'contribution_status_id' => 1,
306 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
307 'join_date' => '2013-07-03',
308 'membership_start_date' => '2013-02-03',
309 'membership_end_date' => NULL,
310 'membership_source' => NULL,
311 'financial_type' => 2,
312 'total_amount' => $this->formatMoneyInput(1500),
313 'receive_date' => '2013-07-17',
314 'receive_date_time' => NULL,
315 'payment_instrument' => NULL,
316 'trxn_id' => 'TX102',
317 'check_number' => NULL,
318 'contribution_status_id' => 1,
320 // no join date, coded end date
322 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
324 'membership_start_date' => NULL,
325 'membership_end_date' => '2013-12-01',
326 'membership_source' => NULL,
327 'financial_type' => 2,
328 'total_amount' => $this->formatMoneyInput(1500),
329 'receive_date' => '2013-07-17',
330 'receive_date_time' => NULL,
331 'payment_instrument' => NULL,
332 'trxn_id' => 'TX103',
333 'check_number' => NULL,
334 'contribution_status_id' => 1,
338 'actualBatchTotal' => 0,
344 * @param $thousandSeparator
348 public function getContributionData($thousandSeparator = '.') {
351 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
352 'primary_contact_id' => array(
353 1 => $this->_contactID
,
354 2 => $this->_contactID2
,
355 3 => $this->_contactID3
,
359 'financial_type' => 1,
360 'total_amount' => $this->formatMoneyInput(1500.15),
361 'receive_date' => '2013-07-24',
362 'receive_date_time' => NULL,
363 'payment_instrument' => 1,
364 'check_number' => NULL,
365 'contribution_status_id' => 1,
368 'financial_type' => 1,
369 'total_amount' => $this->formatMoneyInput(1500.15),
370 'receive_date' => '2013-07-24',
371 'receive_date_time' => NULL,
372 'payment_instrument' => 1,
373 'check_number' => NULL,
374 'contribution_status_id' => 1,
377 'actualBatchTotal' => $this->formatMoneyInput(3000.30),