Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
6a488035 TO |
27 | require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php'; |
28 | class WebTest_Import_MatchExternalIdTest extends ImportCiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | /* | |
35 | * Test participant import for Individuals matching on external identifier. | |
36 | */ | |
37 | function testContributionImport() { | |
6a488035 TO |
38 | $this->webtestLogin(); |
39 | ||
40 | // Get sample import data. | |
41 | list($headers, $rows, $fieldMapper) = $this->_contributionIndividualCSVData(); | |
42 | ||
43 | // Create and import csv from provided data and check imported data. | |
44 | $this->importCSVComponent('Contribution', $headers, $rows, 'Individual', 'Insert new contributions', $fieldMapper); | |
45 | } | |
46 | ||
47 | /* | |
48 | * Test membership import for Individuals matching on external identifier. | |
49 | */ | |
50 | function testMemberImportIndividual() { | |
6a488035 TO |
51 | $this->webtestLogin(); |
52 | ||
53 | // Get membership import data for Individuals. | |
54 | list($headers, $rows, $fieldMapper) = $this->_memberIndividualCSVData(); | |
55 | ||
56 | // Import participants and check imported data. | |
57 | $this->importCSVComponent('Membership', $headers, $rows, 'Individual', 'Skip', $fieldMapper); | |
58 | } | |
59 | ||
60 | /* | |
61 | * Test participant import for Individuals matching on external identifier. | |
62 | */ | |
63 | function testParticipantImportIndividual() { | |
6a488035 TO |
64 | // Log in using webtestLogin() method |
65 | $this->webtestLogin(); | |
66 | ||
67 | // Get sample import data. | |
68 | list($headers, $rows, $fieldMapper) = $this->_participantIndividualCSVData(); | |
69 | ||
70 | // Create and import csv from provided data and check imported data. | |
71 | $this->importCSVComponent('Event', $headers, $rows, 'Individual', 'Skip', $fieldMapper); | |
72 | } | |
73 | ||
74 | /* | |
75 | * Helper function to provide data for contribution import for Individual. | |
76 | */ | |
77 | function _contributionIndividualCSVData() { | |
78 | $firstName1 = substr(sha1(rand()), 0, 7); | |
79 | $lastName1 = substr(sha1(rand()), 0, 7); | |
80 | $externalId1 = substr(sha1(rand()), 0, 4); | |
81 | ||
82 | $this->_addContact($firstName1, $lastName1, $externalId1); | |
83 | ||
84 | $firstName2 = substr(sha1(rand()), 0, 7); | |
85 | $lastName2 = substr(sha1(rand()), 0, 7); | |
86 | $externalId2 = substr(sha1(rand()), 0, 4); | |
87 | ||
88 | $this->_addContact($firstName2, $lastName2, $externalId2); | |
89 | ||
90 | $headers = array( | |
91 | 'external_identifier' => 'External Identifier', | |
92 | 'fee_amount' => 'Fee Amount', | |
93 | 'financial_type' => 'Financial Type', | |
94 | 'contribution_status_id' => 'Contribution Status', | |
95 | 'total_amount' => 'Total Amount', | |
96 | ); | |
97 | ||
98 | $rows = array( | |
99 | array( | |
100 | 'external_identifier' => $externalId1, | |
101 | 'fee_amount' => '200', | |
102 | 'financial_type' => 'Donation', | |
103 | 'contribution_status_id' => 'Completed', | |
104 | 'total_amount' => '200', | |
105 | ), | |
106 | array( | |
107 | 'external_identifier' => $externalId2, | |
108 | 'fee_amount' => '400', | |
109 | 'financial_type' => 'Donation', | |
110 | 'contribution_status_id' => 'Completed', | |
111 | 'total_amount' => '400', | |
112 | ), | |
113 | ); | |
114 | $fieldMapper = array( | |
115 | 'mapper[0][0]' => 'external_identifier', | |
116 | 'mapper[2][0]' => 'financial_type', | |
117 | 'mapper[4][0]' => 'total_amount', | |
118 | ); | |
119 | return array($headers, $rows, $fieldMapper); | |
120 | } | |
121 | ||
122 | /* | |
123 | * Helper function to provide data for membership import for Individual. | |
124 | */ | |
125 | function _memberIndividualCSVData() { | |
126 | $memTypeParams = $this->webtestAddMembershipType(); | |
127 | ||
128 | $firstName1 = substr(sha1(rand()), 0, 7); | |
129 | $lastName1 = substr(sha1(rand()), 0, 7); | |
130 | $externalId1 = substr(sha1(rand()), 0, 4); | |
131 | ||
132 | $this->_addContact($firstName1, $lastName1, $externalId1); | |
133 | $startDate1 = date('Y-m-d'); | |
134 | $year = date('Y') - 1; | |
135 | ||
136 | $firstName2 = substr(sha1(rand()), 0, 7); | |
137 | $lastName2 = substr(sha1(rand()), 0, 7); | |
138 | $externalId2 = substr(sha1(rand()), 0, 4); | |
139 | ||
140 | $this->_addContact($firstName2, $lastName2, $externalId2); | |
141 | $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year)); | |
142 | ||
143 | $headers = array( | |
144 | 'external_identifier' => 'External Identifier', | |
145 | 'membership_type_id' => 'Membership Type', | |
146 | 'membership_start_date' => 'Membership Start Date', | |
147 | ); | |
148 | $rows = array( | |
149 | array( | |
150 | 'external_identifier' => $externalId1, | |
151 | 'membership_type_id' => $memTypeParams['membership_type'], | |
152 | 'membership_start_date' => $startDate1, | |
153 | ), | |
154 | array( | |
155 | 'external_identifier' => $externalId2, | |
156 | 'membership_type_id' => $memTypeParams['membership_type'], | |
157 | 'membership_start_date' => $startDate2, | |
158 | ), | |
159 | ); | |
160 | ||
161 | $fieldMapper = array( | |
162 | 'mapper[0][0]' => 'external_identifier', | |
163 | 'mapper[1][0]' => 'membership_type_id', | |
164 | 'mapper[2][0]' => 'membership_start_date', | |
165 | ); | |
166 | return array($headers, $rows, $fieldMapper); | |
167 | } | |
168 | ||
169 | /* | |
170 | * Helper function to provide data for participant import for Individual. | |
171 | */ | |
172 | function _participantIndividualCSVData() { | |
173 | $eventInfo = $this->_addNewEvent(); | |
174 | ||
175 | $firstName1 = substr(sha1(rand()), 0, 7); | |
176 | $lastName1 = substr(sha1(rand()), 0, 7); | |
177 | $externalId1 = substr(sha1(rand()), 0, 4); | |
178 | ||
179 | $this->_addContact($firstName1, $lastName1, $externalId1); | |
180 | ||
181 | $firstName2 = substr(sha1(rand()), 0, 7); | |
182 | $lastName2 = substr(sha1(rand()), 0, 7); | |
183 | $externalId2 = substr(sha1(rand()), 0, 4); | |
184 | ||
185 | $this->_addContact($firstName2, $lastName2, $externalId2); | |
186 | ||
187 | $headers = array( | |
188 | 'external_identifier' => 'External Identifier', | |
189 | 'event_id' => 'Event Id', | |
190 | 'fee_level' => 'Fee Level', | |
191 | 'role' => 'Participant Role', | |
192 | 'status' => 'Participant Status', | |
193 | 'register_date' => 'Register date', | |
194 | ); | |
195 | ||
196 | $rows = array( | |
197 | array( | |
198 | 'external_identifier' => $externalId1, | |
199 | 'event_id' => $eventInfo['event_id'], | |
200 | 'fee_level' => 'Member', | |
201 | 'role' => 1, | |
202 | 'status' => 1, | |
203 | 'register_date' => '2011-03-30', | |
204 | ), | |
205 | array( | |
206 | 'external_identifier' => $externalId2, | |
207 | 'event_id' => $eventInfo['event_id'], | |
208 | 'fee_level' => 'Non-Member', | |
209 | 'role' => 1, | |
210 | 'status' => 1, | |
211 | 'register_date' => '2011-03-30', | |
212 | ), | |
213 | ); | |
214 | ||
215 | $fieldMapper = array( | |
216 | 'mapper[0][0]' => 'external_identifier', | |
217 | 'mapper[1][0]' => 'event_id', | |
218 | 'mapper[2][0]' => 'participant_fee_level', | |
219 | 'mapper[4][0]' => 'participant_status_id', | |
220 | ); | |
221 | ||
222 | return array($headers, $rows, $fieldMapper); | |
223 | } | |
224 | ||
225 | /* | |
226 | * Helper function to add new contact | |
227 | * | |
228 | * @params $firstName, $lastName, $externalId | |
229 | * | |
230 | * @return int external id | |
231 | */ | |
232 | function _addContact($firstName, $lastName, $externalId) { | |
e3ae42f3 | 233 | $this->openCiviPage('contact/add', 'reset=1&ct=Individual'); |
6a488035 TO |
234 | |
235 | //fill in first name | |
236 | $this->type("first_name", $firstName); | |
237 | ||
238 | //fill in last name | |
239 | $this->type("last_name", $lastName); | |
240 | ||
241 | //fill in external identifier | |
242 | $this->type("external_identifier", $externalId); | |
243 | ||
244 | // Clicking save. | |
245 | $this->click("_qf_Contact_upload_view"); | |
246 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c5f7368 | 247 | $this->waitForText('crm-notification-container', "Contact Saved"); |
6a488035 TO |
248 | |
249 | return $externalId; | |
250 | } | |
251 | ||
252 | /* | |
253 | * Helper function to add new event | |
254 | * | |
255 | * @params array $params parameters to create an event | |
256 | * | |
257 | * @return array $params event details of newly created event | |
258 | */ | |
259 | function _addNewEvent($params = array( | |
260 | )) { | |
261 | if (empty($params)) { | |
262 | ||
263 | // We need a payment processor | |
264 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); | |
265 | $this->webtestAddPaymentProcessor($processorName); | |
266 | ||
267 | // create an event | |
268 | $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7); | |
269 | $params = array( | |
270 | 'title' => $eventTitle, | |
271 | 'template_id' => 6, | |
272 | 'event_type_id' => 4, | |
273 | 'payment_processor' => $processorName, | |
274 | 'fee_level' => array( | |
275 | 'Member' => "250.00", | |
276 | 'Non-Member' => "325.00", | |
277 | ), | |
278 | ); | |
279 | } | |
280 | ||
e3ae42f3 | 281 | $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom'); |
6a488035 | 282 | |
6a488035 TO |
283 | $this->select("event_type_id", "value={$params['event_type_id']}"); |
284 | ||
285 | // Attendee role s/b selected now. | |
286 | $this->select("default_role_id", "value=1"); | |
287 | ||
288 | // Enter Event Title, Summary and Description | |
289 | $this->type("title", $params['title']); | |
290 | $this->type("summary", "This is a great conference. Sign up now!"); | |
291 | $this->fillRichTextField("description", "Here is a description for this event.", 'CKEditor'); | |
292 | ||
293 | // Choose Start and End dates. | |
294 | // Using helper webtestFillDate function. | |
295 | $this->webtestFillDateTime("start_date", "+1 week"); | |
296 | $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours "); | |
297 | ||
298 | $this->type("max_participants", "50"); | |
299 | $this->click("is_map"); | |
300 | $this->click("_qf_EventInfo_upload-bottom"); | |
301 | ||
302 | // Wait for Location tab form to load | |
303 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
304 | ||
305 | // Go to Fees tab | |
306 | $this->click("link=Fees"); | |
307 | $this->waitForElementPresent("_qf_Fee_upload-bottom"); | |
308 | $this->click("CIVICRM_QFID_1_is_monetary"); | |
309 | $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']"); | |
310 | $this->select( "financial_type_id", "value=4" ); | |
311 | ||
312 | $counter = 1; | |
313 | foreach ($params['fee_level'] as $label => $amount) { | |
314 | $this->type("label_{$counter}", $label); | |
315 | $this->type("value_{$counter}", $amount); | |
316 | $counter++; | |
317 | } | |
318 | ||
319 | $this->click("_qf_Fee_upload-bottom"); | |
320 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
321 | ||
322 | // Go to Online Registration tab | |
323 | $this->click("link=Online Registration"); | |
324 | $this->waitForElementPresent("_qf_Registration_upload-bottom"); | |
325 | ||
326 | $this->check("is_online_registration"); | |
327 | $this->assertChecked("is_online_registration"); | |
328 | ||
329 | $this->fillRichTextField("intro_text", "Fill in all the fields below and click Continue."); | |
330 | ||
331 | // enable confirmation email | |
332 | $this->click("CIVICRM_QFID_1_is_email_confirm"); | |
333 | $this->type("confirm_from_name", "Jane Doe"); | |
334 | $this->type("confirm_from_email", "jane.doe@example.org"); | |
335 | ||
336 | $this->click("_qf_Registration_upload-bottom"); | |
337 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c5f7368 | 338 | $this->waitForText('crm-notification-container', "Saved"); |
6a488035 TO |
339 | |
340 | // verify event input on info page | |
341 | // start at Manage Events listing | |
e3ae42f3 | 342 | $this->openCiviPage('event/manage', 'reset=1'); |
6a488035 TO |
343 | $this->type("xpath=//div[@class='crm-block crm-form-block crm-event-searchevent-form-block']/table/tbody/tr/td/input",$params['title']); |
344 | $this->click("_qf_SearchEvent_refresh"); | |
345 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
a471a3b6 | 346 | $this->clickLink("link=" . $params['title']); |
6a488035 | 347 | |
a471a3b6 | 348 | $params['event_id'] = $this->urlArg('id'); |
6a488035 TO |
349 | |
350 | return $params; | |
351 | } | |
352 | } | |
353 |