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