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;
78 'name' => 'MembershipParserTest',
79 'description' => 'Test import parser function',
80 'group' => 'CiviCRM BAO Tests',
88 'contact_type_a' => 'Individual',
89 'contact_type_b' => 'Organization',
90 'name_a_b' => 'Test Employee of',
91 'name_b_a' => 'Test Employer of',
93 $this->_relationshipTypeId
= $this->relationshipTypeCreate($params);
94 $this->_orgContactID
= $this->organizationCreate();
95 $this->_financialTypeId
= 1;
96 $this->_membershipTypeName
= 'Mickey Mouse Club Member';
98 'name' => $this->_membershipTypeName
,
99 'description' => NULL,
101 'duration_unit' => 'year',
102 'member_of_contact_id' => $this->_orgContactID
,
103 'period_type' => 'fixed',
104 'duration_interval' => 1,
105 'financial_type_id' => $this->_financialTypeId
,
106 'relationship_type_id' => $this->_relationshipTypeId
,
107 'visibility' => 'Public',
109 'fixed_period_start_day' => 101,
110 'fixed_period_rollover_day' => 1231
112 $membershipType = CRM_Member_BAO_MembershipType
::add($params, $ids);
113 $this->_membershipTypeID
= $membershipType->id
;
115 $this->_mebershipStatusID
= $this->membershipStatusCreate('test status');
116 $this->_contactID
= $this->individualCreate();
117 $contact2Params = array(
118 'first_name' => 'Anthonita',
119 'middle_name' => 'J.',
120 'last_name' => 'Anderson',
123 'email' => 'b@c.com',
124 'contact_type' => 'Individual',
126 $this->_contactID2
= $this->individualCreate($contact2Params);
127 $this->_contactID3
= $this->individualCreate(array('first_name' => 'bobby', 'email' => 'c@d.com'));
128 $this->_contactID4
= $this->individualCreate(array('first_name' => 'bobbynita', 'email' => 'c@de.com'));
130 $session = CRM_Core_Session
::singleton();
131 $session->set('dateTypes', 1);
136 * Tears down the fixture, for example, closes a network connection.
137 * This method is called after a test is executed.
140 function tearDown() {
141 $tablesToTruncate = array('civicrm_membership', 'civicrm_membership_log', 'civicrm_contribution', 'civicrm_membership_payment');
142 $this->quickCleanup($tablesToTruncate);
143 $this->relationshipTypeDelete($this->_relationshipTypeId
);
144 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
145 $this->membershipStatusDelete($this->_mebershipStatusID
);
146 $this->contactDelete($this->_contactID
);
147 $this->contactDelete($this->_contactID2
);
148 $this->contactDelete($this->_orgContactID
);
154 function testProcessMembership() {
155 $form = new CRM_Batch_Form_Entry();
156 $params = $this->getMembershipData();
157 $this->assertTrue($form->testProcessMembership($params));
158 $result = $this->callAPISuccess('membership', 'get', array());
159 $this->assertEquals(3, $result['count']);
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('first day of January 2013')), $result['values'][1]['start_date']);
163 $this->assertEquals('2013-02-03', $result['values'][2]['start_date']);
165 //check start dates #1 should default to 1 Jan this year, #2 should be as entered
166 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][1]['end_date']);
167 $this->assertEquals(date('Y-m-d', strtotime('last day of December 2013')), $result['values'][2]['end_date']);
168 $this->assertEquals('2013-12-01', $result['values'][3]['end_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('07/22/2013')), $result['values'][1]['join_date']);
172 $this->assertEquals(date('Y-m-d', strtotime('07/03/2013')), $result['values'][2]['join_date']);
173 $this->assertEquals(date('Y-m-d', strtotime('now')), $result['values'][3]['join_date']);
178 * data provider for test process membership
180 function getMembershipData() {
189 'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
190 'primary_contact_id' => Array (
191 1 => $this->_contactID
,
192 2 => $this->_contactID2
,
193 3 => $this->_contactID3
,
197 'membership_type' => Array (0 => 1, 1 => 1),// (I was unable to determine what these both mean but both are refered to in code
198 'join_date' => '07/22/2013',
199 'membership_start_date' => NULL,
200 'membership_end_date' => NULL,
201 'membership_source' => NULL,
202 'financial_type' => 2,
204 'receive_date' => '07/24/2013',
205 'receive_date_time' => NULL,
206 'payment_instrument' => 1,
207 'check_number' => NULL,
208 'contribution_status_id' => 1,
211 'membership_type' => Array (0 => 1, 1 => 1 ),
212 'join_date' => '07/03/2013',
213 'membership_start_date' => '02/03/2013',
214 'membership_end_date' => NULL,
215 'membership_source' => NULL,
216 'financial_type' => 2,
218 'receive_date' => '07/17/2013',
219 'receive_date_time' => NULL,
220 'payment_instrument' => NULL,
221 'check_number' => NULL,
222 'contribution_status_id' => 1,
224 // no join date, coded end date
226 'membership_type' => Array (0 => 1, 1 => 1 ),
228 'membership_start_date' => NULL,
229 'membership_end_date' => '2013-12-01',
230 'membership_source' => NULL,
231 'financial_type' => 2,
233 'receive_date' => '07/17/2013',
234 'receive_date_time' => NULL,
235 'payment_instrument' => NULL,
236 'check_number' => NULL,
237 'contribution_status_id' => 1,
241 'actualBatchTotal' => 0,