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