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.
39 protected $_membershipTypeName = NULL;
42 * Membership type id used in test function.
45 protected $_membershipTypeID = NULL;
48 * Contact id used in test function.
51 protected $_contactID = NULL;
53 * Contact id used in test function.
56 protected $_contactID2 = NULL;
59 * Contact id used in test function.
62 protected $_contactID3 = NULL;
65 * Contact id used in test function.
68 protected $_contactID4 = NULL;
70 public function setUp() {
74 'contact_type_a' => 'Individual',
75 'contact_type_b' => 'Organization',
76 'name_a_b' => 'Test Employee of',
77 'name_b_a' => 'Test Employer of',
79 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
80 $this->_orgContactID
= $this->organizationCreate();
81 $this->_financialTypeId
= 1;
82 $this->_membershipTypeName
= 'Mickey Mouse Club Member';
84 'name' => $this->_membershipTypeName
,
85 'description' => NULL,
86 'minimum_fee' => 1500,
87 'duration_unit' => 'year',
88 'member_of_contact_id' => $this->_orgContactID
,
89 'period_type' => 'fixed',
90 'duration_interval' => 1,
91 'financial_type_id' => $this->_financialTypeId
,
92 'relationship_type_id' => $this->_relationshipTypeId
,
93 'visibility' => 'Public',
95 'fixed_period_start_day' => 101,
96 'fixed_period_rollover_day' => 1231,
97 'domain_id' => CRM_Core_Config
::domainID(),
99 $membershipType = $this->callAPISuccess('membership_type', 'create', $params);
100 $this->_membershipTypeID
= $membershipType['id'];
102 $this->_orgContactID2
= $this->organizationCreate();
105 'duration_unit' => 'year',
106 'duration_interval' => 1,
107 'period_type' => 'rolling',
108 'member_of_contact_id' => $this->_orgContactID2
,
110 'financial_type_id' => 1,
113 'visibility' => 'Public',
115 $membershipType2 = $this->callAPISuccess('membership_type', 'create', $params);
116 $this->_membershipTypeID2
= $membershipType2['id'];
118 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
119 $this->_contactID
= $this->individualCreate();
120 $contact2Params = array(
121 'first_name' => 'Anthonita',
122 'middle_name' => 'J.',
123 'last_name' => 'Anderson',
126 'email' => 'b@c.com',
127 'contact_type' => 'Individual',
129 $this->_contactID2
= $this->individualCreate($contact2Params);
130 $this->_contactID3
= $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
131 $this->_contactID4
= $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
133 $session = CRM_Core_Session
::singleton();
134 $session->set('dateTypes', 1);
135 $this->_sethtmlGlobals();
140 * Tears down the fixture, for example, closes a network connection.
141 * This method is called after a test is executed.
143 public function tearDown() {
144 $this->quickCleanUpFinancialEntities();
145 $this->relationshipTypeDelete($this->_relationshipTypeId
);
146 if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID
))) {
147 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
149 if ($this->callAPISuccessGetCount('MembershipStatus', array('id' => $this->_membershipStatusID
))) {
150 $this->membershipStatusDelete($this->_membershipStatusID
);
152 $this->contactDelete($this->_contactID
);
153 $this->contactDelete($this->_contactID2
);
154 $this->contactDelete($this->_orgContactID
);
160 * @param string $thousandSeparator
162 * @dataProvider getThousandSeparators
164 public function testProcessMembership($thousandSeparator) {
165 $this->setCurrencySeparators($thousandSeparator);
167 $form = new CRM_Batch_Form_Entry();
168 $profileID = $this->callAPISuccessGetValue('UFGroup', ['return' => 'id', 'name' => 'membership_batch_entry']);
169 $form->_fields
= CRM_Core_BAO_UFGroup
::getFields($profileID, FALSE, CRM_Core_Action
::VIEW
);
171 $params = $this->getMembershipData();
172 $this->assertTrue($form->testProcessMembership($params));
173 $result = $this->callAPISuccess('membership', 'get', array());
174 $this->assertEquals(3, $result['count']);
175 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
176 $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
177 $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
179 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
180 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][1]['end_date']);
181 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
182 $this->assertEquals('2013-12-01', $result['values'][3]['end_date']);
184 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
185 $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
186 $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
187 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
188 $result = $this->callAPISuccess('contribution', 'get', array('return' => array('total_amount', 'trxn_id')));
189 $this->assertEquals(3, $result['count']);
190 foreach ($result['values'] as $key => $contribution) {
191 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
192 'contribution_id' => $contribution['id'],
193 'return' => 'line_total',
195 )), $contribution['total_amount']);
196 $this->assertEquals(1500, $contribution['total_amount']);
197 $this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']);
202 * Test Contribution Import.
204 * @param $thousandSeparator
206 * @dataProvider getThousandSeparators
208 public function testProcessContribution($thousandSeparator) {
209 $this->setCurrencySeparators($thousandSeparator);
210 $this->offsetDefaultPriceSet();
211 $form = new CRM_Batch_Form_Entry();
212 $params = $this->getContributionData();
213 $this->assertTrue($form->testProcessContribution($params));
214 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
215 $this->assertEquals(2, $result['count']);
216 foreach ($result['values'] as $contribution) {
217 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
218 'contribution_id' => $contribution['id'],
219 'return' => 'line_total',
221 )), $contribution['total_amount']);
226 * CRM-18000 - Test start_date, end_date after renewal
228 public function testMembershipRenewalDates() {
229 $form = new CRM_Batch_Form_Entry();
230 foreach (array($this->_contactID
, $this->_contactID2
) as $contactID) {
231 $membershipParams = array(
232 'membership_type_id' => $this->_membershipTypeID2
,
233 'contact_id' => $contactID,
234 'start_date' => "01/01/2015",
235 'join_date' => "01/01/2010",
236 'end_date' => "12/31/2015",
238 $this->contactMembershipCreate($membershipParams);
241 $params = $this->getMembershipData();
242 //ensure membership renewal
243 $params['member_option'] = array(
247 $params['field'][1]['membership_type'] = array(0 => $this->_orgContactID2
, 1 => $this->_membershipTypeID2
);
248 $params['field'][1]['receive_date'] = date('Y-m-d');
250 // explicitly specify start and end dates
251 $params['field'][2]['membership_type'] = array(0 => $this->_orgContactID2
, 1 => $this->_membershipTypeID2
);
252 $params['field'][2]['membership_start_date'] = "2016-04-01";
253 $params['field'][2]['membership_end_date'] = "2017-03-31";
254 $params['field'][2]['receive_date'] = "2016-04-01";
256 $this->assertTrue($form->testProcessMembership($params));
257 $result = $this->callAPISuccess('membership', 'get', array());
259 // renewal dates should be from current if start_date and end_date is passed as NULL
260 $this->assertEquals(date('Y-m-d'), $result['values'][1]['start_date']);
261 $endDate = date("Y-m-d", strtotime(date("Y-m-d") . " +1 year -1 day"));
262 $this->assertEquals($endDate, $result['values'][1]['end_date']);
264 // verify if the modified dates asserts with the dates passed above
265 $this->assertEquals('2016-04-01', $result['values'][2]['start_date']);
266 $this->assertEquals('2017-03-31', $result['values'][2]['end_date']);
270 * Data provider for test process membership.
273 public function getMembershipData() {
277 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
278 'primary_contact_id' => array(
279 1 => $this->_contactID
,
280 2 => $this->_contactID2
,
281 3 => $this->_contactID3
,
285 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
286 'join_date' => '2013-07-22',
287 'membership_start_date' => NULL,
288 'membership_end_date' => NULL,
289 'membership_source' => NULL,
290 'financial_type' => 2,
291 'total_amount' => $this->formatMoneyInput(1500),
292 'receive_date' => '2013-07-24',
293 'receive_date_time' => NULL,
294 'payment_instrument' => 1,
295 'trxn_id' => 'TX101',
296 'check_number' => NULL,
297 'contribution_status_id' => 1,
300 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
301 'join_date' => '2013-07-03',
302 'membership_start_date' => '2013-02-03',
303 'membership_end_date' => NULL,
304 'membership_source' => NULL,
305 'financial_type' => 2,
306 'total_amount' => $this->formatMoneyInput(1500),
307 'receive_date' => '2013-07-17',
308 'receive_date_time' => NULL,
309 'payment_instrument' => NULL,
310 'trxn_id' => 'TX102',
311 'check_number' => NULL,
312 'contribution_status_id' => 1,
314 // no join date, coded end date
316 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
318 'membership_start_date' => NULL,
319 'membership_end_date' => '2013-12-01',
320 'membership_source' => NULL,
321 'financial_type' => 2,
322 'total_amount' => $this->formatMoneyInput(1500),
323 'receive_date' => '2013-07-17',
324 'receive_date_time' => NULL,
325 'payment_instrument' => NULL,
326 'trxn_id' => 'TX103',
327 'check_number' => NULL,
328 'contribution_status_id' => 1,
332 'actualBatchTotal' => 0,
338 * @param $thousandSeparator
342 public function getContributionData($thousandSeparator = '.') {
345 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
346 'primary_contact_id' => array(
347 1 => $this->_contactID
,
348 2 => $this->_contactID2
,
349 3 => $this->_contactID3
,
353 'financial_type' => 1,
354 'total_amount' => $this->formatMoneyInput(1500.15),
355 'receive_date' => '2013-07-24',
356 'receive_date_time' => NULL,
357 'payment_instrument' => 1,
358 'check_number' => NULL,
359 'contribution_status_id' => 1,
362 'financial_type' => 1,
363 'total_amount' => $this->formatMoneyInput(1500.15),
364 'receive_date' => '2013-07-24',
365 'receive_date_time' => NULL,
366 'payment_instrument' => 1,
367 'check_number' => NULL,
368 'contribution_status_id' => 1,
371 'actualBatchTotal' => $this->formatMoneyInput(3000.30),