CRM-15104 - applied the changes suggested by @colemanw.
[civicrm-core.git] / tests / phpunit / WebTest / Event / PCPAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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 require_once 'WebTest/Event/AddEventTest.php';
29
30 /**
31 * Class WebTest_Event_PCPAddTest
32 */
33 class WebTest_Event_PCPAddTest extends CiviSeleniumTestCase {
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
39 function testPCPAdd() {
40 //give permissions to anonymous user
41 $permission = array('edit-1-profile-listings-and-forms', 'edit-1-access-all-custom-data', 'edit-1-register-for-events', 'edit-1-make-online-contributions');
42 $this->changePermissions($permission);
43
44 // Log in as normal user
45 $this->webtestLogin();
46
47 // set domain values
48 $domainNameValue = 'civicrm organization ';
49 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
50 $lastName = 'An' . substr(sha1(rand()), 0, 7);
51 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
52 $email = substr(sha1(rand()), 0, 7) . '@example.org';
53 $this->openCiviPage("admin/domain", "action=update&reset=1", '_qf_Domain_cancel-bottom');
54 $this->type('name', $domainNameValue);
55 $this->type('email_name', $firstName);
56 $this->type('email_address', $email);
57
58 $this->click('_qf_Domain_next_view-bottom');
59 $this->waitForPageToLoad($this->getTimeoutMsec());
60
61 // a random 7-char string and an even number to make this pass unique
62 $conHash = substr(sha1(rand()), 0, 7);
63 $conRand = $contributionAmount = 1000;
64 $contributionPageTitle = 'Contribution page for pcp' . $conHash;
65 $conProcessorType = 'Dummy';
66 $conAmountSection = TRUE;
67 $conPayLater = TRUE;
68 $conOnBehalf = FALSE;
69 $conPledges = FALSE;
70 $conRecurring = FALSE;
71 $conMemberships = FALSE;
72 $conMemPriceSetId = NULL;
73 $conFriend = FALSE;
74 $conProfilePreId = NULL;
75 $conProfilePostId = NULL;
76 $conPremiums = FALSE;
77 $conWidget = FALSE;
78 $conPcp = FALSE;
79 $conIsAprovalNeeded = TRUE;
80
81 // We need a payment processor
82 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
83
84 //create contribution page for event pcp with campaign type as contribution
85 $contributionPageId = $this->webtestAddContributionPage($conHash,
86 $conRand,
87 $contributionPageTitle,
88 array($processorName => $conProcessorType),
89 $conAmountSection,
90 $conPayLater,
91 $conOnBehalf,
92 $conPledges,
93 $conRecurring,
94 $conMemberships,
95 $conMemPriceSetId,
96 $conFriend,
97 $conProfilePreId,
98 $conProfilePostId,
99 $conPremiums,
100 $conWidget,
101 $conPcp,
102 TRUE,
103 $conIsAprovalNeeded
104 );
105
106 //event add for contribute campaign type
107 $campaignType = 'contribute';
108 $this->_testAddEventForPCP($processorName, $campaignType, $contributionPageId, $firstName, $lastName, $middleName, $email);
109
110 //event add for contribute campaign type
111 $campaignType = 'event';
112 $firstName = 'Pa' . substr(sha1(rand()), 0, 4);
113 $lastName = 'Cn' . substr(sha1(rand()), 0, 7);
114 $middleName = 'PCid' . substr(sha1(rand()), 0, 7);
115 $email = substr(sha1(rand()), 0, 7) . '@example.org';
116 $this->_testAddEventForPCP($processorName, $campaignType, NULL, $firstName, $lastName, $middleName, $email);
117 }
118
119 /**
120 * @param $processorName
121 * @param $campaignType
122 * @param null $contributionPageId
123 * @param $firstName
124 * @param $lastName
125 * @param $middleName
126 * @param $email
127 */
128 function _testAddEventForPCP($processorName, $campaignType, $contributionPageId = NULL, $firstName, $lastName, $middleName, $email) {
129
130 $this->openCiviPage("event/add", "reset=1&action=add");
131
132 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
133 $eventDescription = "Here is a description for this conference.";
134 $this->_testAddEventInfo($eventTitle, $eventDescription);
135
136 $streetAddress = "100 Main Street";
137 $this->_testAddLocation($streetAddress);
138
139 $this->_testAddFees(FALSE, FALSE, $processorName);
140
141 // intro text for registration page
142 $registerIntro = "Fill in all the fields below and click Continue.";
143 $multipleRegistrations = TRUE;
144 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
145
146 $pageId = $this->_testEventPcpAdd($campaignType, $contributionPageId);
147 $this->_testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, '', $campaignType, TRUE);
148 }
149
150 /**
151 * @param $eventTitle
152 * @param $eventDescription
153 */
154 function _testAddEventInfo($eventTitle, $eventDescription) {
155 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
156
157 $this->select("event_type_id", "value=1");
158
159 // Attendee role s/b selected now.
160 $this->select("default_role_id", "value=1");
161
162 // Enter Event Title, Summary and Description
163 $this->type("title", $eventTitle);
164 $this->type("summary", "This is a great conference. Sign up now!");
165
166 // Type description in ckEditor (fieldname, text to type, editor)
167 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
168
169 // Choose Start and End dates.
170 // Using helper webtestFillDate function.
171 $this->webtestFillDateTime("start_date", "+1 week");
172 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
173
174 $this->type("max_participants", "50");
175 $this->click("is_map");
176 $this->click("_qf_EventInfo_upload-bottom");
177 }
178
179 /**
180 * @param $streetAddress
181 */
182 function _testAddLocation($streetAddress) {
183 // Wait for Location tab form to load
184 $this->waitForPageToLoad($this->getTimeoutMsec());
185 $this->waitForElementPresent("_qf_Location_upload-bottom");
186
187 // Fill in address fields
188 $streetAddress = "100 Main Street";
189 $this->type("address_1_street_address", $streetAddress);
190 $this->type("address_1_city", "San Francisco");
191 $this->type("address_1_postal_code", "94117");
192 $this->select("address_1_state_province_id", "value=1004");
193 $this->type("email_1_email", "info@civicrm.org");
194
195 $this->click("_qf_Location_upload-bottom");
196
197 // Wait for "saved" status msg
198 $this->waitForElementPresent("_qf_Location_upload-bottom");
199 $this->waitForTextPresent("'Event Location' information has been saved.");
200 }
201
202 /**
203 * @param bool $discount
204 * @param bool $priceSet
205 * @param string $processorName
206 */
207 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro") {
208 // Go to Fees tab
209 $this->click("link=Fees");
210 $this->waitForElementPresent("_qf_Fee_upload-bottom");
211 $this->click("CIVICRM_QFID_1_is_monetary");
212 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
213 if ($priceSet) {
214 // get one - TBD
215 }
216 else {
217 $this->select("financial_type_id", "label=Donation");
218 $this->type("label_1", "Member");
219 $this->type("value_1", "250.00");
220 $this->type("label_2", "Non-member");
221 $this->type("value_2", "325.00");
222 //set default
223 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
224 }
225
226 if ($discount) {
227 // enter early bird discounts TBD
228 }
229
230 $this->click("_qf_Fee_upload-bottom");
231
232 // Wait for "saved" status msg
233 $this->waitForElementPresent("_qf_Fee_upload-bottom");
234 $this->waitForTextPresent("'Fees' information has been saved.");
235 }
236
237 /**
238 * @param $registerIntro
239 * @param bool $multipleRegistrations
240 */
241 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
242 // Go to Online Registration tab
243 $this->click("link=Online Registration");
244 $this->waitForElementPresent("_qf_Registration_upload-bottom");
245
246 $this->check("is_online_registration");
247
248 $this->assertChecked("is_online_registration");
249 if ($multipleRegistrations) {
250 $this->check("is_multiple_registrations");
251 $this->assertChecked("is_multiple_registrations");
252 }
253
254 $this->click('intro_text-plain');
255 $this->fillRichTextField("intro_text", $registerIntro);
256
257 // enable confirmation email
258 $this->click("CIVICRM_QFID_1_is_email_confirm");
259 $this->type("confirm_from_name", "Jane Doe");
260 $this->type("confirm_from_email", "jane.doe@example.org");
261
262 $this->click("_qf_Registration_upload-bottom");
263 $this->waitForElementPresent("_qf_Registration_upload-bottom");
264 $this->waitForTextPresent("'Online Registration' information has been saved.");
265 }
266
267 /**
268 * @param $eventTitle
269 * @param $pageId
270 * @param $firstName
271 * @param $lastName
272 * @param $middleName
273 * @param $email
274 * @param int $numberRegistrations
275 * @param $campaignType
276 * @param bool $anonymous
277 */
278 function _testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, $numberRegistrations = 1, $campaignType, $anonymous = TRUE) {
279 $hash = substr(sha1(rand()), 0, 7);
280 $contributionAmount = 600;
281
282 // registering online
283 if ($anonymous) {
284 $this->webtestLogout();
285 }
286
287 //participant registeration
288 $firstNameParticipants = 'Jane' . substr(sha1(rand()), 0, 7);
289 $lastNameParticipants = 'Smith' . substr(sha1(rand()), 0, 7);
290 $emailParticipants = 'jane' . substr(sha1(rand()), 0, 7) . "@example.org";
291
292 $registerUrl = "civicrm/event/register?id={$pageId}&reset=1";
293 $this->open($this->sboxPath . $registerUrl);
294
295 $this->type("first_name", "{$firstNameParticipants}");
296 $this->type("last_name", "{$lastNameParticipants}");
297 $this->select("additional_participants", "value=" . $numberRegistrations);
298 $this->type("email-Primary", $emailParticipants);
299 $this->select("credit_card_type", "value=Visa");
300 $this->type("credit_card_number", "4111111111111111");
301 $this->type("cvv2", "000");
302 $this->select("credit_card_exp_date[M]", "value=1");
303 $this->select("credit_card_exp_date[Y]", "value=2020");
304 $this->type("billing_first_name", "{$firstNameParticipants}");
305 $this->type("billing_last_name", "{$lastNameParticipants}");
306 $this->type("billing_street_address-5", "15 Main St.");
307 $this->type(" billing_city-5", "San Jose");
308 $this->select("billing_country_id-5", "value=1228");
309 $this->select("billing_state_province_id-5", "value=1004");
310 $this->type("billing_postal_code-5", "94129");
311
312 $this->click("_qf_Register_upload-bottom");
313
314 if ($numberRegistrations > 1) {
315 for ($i = 1; $i <= $numberRegistrations; $i++) {
316 $this->waitForPageToLoad($this->getTimeoutMsec());
317 // Look for Skip button
318 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
319 $this->type("email-Primary", "{$firstName}" . substr(sha1(rand()), 0, 7) . "@example.org");
320 $this->click("_qf_Participant_{$i}_next");
321 }
322 }
323
324 $this->waitForPageToLoad($this->getTimeoutMsec());
325 $this->waitForElementPresent("_qf_Confirm_next-bottom");
326 $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information");
327 $this->assertStringsPresent($confirmStrings);
328 $this->click("_qf_Confirm_next-bottom");
329 $this->waitForPageToLoad($this->getTimeoutMsec());
330 $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date");
331 $this->assertStringsPresent($thankStrings);
332
333 //pcp creation via different user
334 $this->openCiviPage('contribute/campaign', "action=add&reset=1&pageId={$pageId}&component=event", "_qf_PCPAccount_next-bottom");
335
336 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
337
338 $this->type("cms_name", $cmsUserName);
339 $this->click("checkavailability");
340 $this->waitForTextPresent('This username is currently available');
341 $this->type("first_name", $firstName);
342 $this->type("last_name", $lastName);
343 $this->type("email-Primary", $email);
344 $this->click("_qf_PCPAccount_next-bottom");
345 $this->waitForElementPresent("_qf_Campaign_upload-bottom");
346
347 $pcpTitle = 'PCPTitle' . substr(sha1(rand()), 0, 7);
348 $this->type("pcp_title", $pcpTitle);
349 $this->type("pcp_intro_text", "Welcome Text $hash");
350 $this->type("goal_amount", $contributionAmount);
351 $this->click("_qf_Campaign_upload-bottom");
352 $this->waitForPageToLoad($this->getTimeoutMsec());
353
354 //admin pcp approval
355 //login to check contribution
356
357 // Log in using webtestLogin() method
358 $this->webtestLogin();
359
360 $this->openCiviPage('admin/pcp', 'reset=1&page_type=event', "_qf_PCP_refresh");
361 $this->select('status_id', 'value=1');
362 $this->click("_qf_PCP_refresh");
363 $this->waitForElementPresent("_qf_PCP_refresh");
364 $id = explode('id=', $this->getAttribute("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody//tr/td/a[text()='$pcpTitle']@href"));
365 $pcpUrl = "civicrm/pcp/info?reset=1&id=$id[1]";
366 $this->click("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody//tr/td/a[text()='$pcpTitle']/../../td[7]/span/a[text()='Approve']");
367
368 $this->waitForPageToLoad($this->getTimeoutMsec());
369
370 $this->webtestLogout();
371
372 $this->open($this->sboxPath . $pcpUrl);
373 $this->waitForElementPresent("xpath=//div[@class='pcp-donate']/a");
374 $this->click("xpath=//div[@class='pcp-donate']/a");
375 $emailElement = "";
376 if ($campaignType == 'contribute') {
377 $this->waitForElementPresent("_qf_Main_upload-bottom");
378 $emailElement = "email-5";
379 }
380 elseif ($campaignType == 'event') {
381 $this->waitForElementPresent('_qf_Register_upload-bottom');
382 $emailElement = "email-Primary";
383 }
384
385 if ($campaignType == 'contribute') {
386 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", "$contributionAmount");
387 $feeLevel = NULL;
388 }
389 elseif ($campaignType == 'event') {
390 $contributionAmount = '250.00';
391 }
392
393 $firstNameDonar = 'Andrew' . substr(sha1(rand()), 0, 7);
394 $lastNameDonar = 'Roger' . substr(sha1(rand()), 0, 7);
395 $middleNameDonar = 'Nicholas' . substr(sha1(rand()), 0, 7);
396
397 if ($this->isElementPresent("first_name")) {
398 $this->type('first_name', $firstNameDonar);
399 }
400
401 if ($this->isElementPresent("last_name")) {
402 $this->type('last_name', $lastNameDonar);
403 }
404 $this->type("{$emailElement}", $firstNameDonar . "@example.com");
405 $this->webtestAddCreditCardDetails();
406 $this->webtestAddBillingDetails($firstNameDonar, $middleNameDonar, $lastNameDonar);
407
408 if ($campaignType == 'contribute') {
409 $this->click("_qf_Main_upload-bottom");
410 }
411 elseif ($campaignType == 'event') {
412 $this->click('_qf_Register_upload-bottom');
413 }
414
415 $this->waitForPageToLoad($this->getTimeoutMsec());
416 $this->waitForElementPresent("_qf_Confirm_next-bottom");
417 $this->click("_qf_Confirm_next-bottom");
418
419 if ($campaignType == 'contribute') {
420 $this->waitForTextPresent("Your transaction has been processed successfully");
421 }
422 elseif ($campaignType == 'event') {
423 $this->waitForTextPresent("Thank You for Registering");
424 }
425
426 //login to check contribution
427 $this->webtestLogin();
428
429 if ($campaignType == 'event') {
430 $this->_testParticipantSearchEventName($eventTitle, $lastNameDonar, $firstNameDonar, $firstName, $lastName, $contributionAmount);
431 }
432 elseif ($campaignType == 'contribute') {
433 $this->_testSearchTest($firstNameDonar, $lastNameDonar, $firstName, $lastName, $contributionAmount);
434 }
435 }
436
437 /**
438 * @param $campaignType
439 * @param $contributionPageId
440 *
441 * @return null
442 */
443 function _testEventPcpAdd($campaignType, $contributionPageId) {
444 $hash = substr(sha1(rand()), 0, 7);
445 $isPcpApprovalNeeded = TRUE;
446
447 // fill in step 9 (Enable Personal Campaign Pages)
448 $this->click('link=Personal Campaigns');
449 $this->waitForElementPresent('pcp_active');
450 $this->click('pcp_active');
451 $this->waitForElementPresent('_qf_Event_upload-bottom');
452
453 $this->select('target_entity_type', "value={$campaignType}");
454
455 if ($campaignType == 'contribute' && !empty($contributionPageId)) {
456
457 $this->select('target_entity_id', "value={$contributionPageId}");
458
459 }
460
461 if (!$isPcpApprovalNeeded) {
462
463 $this->click('is_approval_needed');
464
465 }
466 $this->type('notify_email', "$hash@example.name");
467 $this->select('supporter_profile_id', 'value=2');
468 $this->type('tellfriend_limit', 7);
469 $this->type('link_text', "'Create Personal Campaign Page' link text $hash");
470
471 $this->click('_qf_Event_upload-bottom');
472 $this->waitForElementPresent('_qf_Event_upload-bottom');
473 $text = "'Personal Campaigns' information has been saved.";
474 $this->waitForText('crm-notification-container', $text);
475
476 // parse URL to grab the contribution page id
477 return $this->urlArg('id');
478 }
479
480 /**
481 * @param $eventName
482 * @param $lastNameDonar
483 * @param $firstNameDonar
484 * @param $firstNameCreator
485 * @param $lastNameCreator
486 * @param $amount
487 */
488 function _testParticipantSearchEventName($eventName, $lastNameDonar, $firstNameDonar, $firstNameCreator, $lastNameCreator, $amount) {
489 $sortName = $lastNameDonar . ', ' . $firstNameDonar;
490 $this->openCiviPage("event/search", "reset=1");
491
492 $this->select2("event_id", $eventName);
493
494 $this->click("_qf_Search_refresh");
495 $this->waitForPageToLoad($this->getTimeoutMsec());
496
497 $this->clickLink("xpath=//div[@id='participantSearch']/table/tbody/tr[1]/td[@class='crm-participant-sort_name']/a[text()='{$sortName}']/../../td[11]/span/a[text()='View']", "xpath=//table[@class='selector row-highlight']/tbody/tr/td[8]/span/a[text()='View']", FALSE);
498 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[8]/span/a[text()='View']");
499 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
500
501 $this->webtestVerifyTabularData(
502 array(
503 'From' => "{$firstNameDonar} {$lastNameDonar}",
504 'Total Amount' => $amount,
505 'Contribution Status' => 'Completed',
506 )
507 );
508 $softCreditor = "{$firstNameCreator} {$lastNameCreator}";
509 $this->verifyText("xpath=//div[@id='PCPView']/div[2]//table[@class='crm-info-panel']/tbody/tr[2]/td[2]", preg_quote($softCreditor), 'In line ' . __LINE__);
510 }
511
512 /**
513 * @param $firstName
514 * @param $lastName
515 * @param $pcpCreatorFirstName
516 * @param $pcpCreatorLastName
517 * @param $amount
518 */
519 function _testSearchTest($firstName, $lastName, $pcpCreatorFirstName, $pcpCreatorLastName, $amount) {
520 $sortName = "$pcpCreatorLastName, $pcpCreatorFirstName";
521 $displayName = "$firstName $lastName";
522
523 // visit contact search page
524 $this->openCiviPage("contact/search", "reset=1");
525
526 // fill name as first_name
527 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $pcpCreatorFirstName);
528
529 // click to search
530 $this->click("_qf_Basic_refresh");
531 $this->waitForPageToLoad($this->getTimeoutMsec());
532
533 $this->click("xpath=//div[@class='crm-search-results']//table/tbody//tr/td[3]/a[text()='{$sortName}']");
534 $this->waitForPageToLoad($this->getTimeoutMsec());
535
536 $this->click("css=li#tab_contribute a");
537 $this->waitForElementPresent("xpath=//form[@id='Search']/div[@class='view-content']/table[2]/tbody/tr[@id='rowid']/td/a[text()='$displayName']");
538 $this->click("xpath=//form[@id='Search']/div[@class='view-content']/table[2]/tbody/tr[@id='rowid']/td[8]/a[text()='View']");
539 $this->waitForPageToLoad($this->getTimeoutMsec());
540
541 $this->webtestVerifyTabularData(
542 array(
543 'From' => "{$firstName} {$lastName}",
544 'Net Amount' => $amount,
545 'Contribution Status' => 'Completed',
546 )
547 );
548 $softCreditor = "{$pcpCreatorFirstName} {$pcpCreatorLastName}";
549 $this->verifyText("xpath=//div[@id='PCPView']/div[2]//table[@class='crm-info-panel']/tbody/tr[2]/td[2]", preg_quote($softCreditor), 'In line ' . __LINE__);
550 }
551 }
552