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