Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-08-16-18-06-10
[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-2015 |
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->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 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
541 $this->assertElementContainsText('css=.crm-event-manage-fee-form-block-payment_processor', $processorName);
542 $this->check($xpath);
543 $this->select("financial_type_id", "label=Event Fee");
544 if ($priceSet) {
545 // get one - TBD
546 }
547 else {
548 $this->type("label_1", "Member");
549 $this->type("value_1", "250.00");
550 $this->type("label_2", "Non-member");
551 $this->type("value_2", "325.00");
552 //set default
553 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
554 }
555
556 if ($discount) {
557 // enter early bird discounts TBD
558 }
559
560 $this->click("_qf_Fee_upload-bottom");
561
562 // Wait for "saved" status msg
563 $this->waitForElementPresent("_qf_Fee_upload-bottom");
564 $this->waitForTextPresent("'Fees' information has been saved.");
565 }
566
567 /**
568 * Test adding multiple profiles.
569 *
570 * @param int $profileId
571 *
572 * @return null
573 */
574 public function _testAddMultipleProfile($profileId) {
575 // Go to Online Contribution tab
576 $this->click("link=Online Registration");
577 $this->waitForElementPresent("_qf_Registration_upload-bottom");
578 $this->click("is_online_registration");
579 $this->check("is_multiple_registrations");
580 $this->select("xpath=//*[@id='custom_pre_id']/parent::td/div[1]/div/span/select", "value=1");
581 $this->select("xpath=//*[@id='custom_post_id']/parent::td/div[1]/div/span/select", "value=" . $profileId[3]);
582 $this->select("xpath=//*[@id='additional_custom_post_id']/parent::td/div[1]/div/span/select", "- same as for main contact -");
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_1");
587 $this->select("xpath=//*[@id='custom_post_id_multiple_1']/parent::td/div[1]/div/span/select", "value=" . $profileId[2]);
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_2");
592 $this->select("xpath=//*[@id='custom_post_id_multiple_2']/parent::td/div[1]/div/span/select", "value=" . $profileId[1]);
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_3");
597 $this->select("xpath=//*[@id='custom_post_id_multiple_3']/parent::td/div[1]/div/span/select", "value=" . $profileId[4]);
598
599 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
600 $this->click("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
601 $this->waitForElementPresent("custom_post_id_multiple_4");
602 $this->select("xpath=//*[@id='custom_post_id_multiple_4']/parent::td/div[1]/div/span/select", "value=" . $profileId[5]);
603
604 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
605 $this->click("xpath=//div[@id='registration_screen']/table[2]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
606 $this->waitForElementPresent("custom_post_id_multiple_5");
607 $this->select("xpath=//*[@id='custom_post_id_multiple_5']/parent::td/div[1]/div/span/select", "value=" . $profileId[6]);
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_1");
612 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_1']/parent::td/div[1]/div/span/select", "value=" . $profileId[5]);
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_2");
617 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_2']/parent::td/div[1]/div/span/select", "value=" . $profileId[1]);
618
619 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
620 $this->click("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
621 $this->waitForElementPresent("additional_custom_post_id_multiple_3");
622 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_3']/parent::td/div[1]/div/span/select", "value=" . $profileId[2]);
623
624 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
625 $this->click("xpath=//div[@id='registration_screen']/table[3]//tbody/tr[2]/td[2]/span/a[text()='add another profile (bottom of page)']");
626 $this->waitForElementPresent("additional_custom_post_id_multiple_4");
627 $this->select("xpath=//*[@id='additional_custom_post_id_multiple_4']/parent::td/div[1]/div/span/select", "value=" . $profileId[3]);
628
629 $this->click("CIVICRM_QFID_1_is_email_confirm");
630 $this->type("confirm_from_name", "TestEvent");
631 $this->type("confirm_from_email", "testevent@test.com");
632 $this->click("_qf_Registration_upload-bottom");
633
634 // Wait for "saved" status msg
635 $this->waitForElementPresent("_qf_Registration_upload-bottom");
636 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved.");
637
638 return $this->urlArg('id');
639 }
640
641 /**
642 * @param int $eventPageId
643 * @param int $customId
644 * @param string $firstName
645 * @param string $lastName
646 * @param string $participantfname
647 * @param string $participantlname
648 * @param $email1
649 * @param $email2
650 */
651 public function _testEventRegistration(
652 $eventPageId, $customId, $firstName, $lastName,
653 $participantfname, $participantlname, $email1, $email2
654 ) {
655 $this->openCiviPage("event/register", "id={$eventPageId}&reset=1&action=preview", "_qf_Register_upload-bottom");
656 $this->waitForElementPresent("_qf_Register_upload-bottom");
657 $this->select("additional_participants", "value=1");
658
659 $this->type("email-Primary", $email1);
660 $this->type("first_name", $firstName);
661 $this->type("last_name", $lastName);
662 $this->type("street_address-1", "Test street address");
663 $this->type("city-1", "Mumbai");
664 $this->type("postal_code-1", "2354");
665 $this->select("state_province-1", "value=1001");
666
667 // Credit Card Info
668 $this->select("credit_card_type", "value=Visa");
669 $this->type("credit_card_number", "4111111111111111");
670 $this->type("cvv2", "000");
671 $this->select("credit_card_exp_date[M]", "value=1");
672 $this->select("credit_card_exp_date[Y]", "value=2020");
673
674 //Billing Info
675 $this->type("billing_first_name", $firstName . 'billing');
676 $this->type("billing_last_name", $lastName . 'billing');
677 $this->type("billing_street_address-5", "0121 Mount Highschool.");
678 $this->type(" billing_city-5", "Shangai");
679 $this->select("billing_country_id-5", "value=1228");
680 $this->select("billing_state_province_id-5", "value=1004");
681 $this->type("billing_postal_code-5", "94129");
682
683 $this->waitForElementPresent("current_employer");
684 $this->type("current_employer", "ABCD");
685 $this->type("job_title", "Painter");
686 $this->waitForElementPresent('nick_name');
687 $this->type("nick_name", "Nick");
688 $this->type("url-1", "http://www.test.com");
689
690 $this->waitForElementPresent('street_address-Primary');
691 $this->type("street_address-Primary", "Primary street address");
692 $this->type("city-Primary", "primecity");
693 $this->type("phone-Primary-1", "98667764");
694 $this->type("postal_code-Primary", "6548");
695
696 $this->type("custom_" . $customId[0], "fname_custom1");
697 $this->type("custom_" . $customId[1], "mname_custom1");
698 $this->type("custom_" . $customId[2], "lname_custom1");
699
700 $this->type("middle_name", "xyz");
701 $this->click("name=gender_id value=2");
702 $this->waitForElementPresent('participant_role');
703 $this->select("participant_role", "value=2");
704
705 $this->click("_qf_Register_upload-bottom");
706 $this->waitForElementPresent("_qf_Participant_1_next-Array");
707 $this->type("email-Primary", $email2);
708 $this->type("first_name", $participantfname);
709 $this->type("last_name", $participantlname);
710 $this->type("street_address-1", "participant street address");
711 $this->type("city-1", "pune");
712 $this->type("postal_code-1", "2354");
713 $this->select("state_province-1", "value=1001");
714
715 $this->waitForElementPresent("current_employer");
716 $this->type("current_employer", "ABCD");
717 $this->type("job_title", "Potato picker");
718
719 $this->type("custom_" . $customId[0], "participant_custom1");
720 $this->type("custom_" . $customId[1], "participant_custom1");
721 $this->type("custom_" . $customId[2], "participant_custom1");
722
723 $this->waitForElementPresent('street_address-Primary');
724 $this->type("street_address-Primary", "Primary street address");
725 $this->type("city-Primary", "primecity");
726 $this->type("phone-Primary-1", "98667764");
727 $this->type("postal_code-Primary", "6548");
728 $this->waitForElementPresent('nick_name');
729 $this->type("nick_name", "Nick1");
730 $this->type("url-1", "http://www.part.com");
731
732 $this->clickLink("_qf_Participant_1_next-Array", "_qf_Confirm_next-bottom");
733 $this->click("_qf_Confirm_next-bottom");
734 $this->waitForPageToLoad($this->getTimeoutMsec());
735 }
736
737 /**
738 * @param int $eventPageId
739 * @param int $customId
740 * @param string $firstName2
741 * @param string $lastName2
742 * @param string $participantfname2
743 * @param $participantlname2
744 * @param $email3
745 * @param $email4
746 */
747 public function _testEventRegistrationAfterRemoving($eventPageId, $customId, $firstName2, $lastName2, $participantfname2, $participantlname2, $email3, $email4) {
748 $this->openCiviPage("event/register", "id={$eventPageId}&reset=1&action=preview", "_qf_Register_upload-bottom");
749 $this->select("additional_participants", "value=1");
750
751 $this->type("email-Primary", $email4);
752 $this->type("first_name", $firstName2);
753 $this->type("last_name", $lastName2);
754 $this->type("street_address-1", "Test street address");
755 $this->type("city-1", "Mumbai");
756 $this->type("postal_code-1", "2354");
757 $this->select("state_province-1", "value=1001");
758
759 // Credit Card Info
760 $this->select("credit_card_type", "value=Visa");
761 $this->type("credit_card_number", "4111111111111111");
762 $this->type("cvv2", "000");
763 $this->select("credit_card_exp_date[M]", "value=1");
764 $this->select("credit_card_exp_date[Y]", "value=2020");
765
766 //Billing Info
767 $this->type("billing_first_name", $firstName2 . 'billing');
768 $this->type("billing_last_name", $lastName2 . 'billing');
769 $this->type("billing_street_address-5", "0121 Mount Highschool.");
770 $this->type(" billing_city-5", "Shangai");
771 $this->select("billing_country_id-5", "value=1228");
772 $this->select("billing_state_province_id-5", "value=1004");
773 $this->type("billing_postal_code-5", "94129");
774
775 $this->type("current_employer", "ABCD");
776 $this->type("job_title", "Painter");
777
778 $this->type("nick_name", "Nickkk");
779 $this->type("url-1", "http://www.testweb.com");
780
781 $this->type("street_address-Primary", "Primary street address");
782 $this->type("city-Primary", "primecity");
783 $this->type("phone-Primary-1", "9866776422");
784 $this->type("postal_code-Primary", "6534");
785
786 $this->type("custom_" . $customId[0], "fname_custom1");
787 $this->type("custom_" . $customId[1], "mname_custom1");
788 $this->type("custom_" . $customId[2], "lname_custom1");
789
790 $this->type("middle_name", "xyz");
791 $this->click("name=gender_id value=2");
792 $this->select("participant_role", "value=2");
793
794 $this->click("_qf_Register_upload-bottom");
795 $this->waitForElementPresent("_qf_Participant_1_next-Array");
796
797 $this->type("email-Primary", $email3);
798 $this->type("first_name", $participantfname2);
799 $this->type("last_name", $participantlname2);
800 $this->type("street_address-1", "participant street address");
801 $this->type("city-1", "pune");
802 $this->type("postal_code-1", "2354");
803 $this->select("state_province-1", "value=1001");
804
805 $this->type("current_employer", "ABCD");
806 $this->type("job_title", "BATCHER");
807
808 $this->clickLink("_qf_Participant_1_next-Array", "_qf_Confirm_next-bottom");
809 $this->click("_qf_Confirm_next-bottom");
810 }
811
812 /**
813 * @return array|string
814 */
815 public function _addEmailField() {
816 //add email field in name and address profile
817 $this->openCiviPage('admin/uf/group/field/add', 'reset=1&action=add&gid=1', "_qf_Field_next-bottom");
818 $this->select("field_name[0]", "value=Contact");
819 $this->select("field_name[1]", "value=email");
820 $this->select("field_name[2]", "value=0");
821 $this->click('_qf_Field_next-bottom');
822 $this->waitForPageToLoad($this->getTimeoutMsec());
823
824 $cfId = "";
825 //check wheather webtest has created the field
826 if ($this->assertElementNotContainsText('crm-notification-container', "The selected field was not added. It already exists in this profile")) {
827 $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr[8]/td[9]/span/a[text()='Edit']");
828 $cfId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[8]/td[9]/span/a[text()='Edit']/@href"));
829 $cfId = $cfId[1];
830 }
831 return $cfId;
832 }
833
834 /**
835 * @param int $cfId
836 */
837 public function _removeEmailField($cfId) {
838 $this->openCiviPage("admin/uf/group/field", "action=delete&id={$cfId}");
839 $this->click("_qf_Field_next-bottom");
840 $this->waitForPageToLoad($this->getTimeoutMsec());
841 }
842
843 }