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