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,
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 public function testProcessMembership() {
161 $form = new CRM_Batch_Form_Entry();
162 $params = $this->getMembershipData();
163 $this->assertTrue($form->testProcessMembership($params));
164 $result = $this->callAPISuccess('membership', 'get', array());
165 $this->assertEquals(3, $result['count']);
166 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
167 $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
168 $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
170 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
171 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][1]['end_date']);
172 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
173 $this->assertEquals('2013-12-01', $result['values'][3]['end_date']);
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('07/22/2013')), $result['values'][1]['join_date']);
177 $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
178 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
179 $result = $this->callAPISuccess('contribution', 'get', array('return' => array('total_amount', 'trxn_id')));
180 $this->assertEquals(3, $result['count']);
181 foreach ($result['values'] as $key => $contribution) {
182 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
183 'contribution_id' => $contribution['id'],
184 'return' => 'line_total',
186 )), $contribution['total_amount']);
187 $this->assertEquals($params['field'][$key]['trxn_id'], $contribution['trxn_id']);
192 * Test Contribution Import.
194 public function testProcessContribution() {
195 $this->offsetDefaultPriceSet();
196 $form = new CRM_Batch_Form_Entry();
197 $params = $this->getContributionData();
198 $this->assertTrue($form->testProcessContribution($params));
199 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
200 $this->assertEquals(2, $result['count']);
201 foreach ($result['values'] as $contribution) {
202 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
203 'contribution_id' => $contribution['id'],
204 'return' => 'line_total',
206 )), $contribution['total_amount']);
211 * CRM-18000 - Test start_date, end_date after renewal
213 public function testMembershipRenewalDates() {
214 $form = new CRM_Batch_Form_Entry();
215 foreach (array($this->_contactID
, $this->_contactID2
) as $contactID) {
216 $membershipParams = array(
217 'membership_type_id' => $this->_membershipTypeID2
,
218 'contact_id' => $contactID,
219 'start_date' => "01/01/2015",
220 'join_date' => "01/01/2010",
221 'end_date' => "12/31/2015",
223 $this->contactMembershipCreate($membershipParams);
226 $params = $this->getMembershipData();
227 //ensure membership renewal
228 $params['member_option'] = array(
232 $params['field'][1]['membership_type'] = array(0 => $this->_orgContactID2
, 1 => $this->_membershipTypeID2
);
233 $params['field'][1]['receive_date'] = date('Y-m-d');
235 // explicitly specify start and end dates
236 $params['field'][2]['membership_type'] = array(0 => $this->_orgContactID2
, 1 => $this->_membershipTypeID2
);
237 $params['field'][2]['membership_start_date'] = "2016-04-01";
238 $params['field'][2]['membership_end_date'] = "2017-03-31";
239 $params['field'][2]['receive_date'] = "2016-04-01";
241 $this->assertTrue($form->testProcessMembership($params));
242 $result = $this->callAPISuccess('membership', 'get', array());
244 // renewal dates should be from current if start_date and end_date is passed as NULL
245 $this->assertEquals(date('Y-m-d'), $result['values'][1]['start_date']);
246 $endDate = date("Y-m-d", strtotime(date("Y-m-d") . " +1 year -1 day"));
247 $this->assertEquals($endDate, $result['values'][1]['end_date']);
249 // verify if the modified dates asserts with the dates passed above
250 $this->assertEquals('2016-04-01', $result['values'][2]['start_date']);
251 $this->assertEquals('2017-03-31', $result['values'][2]['end_date']);
255 * Data provider for test process membership.
258 public function getMembershipData() {
262 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
263 'primary_contact_id' => array(
264 1 => $this->_contactID
,
265 2 => $this->_contactID2
,
266 3 => $this->_contactID3
,
270 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
271 'join_date' => '2013-07-22',
272 'membership_start_date' => NULL,
273 'membership_end_date' => NULL,
274 'membership_source' => NULL,
275 'financial_type' => 2,
277 'receive_date' => '2013-07-24',
278 'receive_date_time' => NULL,
279 'payment_instrument' => 1,
280 'trxn_id' => 'TX101',
281 'check_number' => NULL,
282 'contribution_status_id' => 1,
285 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
286 'join_date' => '2013-07-03',
287 'membership_start_date' => '2013-02-03',
288 'membership_end_date' => NULL,
289 'membership_source' => NULL,
290 'financial_type' => 2,
292 'receive_date' => '2013-07-17',
293 'receive_date_time' => NULL,
294 'payment_instrument' => NULL,
295 'trxn_id' => 'TX102',
296 'check_number' => NULL,
297 'contribution_status_id' => 1,
299 // no join date, coded end date
301 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
303 'membership_start_date' => NULL,
304 'membership_end_date' => '2013-12-01',
305 'membership_source' => NULL,
306 'financial_type' => 2,
308 'receive_date' => '2013-07-17',
309 'receive_date_time' => NULL,
310 'payment_instrument' => NULL,
311 'trxn_id' => 'TX103',
312 'check_number' => NULL,
313 'contribution_status_id' => 1,
317 'actualBatchTotal' => 0,
325 public function getContributionData() {
328 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
329 'primary_contact_id' => array(
330 1 => $this->_contactID
,
331 2 => $this->_contactID2
,
332 3 => $this->_contactID3
,
336 'financial_type' => 1,
337 'total_amount' => 15,
338 'receive_date' => '2013-07-24',
339 'receive_date_time' => NULL,
340 'payment_instrument' => 1,
341 'check_number' => NULL,
342 'contribution_status_id' => 1,
345 'financial_type' => 1,
346 'total_amount' => 15,
347 'receive_date' => '2013-07-24',
348 'receive_date_time' => NULL,
349 'payment_instrument' => 1,
350 'check_number' => NULL,
351 'contribution_status_id' => 1,
354 'actualBatchTotal' => 30,