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/>.
27 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Test CRM/Member/BAO Membership Log add , delete functions
35 class CRM_Batch_Form_EntryTest
extends CiviUnitTestCase
{
38 * Membership type name used in test function
41 protected $_membershipTypeName = NULL;
44 * Membership type id used in test function
47 protected $_membershipTypeID = NULL;
50 * Contact id used in test function
53 protected $_contactID = NULL;
55 * Contact id used in test function
58 protected $_contactID2 = NULL;
61 * Contact id used in test function
64 protected $_contactID3 = NULL;
67 * Contact id used in test function
70 protected $_contactID4 = NULL;
76 'contact_type_a' => 'Individual',
77 'contact_type_b' => 'Organization',
78 'name_a_b' => 'Test Employee of',
79 'name_b_a' => 'Test Employer of',
81 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
82 $this->_orgContactID
= $this->organizationCreate();
83 $this->_financialTypeId
= 1;
84 $this->_membershipTypeName
= 'Mickey Mouse Club Member';
86 'name' => $this->_membershipTypeName
,
87 'description' => NULL,
89 'duration_unit' => 'year',
90 'member_of_contact_id' => $this->_orgContactID
,
91 'period_type' => 'fixed',
92 'duration_interval' => 1,
93 'financial_type_id' => $this->_financialTypeId
,
94 'relationship_type_id' => $this->_relationshipTypeId
,
95 'visibility' => 'Public',
97 'fixed_period_start_day' => 101,
98 'fixed_period_rollover_day' => 1231,
99 'domain_id' => CRM_Core_Config
::domainID(),
101 $membershipType = $this->callAPISuccess('membership_type', 'create', $params);
102 $this->_membershipTypeID
= $membershipType['id'];
104 $this->_membershipStatusID
= $this->membershipStatusCreate('test status');
105 $this->_contactID
= $this->individualCreate();
106 $contact2Params = array(
107 'first_name' => 'Anthonita',
108 'middle_name' => 'J.',
109 'last_name' => 'Anderson',
112 'email' => 'b@c.com',
113 'contact_type' => 'Individual',
115 $this->_contactID2
= $this->individualCreate($contact2Params);
116 $this->_contactID3
= $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
117 $this->_contactID4
= $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
119 $session = CRM_Core_Session
::singleton();
120 $session->set('dateTypes', 1);
121 $this->_sethtmlGlobals();
126 * Tears down the fixture, for example, closes a network connection.
127 * This method is called after a test is executed.
132 $this->quickCleanUpFinancialEntities();
133 $this->relationshipTypeDelete($this->_relationshipTypeId
);
134 if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID
))) {
135 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
137 $this->membershipStatusDelete($this->_membershipStatusID
);
138 $this->contactDelete($this->_contactID
);
139 $this->contactDelete($this->_contactID2
);
140 $this->contactDelete($this->_orgContactID
);
146 function testProcessMembership() {
147 $form = new CRM_Batch_Form_Entry();
148 $params = $this->getMembershipData();
149 $this->assertTrue($form->testProcessMembership($params));
150 $result = $this->callAPISuccess('membership', 'get', array());
151 $this->assertEquals(3, $result['count']);
152 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
153 $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
154 $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
156 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
157 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][1]['end_date']);
158 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
159 $this->assertEquals('2013-12-01', $result['values'][3]['end_date']);
161 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
162 $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
163 $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
164 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
165 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
166 $this->assertEquals(3, $result['count']);
167 foreach($result['values'] as $contribution) {
168 $this-> assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
169 'contribution_id' => $contribution['id'],
170 'return' => 'line_total',
172 )), $contribution['total_amount']);
177 * Test Contribution Import
179 function testProcessContribution() {
180 $this->offsetDefaultPriceSet();
181 $form = new CRM_Batch_Form_Entry();
182 $params = $this->getContributionData();
183 $this->assertTrue($form->testProcessContribution($params));
184 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
185 $this->assertEquals(2, $result['count']);
186 foreach($result['values'] as $contribution) {
187 $this-> assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
188 'contribution_id' => $contribution['id'],
189 'return' => 'line_total',
191 )), $contribution['total_amount']);
195 * Data provider for test process membership
198 function getMembershipData() {
202 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
203 'primary_contact_id' => Array (
204 1 => $this->_contactID
,
205 2 => $this->_contactID2
,
206 3 => $this->_contactID3
,
210 'membership_type' => Array (0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
211 'join_date' => '07/22/2013',
212 'membership_start_date' => NULL,
213 'membership_end_date' => NULL,
214 'membership_source' => NULL,
215 'financial_type' => 2,
217 'receive_date' => '07/24/2013',
218 'receive_date_time' => NULL,
219 'payment_instrument' => 1,
220 'check_number' => NULL,
221 'contribution_status_id' => 1,
224 'membership_type' => Array (0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
225 'join_date' => '07/03/2013',
226 'membership_start_date' => '02/03/2013',
227 'membership_end_date' => NULL,
228 'membership_source' => NULL,
229 'financial_type' => 2,
231 'receive_date' => '07/17/2013',
232 'receive_date_time' => NULL,
233 'payment_instrument' => NULL,
234 'check_number' => NULL,
235 'contribution_status_id' => 1,
237 // no join date, coded end date
239 'membership_type' => Array (0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
241 'membership_start_date' => NULL,
242 'membership_end_date' => '2013-12-01',
243 'membership_source' => NULL,
244 'financial_type' => 2,
246 'receive_date' => '07/17/2013',
247 'receive_date_time' => NULL,
248 'payment_instrument' => NULL,
249 'check_number' => NULL,
250 'contribution_status_id' => 1,
254 'actualBatchTotal' => 0,
262 function getContributionData() {
265 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
266 'primary_contact_id' => Array (
267 1 => $this->_contactID
,
268 2 => $this->_contactID2
,
269 3 => $this->_contactID3
,
273 'financial_type' => 1,
274 'total_amount' => 15,
275 'receive_date' => '07/24/2013',
276 'receive_date_time' => NULL,
277 'payment_instrument' => 1,
278 'check_number' => NULL,
279 'contribution_status_id' => 1,
282 'financial_type' => 1,
283 'total_amount' => 15,
284 'receive_date' => '07/24/2013',
285 'receive_date_time' => NULL,
286 'payment_instrument' => 1,
287 'check_number' => NULL,
288 'contribution_status_id' => 1,
291 'actualBatchTotal' => 30,