a2f78a3bc94bcecc2cab26684f977a64f337b4b9
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->_membershipStatusID
= $this->membershipStatusCreate('test status');
103 $this->_contactID
= $this->individualCreate();
104 $contact2Params = array(
105 'first_name' => 'Anthonita',
106 'middle_name' => 'J.',
107 'last_name' => 'Anderson',
110 'email' => 'b@c.com',
111 'contact_type' => 'Individual',
113 $this->_contactID2
= $this->individualCreate($contact2Params);
114 $this->_contactID3
= $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
115 $this->_contactID4
= $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
117 $session = CRM_Core_Session
::singleton();
118 $session->set('dateTypes', 1);
119 $this->_sethtmlGlobals();
124 * Tears down the fixture, for example, closes a network connection.
125 * This method is called after a test is executed.
127 public function tearDown() {
128 $this->quickCleanUpFinancialEntities();
129 $this->relationshipTypeDelete($this->_relationshipTypeId
);
130 if ($this->callAPISuccessGetCount('membership', array('id' => $this->_membershipTypeID
))) {
131 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
133 $this->membershipStatusDelete($this->_membershipStatusID
);
134 $this->contactDelete($this->_contactID
);
135 $this->contactDelete($this->_contactID2
);
136 $this->contactDelete($this->_orgContactID
);
142 public function testProcessMembership() {
143 $form = new CRM_Batch_Form_Entry();
144 $params = $this->getMembershipData();
145 $this->assertTrue($form->testProcessMembership($params));
146 $result = $this->callAPISuccess('membership', 'get', array());
147 $this->assertEquals(3, $result['count']);
148 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
149 $this->assertEquals(date('Y-m-d', strtotime('first day of January 2013')), $result['values'][1]['start_date']);
150 $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
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('last day of December 2013')), $result['values'][1]['end_date']);
154 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
155 $this->assertEquals('2013-12-01', $result['values'][3]['end_date']);
157 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
158 $this->assertEquals(date('Y-m-d', strtotime('07/22/2013')), $result['values'][1]['join_date']);
159 $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
160 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
161 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
162 $this->assertEquals(3, $result['count']);
163 foreach ($result['values'] as $contribution) {
164 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
165 'contribution_id' => $contribution['id'],
166 'return' => 'line_total',
168 )), $contribution['total_amount']);
173 * Test Contribution Import.
175 public function testProcessContribution() {
176 $this->offsetDefaultPriceSet();
177 $form = new CRM_Batch_Form_Entry();
178 $params = $this->getContributionData();
179 $this->assertTrue($form->testProcessContribution($params));
180 $result = $this->callAPISuccess('contribution', 'get', array('return' => 'total_amount'));
181 $this->assertEquals(2, $result['count']);
182 foreach ($result['values'] as $contribution) {
183 $this->assertEquals($this->callAPISuccess('line_item', 'getvalue', array(
184 'contribution_id' => $contribution['id'],
185 'return' => 'line_total',
187 )), $contribution['total_amount']);
192 * Data provider for test process membership.
195 public function getMembershipData() {
199 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
200 'primary_contact_id' => array(
201 1 => $this->_contactID
,
202 2 => $this->_contactID2
,
203 3 => $this->_contactID3
,
207 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
208 'join_date' => '07/22/2013',
209 'membership_start_date' => NULL,
210 'membership_end_date' => NULL,
211 'membership_source' => NULL,
212 'financial_type' => 2,
214 'receive_date' => '07/24/2013',
215 'receive_date_time' => NULL,
216 'payment_instrument' => 1,
217 'check_number' => NULL,
218 'contribution_status_id' => 1,
221 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
222 'join_date' => '07/03/2013',
223 'membership_start_date' => '02/03/2013',
224 'membership_end_date' => NULL,
225 'membership_source' => NULL,
226 'financial_type' => 2,
228 'receive_date' => '07/17/2013',
229 'receive_date_time' => NULL,
230 'payment_instrument' => NULL,
231 'check_number' => NULL,
232 'contribution_status_id' => 1,
234 // no join date, coded end date
236 'membership_type' => array(0 => $this->_orgContactID
, 1 => $this->_membershipTypeID
),
238 'membership_start_date' => NULL,
239 'membership_end_date' => '2013-12-01',
240 'membership_source' => NULL,
241 'financial_type' => 2,
243 'receive_date' => '07/17/2013',
244 'receive_date_time' => NULL,
245 'payment_instrument' => NULL,
246 'check_number' => NULL,
247 'contribution_status_id' => 1,
251 'actualBatchTotal' => 0,
259 public function getContributionData() {
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 'financial_type' => 1,
271 'total_amount' => 15,
272 'receive_date' => '07/24/2013',
273 'receive_date_time' => NULL,
274 'payment_instrument' => 1,
275 'check_number' => NULL,
276 'contribution_status_id' => 1,
279 'financial_type' => 1,
280 'total_amount' => 15,
281 'receive_date' => '07/24/2013',
282 'receive_date_time' => NULL,
283 'payment_instrument' => 1,
284 'check_number' => NULL,
285 'contribution_status_id' => 1,
288 'actualBatchTotal' => 30,