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