Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-28-11-04-58
[civicrm-core.git] / tests / phpunit / CRM / Batch / Form / EntryTest.php
1 <?php
2
3 /**
4 * File for the EntryTest class
5 *
6 * (PHP 5)
7 *
8 * @package CiviCRM
9 *
10 * This file is part of CiviCRM
11 *
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.
16 *
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.
21 *
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/>.
25 */
26
27 require_once 'CiviTest/CiviUnitTestCase.php';
28
29
30 /**
31 * Test CRM/Member/BAO Membership Log add , delete functions
32 *
33 * @package CiviCRM
34 */
35 class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
36
37 /**
38 * Membership type name used in test function
39 * @var String
40 */
41 protected $_membershipTypeName = NULL;
42
43 /**
44 * Membership type id used in test function
45 * @var String
46 */
47 protected $_membershipTypeID = NULL;
48
49 /**
50 * Contact id used in test function
51 * @var String
52 */
53 protected $_contactID = NULL;
54 /**
55 * Contact id used in test function
56 * @var String
57 */
58 protected $_contactID2 = NULL;
59
60 /**
61 * Contact id used in test function
62 * @var String
63 */
64 protected $_contactID3 = NULL;
65
66 /**
67 * Contact id used in test function
68 * @var String
69 */
70 protected $_contactID4 = NULL;
71
72 /**
73 * Describe test class
74 * @return array
75 */
76 function get_info() {
77 return array(
78 'name' => 'MembershipParserTest',
79 'description' => 'Test import parser function',
80 'group' => 'CiviCRM BAO Tests',
81 );
82 }
83
84 function setUp() {
85 parent::setUp();
86
87 $params = array(
88 'contact_type_a' => 'Individual',
89 'contact_type_b' => 'Organization',
90 'name_a_b' => 'Test Employee of',
91 'name_b_a' => 'Test Employer of',
92 );
93 $this->_relationshipTypeId = $this->relationshipTypeCreate($params);
94 $this->_orgContactID = $this->organizationCreate();
95 $this->_financialTypeId = 1;
96 $this->_membershipTypeName = 'Mickey Mouse Club Member';
97 $params = array(
98 'name' => $this->_membershipTypeName,
99 'description' => NULL,
100 'minimum_fee' => 10,
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',
108 'is_active' => 1,
109 'fixed_period_start_day' => 101,
110 'fixed_period_rollover_day' => 1231
111 );
112 $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
113 $this->_membershipTypeID = $membershipType->id;
114
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',
121 'prefix_id' => 3,
122 'suffix_id' => 3,
123 'email' => 'b@c.com',
124 'contact_type' => 'Individual',
125 );
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'));
129
130 $session = CRM_Core_Session::singleton();
131 $session->set('dateTypes', 1);
132
133 }
134
135 /**
136 * Tears down the fixture, for example, closes a network connection.
137 * This method is called after a test is executed.
138 *
139 */
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);
149 }
150
151 /**
152 * Test Import
153 */
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']);
160
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']);
164
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']);
169
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']);
174
175 }
176
177 /*
178 * data provider for test process membership
179 */
180 function getMembershipData() {
181
182 /*
183 Array (
184
185 );
186 */
187 return array(
188 'batch_id' => 4,
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,
194 ),
195 'field' => array(
196 1 => array(
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,
203 'total_amount' => 1,
204 'receive_date' => '07/24/2013',
205 'receive_date_time' => NULL,
206 'payment_instrument' => 1,
207 'check_number' => NULL,
208 'contribution_status_id' => 1,
209 ),
210 2 => array(
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,
217 'total_amount' => 1,
218 'receive_date' => '07/17/2013',
219 'receive_date_time' => NULL,
220 'payment_instrument' => NULL,
221 'check_number' => NULL,
222 'contribution_status_id' => 1,
223 ),
224 // no join date, coded end date
225 3 => array(
226 'membership_type' => Array (0 => 1, 1 => 1 ),
227 'join_date' => NULL,
228 'membership_start_date' => NULL,
229 'membership_end_date' => '2013-12-01',
230 'membership_source' => NULL,
231 'financial_type' => 2,
232 'total_amount' => 1,
233 'receive_date' => '07/17/2013',
234 'receive_date_time' => NULL,
235 'payment_instrument' => NULL,
236 'check_number' => NULL,
237 'contribution_status_id' => 1,
238 ),
239
240 ),
241 'actualBatchTotal' => 0,
242
243 );
244 }
245 }
246