Merge pull request #4942 from civicrm/batch-5
[civicrm-core.git] / tests / phpunit / WebTest / Event / MultiprofileEventTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Event_MultiprofileEventTest
31 */
32 class WebTest_Event_MultiprofileEventTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testCreateEventRegisterPage() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 $customGrp1 = "Custom Data1_" . substr(sha1(rand()), 0, 7);
43 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
44 $lastName = 'An' . substr(sha1(rand()), 0, 7);
45 $participantfname = 'Dany' . substr(sha1(rand()), 0, 4);
46 $participantlname = 'Dan' . substr(sha1(rand()), 0, 4);
47 $email1 = $firstName . "@test.com";
48 $email2 = $participantfname . "@test.com";
49
50 // Use default payment processor
51 $processorName = 'Test Processor';
52 $this->webtestAddPaymentProcessor($processorName);
53
54 //add email to name and address profile
55 $cfId = $this->_addEmailField();
56
57 // create custom group1
58 $this->openCiviPage("admin/custom/group", "reset=1");
59 $this->click("newCustomDataGroup");
60 $this->waitForPageToLoad($this->getTimeoutMsec());
61 $this->type("title", $customGrp1);
62 $this->select("extends[0]", "value=Contact");
63 $this->click("_qf_Group_next-bottom");
64 $this->waitForPageToLoad($this->getTimeoutMsec());
65
66 // get custom group id
67 $customGrpId1 = $this->urlArg('gid');
68
69 $customId = $this->_testGetCustomFieldId($customGrpId1);
70
71 $profileId = $this->_testGetProfileId($customId);
72
73 $this->openCiviPage("event/add", "reset=1&action=add");
74
75 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
76 $eventDescription = "Here is a description for this conference.";
77 $this->_testAddEventInfo($eventTitle, $eventDescription);
78
79 $streetAddress = "100 Main Street";
80 $this->_testAddLocation($streetAddress);
81
82 $this->_testAddFees(FALSE, FALSE, $processorName);
83
84 $eventPageId = $this->_testAddMultipleProfile($profileId);
85
86 $this->_testEventRegistration($eventPageId, $customId, $firstName, $lastName,
87 $participantfname, $participantlname, $email1, $email2
88 );
89 $this->waitForPageToLoad($this->getTimeoutMsec());
90
91 // Find Main Participant
92 $this->openCiviPage("event/search", "reset=1");
93 $this->type("sort_name", $firstName);
94 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
95 $this->clickLink("xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ParticipantView_cancel-top", FALSE);
96
97 $name = $firstName . " " . $lastName;
98 $status = 'Registered';
99
100 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[1]/td[2]/a", preg_quote($name));
101 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[3]/td[2]/a", preg_quote($eventTitle));
102 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[6]/td[2]", preg_quote($status));
103
104 // Find additional Participant
105 $this->openCiviPage("event/search", "reset=1");
106 $this->type("sort_name", $participantfname);
107 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
108 $this->clickLink("xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ParticipantView_cancel-top", FALSE);
109
110 $name = $participantfname . " " . $participantlname;
111 $status = 'Registered';
112
113 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[1]/td[2]/a", preg_quote($name));
114 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[3]/td[2]/a", preg_quote($eventTitle));
115 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[6]/td[2]", preg_quote($status));
116
117 // delete all custom data
118 if (isset($cfId)) {
119 $this->_removeEmailField($cfId);
120 }
121 foreach ($customId as $cid) {
122 $this->openCiviPage("admin/custom/group/field", "action=delete&reset=1&gid={$customGrpId1}&id=$cid");
123 $this->click("_qf_DeleteField_next-bottom");
124 $this->waitForPageToLoad($this->getTimeoutMsec());
125 }
126 $this->openCiviPage("admin/custom/group", "action=delete&reset=1&id=$customGrpId1");
127 $this->click("_qf_DeleteGroup_next-bottom");
128 $this->waitForPageToLoad($this->getTimeoutMsec());
129 }
130
131 public function testAnoumyousRegisterPage() {
132 // add the required Drupal permission
133 $permission = array('edit-1-access-all-custom-data');
134 $this->changePermissions($permission);
135
136 $customGrp1 = "Custom Data1_" . substr(sha1(rand()), 0, 7);
137 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
138 $lastName = 'An' . substr(sha1(rand()), 0, 7);
139 $participantfname = 'Dany' . substr(sha1(rand()), 0, 4);
140 $participantlname = 'Dan' . substr(sha1(rand()), 0, 4);
141 $email1 = $firstName . "@test.com";
142 $email2 = $participantfname . "@test.com";
143 $firstName2 = 'Man' . substr(sha1(rand()), 0, 4);
144 $lastName2 = 'Ann' . substr(sha1(rand()), 0, 7);
145 $participantfname2 = 'Adam' . substr(sha1(rand()), 0, 4);
146 $participantlname2 = 'Gil' . substr(sha1(rand()), 0, 4);
147 $email3 = $participantfname2 . "@test.com";
148 $email4 = $firstName2 . "@test.com";
149
150 // Use default payment processor
151 $processorName = 'Test Processor';
152 $this->webtestAddPaymentProcessor($processorName);
153
154 //add email field to name and address profile
155 $cfId = $this->_addEmailField();
156
157 // create custom group1
158 $this->openCiviPage("admin/custom/group", "reset=1");
159 $this->click("newCustomDataGroup");
160 $this->waitForPageToLoad($this->getTimeoutMsec());
161 $this->type("title", $customGrp1);
162 $this->select("extends[0]", "value=Contact");
163 $this->click("_qf_Group_next-bottom");
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165
166 // get custom group id
167 $customGrpId1 = $this->urlArg('gid');
168
169 $customId = $this->_testGetCustomFieldId($customGrpId1);
170
171 $profileId = $this->_testGetProfileId($customId);
172
173 $this->openCiviPage('event/add', "reset=1&action=add");
174
175 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
176 $eventDescription = "Here is a description for this conference.";
177 $this->_testAddEventInfo($eventTitle, $eventDescription);
178
179 $streetAddress = "100 Main Street";
180 $this->_testAddLocation($streetAddress);
181
182 $this->_testAddFees(FALSE, FALSE, $processorName);
183
184 $eventPageId = $this->_testAddMultipleProfile($profileId);
185
186 // logout
187 $this->webtestLogout();
188
189 $this->_testEventRegistration($eventPageId, $customId, $firstName, $lastName, $participantfname, $participantlname, $email1, $email2);
190 $this->waitForPageToLoad($this->getTimeoutMsec());
191 // Log in using webtestLogin() method
192 $this->webtestLogin();
193
194 // Find Main Participant
195 $this->openCiviPage("event/search", "reset=1");
196 $this->type("sort_name", $firstName);
197 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
198 $this->clickLink("xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ParticipantView_cancel-top", FALSE);
199
200 $name = $firstName . " " . $lastName;
201 $status = 'Registered';
202
203 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[1]/td[2]/a", preg_quote($name));
204 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[3]/td[2]/a", preg_quote($eventTitle));
205 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[6]/td[2]", preg_quote($status));
206
207 // Find additional Participant
208 $this->openCiviPage("event/search", "reset=1");
209 $this->type("sort_name", $participantfname);
210 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
211 $this->clickLink("xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ParticipantView_cancel-top", FALSE);
212
213 $name = $participantfname . " " . $participantlname;
214 $status = 'Registered';
215
216 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[1]/td[2]/a", preg_quote($name));
217 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[3]/td[2]/a", preg_quote($eventTitle));
218 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[6]/td[2]", preg_quote($status));
219
220 // Edit page and remove some profile
221 $this->_testRemoveProfile($eventPageId);
222
223 // logout
224 $this->webtestLogout();
225
226 $this->_testEventRegistrationAfterRemoving($eventPageId, $customId, $firstName2, $lastName2, $participantfname2, $participantlname2, $email3, $email4);
227 $this->waitForPageToLoad($this->getTimeoutMsec());
228
229 // Log in using webtestLogin() method
230 $this->webtestLogin();
231
232 // Find Main Participant
233 $this->openCiviPage('event/search', "reset=1");
234 $this->type("sort_name", $firstName2);
235 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
236 $this->clickLink("xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ParticipantView_cancel-top", FALSE);
237
238 $name = $firstName2 . " " . $lastName2;
239 $status = 'Registered';
240
241 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[1]/td[2]/a", preg_quote($name));
242 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[3]/td[2]/a", preg_quote($eventTitle));
243 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[6]/td[2]", preg_quote($status));
244
245 // Find additional Participant
246 $this->openCiviPage("event/search", "reset=1");
247 $this->type("sort_name", $participantfname2);
248 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
249 $this->clickLink("xpath=//div[@id='participantSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ParticipantView_cancel-top", FALSE);
250
251 $name = $participantfname2 . " " . $participantlname2;
252 $status = 'Registered';
253
254 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[1]/td[2]/a", preg_quote($name));
255 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[3]/td[2]/a", preg_quote($eventTitle));
256 $this->verifyText("xpath=//form[@id='ParticipantView']/div[2]/table/tbody/tr[6]/td[2]", preg_quote($status));
257
258 // delete all custom data
259 if (isset($cfId)) {
260 $this->_removeEmailField($cfId);
261 }
262 foreach ($customId as $cid) {
263 $this->openCiviPage("admin/custom/group/field", "action=delete&reset=1&gid={$customGrpId1}&id=$cid");
264 $this->click("_qf_DeleteField_next-bottom");
265 $this->waitForPageToLoad($this->getTimeoutMsec());
266 }
267 $this->openCiviPage("admin/custom/group", "action=delete&reset=1&id=$customGrpId1");
268 $this->click("_qf_DeleteGroup_next-bottom");
269 $this->waitForPageToLoad($this->getTimeoutMsec());
270 }
271
272 /**
273 * @param $customGrpId1
274 *
275 * @return array
276 */
277 public function _testGetCustomFieldId($customGrpId1) {
278 $customId = array();
279
280 // Create a custom data to add in profile
281
282 $field1 = "Fname" . substr(sha1(rand()), 0, 7);
283 $field2 = "Mname" . substr(sha1(rand()), 0, 7);
284 $field3 = "Lname" . substr(sha1(rand()), 0, 7);
285
286 // add custom fields for group 1
287 $this->openCiviPage("admin/custom/group/field/add", "reset=1&action=add&gid=$customGrpId1");
288 $this->type("label", $field1);
289 $this->check("is_searchable");
290 $this->click("_qf_Field_next_new-bottom");
291 $this->waitForPageToLoad($this->getTimeoutMsec());
292
293 $this->type("label", $field2);
294 $this->check("is_searchable");
295 $this->click("_qf_Field_next_new-bottom");
296 $this->waitForPageToLoad($this->getTimeoutMsec());
297
298 $this->type("label", $field3);
299 $this->check("is_searchable");
300 $this->click("_qf_Field_done-bottom");
301 $this->waitForPageToLoad($this->getTimeoutMsec());
302
303 // get id of custom fields
304 $this->openCiviPage("admin/custom/group/field", "reset=1&action=browse&gid=$customGrpId1");
305 $custom1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[1]/td[8]/span/a[text()='Edit Field']/@href"));
306 $custom1 = $custom1[1];
307 array_push($customId, $custom1);
308 $custom2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[2]/td[8]/span/a[text()='Edit Field']/@href"));
309 $custom2 = $custom2[1];
310 array_push($customId, $custom2);
311 $custom3 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[3]/td[8]/span/a[text()='Edit Field']/@href"));
312 $custom3 = $custom3[1];
313 array_push($customId, $custom3);
314
315 return $customId;
316 }
317
318 /**
319 * @param int $eventPageId
320 */
321 public function _testRemoveProfile($eventPageId) {
322 $this->openCiviPage("event/manage/settings", "reset=1&action=update&id=$eventPageId");
323
324 // Go to Online Contribution tab
325 $this->click("link=Online Registration");
326 $this->waitForElementPresent("_qf_Registration_upload-bottom");
327 $this->click("xpath=//*[@id='additional_custom_post_id_multiple_1']/parent::td/span[1]/a");
328 $this->click("xpath=//*[@id='additional_custom_post_id_multiple_2']/parent::td/span[1]/a");
329 $this->click("xpath=//*[@id='additional_custom_post_id_multiple_3']/parent::td/span[1]/a");
330 $this->click("xpath=//*[@id='additional_custom_post_id_multiple_4']/parent::td/span[1]/a");
331 $this->click("_qf_Registration_upload-bottom");
332 $this->waitForElementPresent("_qf_Registration_upload-bottom");
333 }
334
335 /**
336 * @param int $customId
337 *
338 * @return array
339 */
340 public function _testGetProfileId($customId) {
341 // create profiles
342 $profileId = array();
343 $profilefield = array(
344 'street_address' => 'street_address',
345 'supplemental_address_1' => 'supplemental_address_1',
346 'city' => 'city',
347 );
348 $location = 1;
349 $type = "Contact";
350 $profileId1 = $this->_testCreateProfile($profilefield, $location, $type);
351 array_push($profileId, $profileId1);
352
353 $profilefield = array(
354 'street_address' => 'street_address',
355 'city' => 'city',
356 'phone' => 'phone',
357 'postal_code' => 'postal_code',
358 );
359 $location = 0;
360 $type = "Contact";
361 $profileId2 = $this->_testCreateProfile($profilefield, $location, $type);
362 array_push($profileId, $profileId2);
363
364 $profilefield = array(
365 'nick_name' => 'nick_name',
366 'url' => 'url',
367 );
368 $location = 0;
369 $type = "Contact";
370 $profileId3 = $this->_testCreateProfile($profilefield, $location, $type);
371 array_push($profileId, $profileId3);
372
373 $profilefield = array(
374 'current_employer' => 'current_employer',
375 'job_title' => 'job_title',
376 );
377 $location = 0;
378 $type = "Individual";
379 $profileId4 = $this->_testCreateProfile($profilefield, $location, $type);
380 array_push($profileId, $profileId4);
381
382 $profilefield = array(
383 'middle_name' => 'middle_name',
384 'gender_id' => 'gender_id',
385 );
386 $location = 0;
387 $type = "Individual";
388 $profileId5 = $this->_testCreateProfile($profilefield, $location, $type);
389 array_push($profileId, $profileId5);
390
391 $profilefield = array(
392 'custom_' . $customId[0] => 'custom_' . $customId[0],
393 'custom_' . $customId[1] => 'custom_' . $customId[1],
394 'custom_' . $customId[2] => 'custom_' . $customId[2],
395 );
396 $location = 0;
397 $type = "Contact";
398 $profileId6 = $this->_testCreateProfile($profilefield, $location, $type);
399 array_push($profileId, $profileId6);
400
401 $profilefield = array(
402 'participant_role' => 'participant_role',
403 );
404 $location = 0;
405 $type = "Participant";
406 $profileId7 = $this->_testCreateProfile($profilefield, $location, $type);
407 array_push($profileId, $profileId7);
408
409 return $profileId;
410 }
411
412 /**
413 * Test profile creation.
414 *
415 *@param $profileField
416 * @param int $location
417 * @param $type
418 *
419 * @return null
420 */
421 public function _testCreateProfile($profileField, $location = 0, $type) {
422 $locationFields = array(
423 'supplemental_address_1',
424 'supplemental_address_2',
425 'city',
426 'country',
427 'email',
428 'state',
429 'street_address',
430 'postal_code',
431 );
432
433 // Add new profile.
434 $profileName = "Profile_" . substr(sha1(rand()), 0, 7);
435 $this->openCiviPage("admin/uf/group", "reset=1");
436 $this->click('newCiviCRMProfile-top');
437 $this->waitForElementPresent('_qf_Group_next-top');
438
439 //Name of profile
440 $this->type('title', $profileName);
441 $this->click('uf_group_type_Profile');
442 $this->click('_qf_Group_next-top');
443 $this->waitForPageToLoad($this->getTimeoutMsec());
444 $profileId = $this->urlArg('gid');
445
446 //Add field to profile_testCreateProfile
447 foreach ($profileField as $key => $value) {
448 $this->openCiviPage("admin/uf/group/field/add", "reset=1&action=add&gid=$profileId");
449 if (in_array($value, $locationFields)) {
450 $this->select("field_name[0]", "value={$type}");
451 $this->select("field_name[1]", "value={$value}");
452 $this->select("field_name[2]", "value={$location}");
453 $this->type("label", $value);
454 }
455 else {
456 $this->select("field_name[0]", "value={$type}");
457 $this->select("field_name[1]", "value={$value}");
458 $this->type("label", $value);
459 }
460 $this->click('_qf_Field_next-top');
461 $this->waitForPageToLoad($this->getTimeoutMsec());
462 }
463 return $profileId;
464 }
465
466 /**
467 * @param $eventTitle
468 * @param $eventDescription
469 */
470 public function _testAddEventInfo($eventTitle, $eventDescription) {
471 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
472
473 $this->select("event_type_id", "value=1");
474
475 // Attendee role s/b selected now.
476 $this->select("default_role_id", "value=1");
477
478 // Enter Event Title, Summary and Description
479 $this->type("title", $eventTitle);
480 $this->type("summary", "This is a great conference. Sign up now!");
481
482 // Type description in ckEditor (fieldname, text to type, editor)
483 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
484
485 // Choose Start and End dates.
486 // Using helper webtestFillDate function.
487 $this->webtestFillDateTime("start_date", "+1 week");
488 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
489
490 $this->type("max_participants", "50");
491 $this->click("is_map");
492 $this->click("_qf_EventInfo_upload-bottom");
493 }
494
495 /**
496 * @param $streetAddress
497 */
498 public function _testAddLocation($streetAddress) {
499 // Wait for Location tab form to load
500 $this->waitForPageToLoad($this->getTimeoutMsec());
501 $this->waitForElementPresent("_qf_Location_upload-bottom");
502
503 // Fill in address fields
504 //$streetAddress = "100 Main Street";
505 $this->type("address_1_street_address", $streetAddress);
506 $this->type("address_1_city", "San Francisco");
507 $this->waitForElementPresent('address_1_country_id');
508 $this->select("address_1_country_id", "value=1228");
509 $this->type("address_1_postal_code", "94117");
510 $this->select("address_1_state_province_id", "value=1004");
511 $this->type("email_1_email", "info@civicrm.org");
512
513 $this->click("_qf_Location_upload-bottom");
514
515 // Wait for "saved" status msg
516 $this->waitForElementPresent("_qf_Location_upload-bottom");
517 $this->waitForText('crm-notification-container', "'Event Location' information has been saved.");
518 }
519
520 /**
521 * @param bool $discount
522 * @param bool $priceSet
523 * @param string $processorName
524 */
525 public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro") {
526 // Go to Fees tab
527 $this->click("link=Fees");
528 $this->waitForElementPresent("_qf_Fee_upload-bottom");
529 $this->click("CIVICRM_QFID_1_is_monetary");
530
531 // select newly created processor
532 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
533 $this->assertElementContainsText('css=.crm-event-manage-fee-form-block-payment_processor', $processorName);
534 $this->check($xpath);
535 $this->select("financial_type_id", "label=Event Fee");
536 if ($priceSet) {
537 // get one - TBD
538 }
539 else {
540 $this->type("label_1", "Member");
541 $this->type("value_1", "250.00");
542 $this->type("label_2", "Non-member");
543 $this->type("value_2", "325.00");
544 //set default
545 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
546 }
547
548 if ($discount) {
549 // enter early bird discounts TBD
550 }
551
552 $this->click("_qf_Fee_upload-bottom");
553
554 // Wait for "saved" status msg
555 $this->waitForElementPresent("_qf_Fee_upload-bottom");
556 $this->waitForTextPresent("'Fees' information has been saved.");
557 }
558
559 /**
560 * @param int $profileId
561 *
562 * @return null
563 */
564 public function _testAddMultipleProfile($profileId) {
565 // Go to Online Contribution tab
566 $this->click("link=Online Registration");
567 $this->waitForElementPresent("_qf_Registration_upload-bottom");
568 $this->click("is_online_registration");
569 $this->check("is_multiple_registrations");
570 $this->select("xpath=//*[@id='custom_pre_id']/parent::td/div[1]/div/span/select", "value=1");
571 $this->select("xpath=//*[@id='custom_post_id']/parent::td/div[1]/div/span/select", "value=" . $profileId[3]);
572 $this->select("xpath=//*[@id='additional_custom_post_id']/parent::td/div[1]/div/span/select", "- same as for main contact -");
573
574 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
575 $this->click("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
576 $this->waitForElementPresent("custom_post_id_multiple_1");
577 $this->select("xpath=//*[@id='custom_post_id_multiple_1']/parent::td/div[1]/div/span/select", "value=" . $profileId[2]);
578
579 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
580 $this->click("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
581 $this->waitForElementPresent("custom_post_id_multiple_2");
582 $this->select("xpath=//*[@id='custom_post_id_multiple_2']/parent::td/div[1]/div/span/select", "value=" . $profileId[1]);
583
584 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
585 $this->click("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
586 $this->waitForElementPresent("custom_post_id_multiple_3");
587 $this->select("xpath=//*[@id='custom_post_id_multiple_3']/parent::td/div[1]/div/span/select", "value=" . $profileId[4]);
588
589 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
590 $this->click("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
591 $this->waitForElementPresent("custom_post_id_multiple_4");
592 $this->select("xpath=//*[@id='custom_post_id_multiple_4']/parent::td/div[1]/div/span/select", "value=" . $profileId[5]);
593
594 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
595 $this->click("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
596 $this->waitForElementPresent("custom_post_id_multiple_5");
597 $this->select("xpath=//*[@id='custom_post_id_multiple_5']/parent::td/div[1]/div/span/select", "value=" . $profileId[6]);
598
599 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
600 $this->click("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
601 $this->waitForElementPresent("additional_custom_post_id_multiple_1");
602 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_1']/parent::td/div[1]/div/span/select", "value=" . $profileId[5]);
603
604 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
605 $this->click("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
606 $this->waitForElementPresent("additional_custom_post_id_multiple_2");
607 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_2']/parent::td/div[1]/div/span/select", "value=" . $profileId[1]);
608
609 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
610 $this->click("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
611 $this->waitForElementPresent("additional_custom_post_id_multiple_3");
612 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_3']/parent::td/div[1]/div/span/select", "value=" . $profileId[2]);
613
614 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
615 $this->click("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
616 $this->waitForElementPresent("additional_custom_post_id_multiple_4");
617 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_4']/parent::td/div[1]/div/span/select", "value=" . $profileId[3]);
618
619 $this->click("CIVICRM_QFID_1_is_email_confirm");
620 $this->type("confirm_from_name", "TestEvent");
621 $this->type("confirm_from_email", "testevent@test.com");
622 $this->click("_qf_Registration_upload-bottom");
623
624 // Wait for "saved" status msg
625 $this->waitForElementPresent("_qf_Registration_upload-bottom");
626 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved.");
627
628 return $this->urlArg('id');
629 }
630
631 /**
632 * @param int $eventPageId
633 * @param int $customId
634 * @param string $firstName
635 * @param string $lastName
636 * @param string $participantfname
637 * @param string $participantlname
638 * @param $email1
639 * @param $email2
640 */
641 function _testEventRegistration(
642 $eventPageId, $customId, $firstName, $lastName,
643 $participantfname, $participantlname, $email1, $email2
644 ) {
645 $this->openCiviPage("event/register", "id={$eventPageId}&reset=1", "_qf_Register_upload-bottom");
646 $this->select("additional_participants", "value=1");
647
648 $this->type("email-Primary", $email1);
649 $this->type("first_name", $firstName);
650 $this->type("last_name", $lastName);
651 $this->type("street_address-1", "Test street addres");
652 $this->type("city-1", "Mumbai");
653 $this->type("postal_code-1", "2354");
654 $this->select("state_province-1", "value=1001");
655
656 // Credit Card Info
657 $this->select("credit_card_type", "value=Visa");
658 $this->type("credit_card_number", "4111111111111111");
659 $this->type("cvv2", "000");
660 $this->select("credit_card_exp_date[M]", "value=1");
661 $this->select("credit_card_exp_date[Y]", "value=2020");
662
663 //Billing Info
664 $this->type("billing_first_name", $firstName . 'billing');
665 $this->type("billing_last_name", $lastName . 'billing');
666 $this->type("billing_street_address-5", "0121 Mount Highschool.");
667 $this->type(" billing_city-5", "Shangai");
668 $this->select("billing_country_id-5", "value=1228");
669 $this->select("billing_state_province_id-5", "value=1004");
670 $this->type("billing_postal_code-5", "94129");
671
672 $this->type("current_employer", "ABCD");
673 $this->type("job_title", "Painter");
674 $this->waitForElementPresent('nick_name');
675 $this->type("nick_name", "Nick");
676 $this->type("url-1", "http://www.test.com");
677
678 $this->waitForElementPresent('street_address-Primary');
679 $this->type("street_address-Primary", "Primary street address");
680 $this->type("city-Primary", "primecity");
681 $this->type("phone-Primary-1", "98667764");
682 $this->type("postal_code-Primary", "6548");
683
684 $this->type("custom_" . $customId[0], "fname_custom1");
685 $this->type("custom_" . $customId[1], "mname_custom1");
686 $this->type("custom_" . $customId[2], "lname_custom1");
687
688 $this->type("middle_name", "xyz");
689 $this->click("name=gender_id value=2");
690 $this->waitForElementPresent('participant_role');
691 $this->select("participant_role", "value=2");
692
693 $this->click("_qf_Register_upload-bottom");
694 $this->waitForElementPresent("_qf_Participant_1_next-Array");
695
696 $this->type("email-Primary", $email2);
697 $this->type("first_name", $participantfname);
698 $this->type("last_name", $participantlname);
699 $this->type("street_address-1", "participant street addres");
700 $this->type("city-1", "pune");
701 $this->type("postal_code-1", "2354");
702 $this->select("state_province-1", "value=1001");
703
704 $this->type("current_employer", "ABCD");
705 $this->type("job_title", "Potato picker");
706
707 $this->type("custom_" . $customId[0], "participant_custom1");
708 $this->type("custom_" . $customId[1], "participant_custom1");
709 $this->type("custom_" . $customId[2], "participant_custom1");
710
711 $this->waitForElementPresent('street_address-Primary');
712 $this->type("street_address-Primary", "Primary street address");
713 $this->type("city-Primary", "primecity");
714 $this->type("phone-Primary-1", "98667764");
715 $this->type("postal_code-Primary", "6548");
716 $this->waitForElementPresent('nick_name');
717 $this->type("nick_name", "Nick1");
718 $this->type("url-1", "http://www.part.com");
719
720 $this->clickLink("_qf_Participant_1_next-Array", "_qf_Confirm_next-bottom");
721 $this->click("_qf_Confirm_next-bottom");
722 $this->waitForPageToLoad($this->getTimeoutMsec());
723 }
724
725 /**
726 * @param int $eventPageId
727 * @param int $customId
728 * @param string $firstName2
729 * @param string $lastName2
730 * @param string $participantfname2
731 * @param $participantlname2
732 * @param $email3
733 * @param $email4
734 */
735 public function _testEventRegistrationAfterRemoving($eventPageId, $customId, $firstName2, $lastName2, $participantfname2, $participantlname2, $email3, $email4) {
736 $this->openCiviPage("event/register", "id={$eventPageId}&reset=1", "_qf_Register_upload-bottom");
737 $this->select("additional_participants", "value=1");
738
739 $this->type("email-Primary", $email4);
740 $this->type("first_name", $firstName2);
741 $this->type("last_name", $lastName2);
742 $this->type("street_address-1", "Test street addres");
743 $this->type("city-1", "Mumbai");
744 $this->type("postal_code-1", "2354");
745 $this->select("state_province-1", "value=1001");
746
747 // Credit Card Info
748 $this->select("credit_card_type", "value=Visa");
749 $this->type("credit_card_number", "4111111111111111");
750 $this->type("cvv2", "000");
751 $this->select("credit_card_exp_date[M]", "value=1");
752 $this->select("credit_card_exp_date[Y]", "value=2020");
753
754 //Billing Info
755 $this->type("billing_first_name", $firstName2 . 'billing');
756 $this->type("billing_last_name", $lastName2 . 'billing');
757 $this->type("billing_street_address-5", "0121 Mount Highschool.");
758 $this->type(" billing_city-5", "Shangai");
759 $this->select("billing_country_id-5", "value=1228");
760 $this->select("billing_state_province_id-5", "value=1004");
761 $this->type("billing_postal_code-5", "94129");
762
763 $this->type("current_employer", "ABCD");
764 $this->type("job_title", "Painter");
765
766 $this->type("nick_name", "Nickkk");
767 $this->type("url-1", "http://www.testweb.com");
768
769 $this->type("street_address-Primary", "Primary street address");
770 $this->type("city-Primary", "primecity");
771 $this->type("phone-Primary-1", "9866776422");
772 $this->type("postal_code-Primary", "6534");
773
774 $this->type("custom_" . $customId[0], "fname_custom1");
775 $this->type("custom_" . $customId[1], "mname_custom1");
776 $this->type("custom_" . $customId[2], "lname_custom1");
777
778 $this->type("middle_name", "xyz");
779 $this->click("name=gender_id value=2");
780 $this->select("participant_role", "value=2");
781
782 $this->click("_qf_Register_upload-bottom");
783 $this->waitForElementPresent("_qf_Participant_1_next-Array");
784
785 $this->type("email-Primary", $email3);
786 $this->type("first_name", $participantfname2);
787 $this->type("last_name", $participantlname2);
788 $this->type("street_address-1", "participant street addres");
789 $this->type("city-1", "pune");
790 $this->type("postal_code-1", "2354");
791 $this->select("state_province-1", "value=1001");
792
793 $this->type("current_employer", "ABCD");
794 $this->type("job_title", "BATCHER");
795
796 $this->clickLink("_qf_Participant_1_next-Array", "_qf_Confirm_next-bottom");
797 $this->click("_qf_Confirm_next-bottom");
798 }
799
800 /**
801 * @return array|string
802 */
803 public function _addEmailField() {
804 //add email field in name and address profile
805 $this->openCiviPage('admin/uf/group/field/add', 'reset=1&action=add&gid=1', "_qf_Field_next-bottom");
806 $this->select("field_name[0]", "value=Contact");
807 $this->select("field_name[1]", "value=email");
808 $this->select("field_name[2]", "value=0");
809 $this->click('_qf_Field_next-bottom');
810 $this->waitForPageToLoad($this->getTimeoutMsec());
811
812 $cfId = "";
813 //check wheather webtest has created the field
814 if ($this->assertElementNotContainsText('crm-notification-container', "The selected field was not added. It already exists in this profile")) {
815 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr[8]/td[9]/span/a[text()='Edit']");
816 $cfId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[8]/td[9]/span/a[text()='Edit']/@href"));
817 $cfId = $cfId[1];
818 }
819 return $cfId;
820 }
821
822 /**
823 * @param int $cfId
824 */
825 public function _removeEmailField($cfId) {
826 $this->openCiviPage("admin/uf/group/field", "action=delete&id={$cfId}");
827 $this->click("_qf_Field_next-bottom");
828 $this->waitForPageToLoad($this->getTimeoutMsec());
829 }
830 }