3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Event_PCPAddTest
32 class WebTest_Event_PCPAddTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testPCPAdd() {
39 //give permissions to anonymous user
40 $permission = array('edit-1-profile-listings-and-forms', 'edit-1-access-all-custom-data', 'edit-1-register-for-events', 'edit-1-make-online-contributions');
41 $this->changePermissions($permission);
43 // Log in as normal user
44 $this->webtestLogin();
47 $domainNameValue = 'civicrm organization ';
48 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
49 $lastName = 'An' . substr(sha1(rand()), 0, 7);
50 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
51 $email = substr(sha1(rand()), 0, 7) . '@example.org';
52 $this->openCiviPage("admin/domain", "action=update&reset=1", '_qf_Domain_cancel-bottom');
53 $this->type('name', $domainNameValue);
54 $this->type('email_name', $firstName);
55 $this->type('email_address', $email);
57 $this->click('_qf_Domain_next_view-bottom');
58 $this->waitForPageToLoad($this->getTimeoutMsec());
60 // a random 7-char string and an even number to make this pass unique
61 $conHash = substr(sha1(rand()), 0, 7);
62 $conRand = $contributionAmount = 1000;
63 $contributionPageTitle = 'Contribution page for pcp' . $conHash;
64 $conProcessorType = 'Dummy';
65 $conAmountSection = TRUE;
69 $conRecurring = FALSE;
70 $conMemberships = FALSE;
71 $conMemPriceSetId = NULL;
73 $conProfilePreId = NULL;
74 $conProfilePostId = NULL;
78 $conIsAprovalNeeded = TRUE;
80 // We need a payment processor
81 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
83 //create contribution page for event pcp with campaign type as contribution
84 $contributionPageId = $this->webtestAddContributionPage($conHash,
86 $contributionPageTitle,
87 array($processorName => $conProcessorType),
105 //event add for contribute campaign type
106 $campaignType = 'contribute';
107 $this->_testAddEventForPCP($processorName, $campaignType, $contributionPageId, $firstName, $lastName, $middleName, $email);
109 //event add for contribute campaign type
110 $campaignType = 'event';
111 $firstName = 'Pa' . substr(sha1(rand()), 0, 4);
112 $lastName = 'Cn' . substr(sha1(rand()), 0, 7);
113 $middleName = 'PCid' . substr(sha1(rand()), 0, 7);
114 $email = substr(sha1(rand()), 0, 7) . '@example.org';
115 $this->_testAddEventForPCP($processorName, $campaignType, NULL, $firstName, $lastName, $middleName, $email);
119 * @param $processorName
120 * @param $campaignType
121 * @param null $contributionPageId
127 function _testAddEventForPCP($processorName, $campaignType, $contributionPageId = NULL, $firstName, $lastName, $middleName, $email) {
129 $this->openCiviPage("event/add", "reset=1&action=add");
131 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
132 $eventDescription = "Here is a description for this conference.";
133 $this->_testAddEventInfo($eventTitle, $eventDescription);
135 $streetAddress = "100 Main Street";
136 $this->_testAddLocation($streetAddress);
138 $this->_testAddFees(FALSE, FALSE, $processorName);
140 // intro text for registration page
141 $registerIntro = "Fill in all the fields below and click Continue.";
142 $multipleRegistrations = TRUE;
143 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
145 $pageId = $this->_testEventPcpAdd($campaignType, $contributionPageId);
146 $this->_testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, '', $campaignType, TRUE);
151 * @param $eventDescription
153 function _testAddEventInfo($eventTitle, $eventDescription) {
154 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
156 $this->select("event_type_id", "value=1");
158 // Attendee role s/b selected now.
159 $this->select("default_role_id", "value=1");
161 // Enter Event Title, Summary and Description
162 $this->type("title", $eventTitle);
163 $this->type("summary", "This is a great conference. Sign up now!");
165 // Type description in ckEditor (fieldname, text to type, editor)
166 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
168 // Choose Start and End dates.
169 // Using helper webtestFillDate function.
170 $this->webtestFillDateTime("start_date", "+1 week");
171 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
173 $this->type("max_participants", "50");
174 $this->click("is_map");
175 $this->click("_qf_EventInfo_upload-bottom");
179 * @param $streetAddress
181 function _testAddLocation($streetAddress) {
182 // Wait for Location tab form to load
183 $this->waitForPageToLoad($this->getTimeoutMsec());
184 $this->waitForElementPresent("_qf_Location_upload-bottom");
186 // Fill in address fields
187 $streetAddress = "100 Main Street";
188 $this->type("address_1_street_address", $streetAddress);
189 $this->type("address_1_city", "San Francisco");
190 $this->type("address_1_postal_code", "94117");
191 $this->select("address_1_state_province_id", "value=1004");
192 $this->type("email_1_email", "info@civicrm.org");
194 $this->click("_qf_Location_upload-bottom");
196 // Wait for "saved" status msg
197 $this->waitForElementPresent("_qf_Location_upload-bottom");
198 $this->waitForTextPresent("'Event Location' information has been saved.");
202 * @param bool $discount
203 * @param bool $priceSet
204 * @param string $processorName
206 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro") {
208 $this->click("link=Fees");
209 $this->waitForElementPresent("_qf_Fee_upload-bottom");
210 $this->click("CIVICRM_QFID_1_is_monetary");
211 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
216 $this->select("financial_type_id", "label=Donation");
217 $this->type("label_1", "Member");
218 $this->type("value_1", "250.00");
219 $this->type("label_2", "Non-member");
220 $this->type("value_2", "325.00");
222 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
226 // enter early bird discounts TBD
229 $this->click("_qf_Fee_upload-bottom");
231 // Wait for "saved" status msg
232 $this->waitForElementPresent("_qf_Fee_upload-bottom");
233 $this->waitForTextPresent("'Fees' information has been saved.");
237 * @param $registerIntro
238 * @param bool $multipleRegistrations
240 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
241 // Go to Online Registration tab
242 $this->click("link=Online Registration");
243 $this->waitForElementPresent("_qf_Registration_upload-bottom");
245 $this->check("is_online_registration");
247 $this->assertChecked("is_online_registration");
248 if ($multipleRegistrations) {
249 $this->check("is_multiple_registrations");
250 $this->assertChecked("is_multiple_registrations");
253 $this->click('intro_text-plain');
254 $this->fillRichTextField("intro_text", $registerIntro);
256 // enable confirmation email
257 $this->click("CIVICRM_QFID_1_is_email_confirm");
258 $this->type("confirm_from_name", "Jane Doe");
259 $this->type("confirm_from_email", "jane.doe@example.org");
261 $this->click("_qf_Registration_upload-bottom");
262 $this->waitForElementPresent("_qf_Registration_upload-bottom");
263 $this->waitForTextPresent("'Online Registration' information has been saved.");
273 * @param int $numberRegistrations
274 * @param $campaignType
275 * @param bool $anonymous
277 function _testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, $numberRegistrations = 1, $campaignType, $anonymous = TRUE) {
278 $hash = substr(sha1(rand()), 0, 7);
279 $contributionAmount = 600;
281 // registering online
283 $this->webtestLogout();
286 //participant registeration
287 $firstNameParticipants = 'Jane' . substr(sha1(rand()), 0, 7);
288 $lastNameParticipants = 'Smith' . substr(sha1(rand()), 0, 7);
289 $emailParticipants = 'jane' . substr(sha1(rand()), 0, 7) . "@example.org";
291 $registerUrl = "civicrm/event/register?id={$pageId}&reset=1";
292 $this->open($this->sboxPath
. $registerUrl);
294 $this->type("first_name", "{$firstNameParticipants}");
295 $this->type("last_name", "{$lastNameParticipants}");
296 $this->select("additional_participants", "value=" . $numberRegistrations);
297 $this->type("email-Primary", $emailParticipants);
298 $this->select("credit_card_type", "value=Visa");
299 $this->type("credit_card_number", "4111111111111111");
300 $this->type("cvv2", "000");
301 $this->select("credit_card_exp_date[M]", "value=1");
302 $this->select("credit_card_exp_date[Y]", "value=2020");
303 $this->type("billing_first_name", "{$firstNameParticipants}");
304 $this->type("billing_last_name", "{$lastNameParticipants}");
305 $this->type("billing_street_address-5", "15 Main St.");
306 $this->type(" billing_city-5", "San Jose");
307 $this->select("billing_country_id-5", "value=1228");
308 $this->select("billing_state_province_id-5", "value=1004");
309 $this->type("billing_postal_code-5", "94129");
311 $this->click("_qf_Register_upload-bottom");
313 if ($numberRegistrations > 1) {
314 for ($i = 1; $i <= $numberRegistrations; $i++
) {
315 $this->waitForPageToLoad($this->getTimeoutMsec());
316 // Look for Skip button
317 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
318 $this->type("email-Primary", "{$firstName}" . substr(sha1(rand()), 0, 7) . "@example.org");
319 $this->click("_qf_Participant_{$i}_next");
323 $this->waitForPageToLoad($this->getTimeoutMsec());
324 $this->waitForElementPresent("_qf_Confirm_next-bottom");
325 $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information");
326 $this->assertStringsPresent($confirmStrings);
327 $this->click("_qf_Confirm_next-bottom");
328 $this->waitForPageToLoad($this->getTimeoutMsec());
329 $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date");
330 $this->assertStringsPresent($thankStrings);
332 //pcp creation via different user
333 $this->openCiviPage('contribute/campaign', "action=add&reset=1&pageId={$pageId}&component=event", "_qf_PCPAccount_next-bottom");
335 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
337 $this->type("cms_name", $cmsUserName);
338 $this->click("checkavailability");
339 $this->waitForTextPresent('This username is currently available');
340 $this->type("first_name", $firstName);
341 $this->type("last_name", $lastName);
342 $this->type("email-Primary", $email);
343 $this->click("_qf_PCPAccount_next-bottom");
344 $this->waitForElementPresent("_qf_Campaign_upload-bottom");
346 $pcpTitle = 'PCPTitle' . substr(sha1(rand()), 0, 7);
347 $this->type("pcp_title", $pcpTitle);
348 $this->type("pcp_intro_text", "Welcome Text $hash");
349 $this->type("goal_amount", $contributionAmount);
350 $this->click("_qf_Campaign_upload-bottom");
351 $this->waitForPageToLoad($this->getTimeoutMsec());
354 //login to check contribution
356 // Log in using webtestLogin() method
357 $this->webtestLogin();
359 $this->openCiviPage('admin/pcp', 'reset=1&page_type=event', "_qf_PCP_refresh");
360 $this->select('status_id', 'value=1');
361 $this->click("_qf_PCP_refresh");
362 $this->waitForElementPresent("_qf_PCP_refresh");
363 $id = explode('id=', $this->getAttribute("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody//tr/td/a[text()='$pcpTitle']@href"));
364 $pcpUrl = "civicrm/pcp/info?reset=1&id=$id[1]";
365 $this->click("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody//tr/td/a[text()='$pcpTitle']/../../td[7]/span/a[text()='Approve']");
367 $this->waitForPageToLoad($this->getTimeoutMsec());
369 $this->webtestLogout();
371 $this->open($this->sboxPath
. $pcpUrl);
372 $this->waitForElementPresent("xpath=//div[@class='pcp-donate']/a");
373 $this->click("xpath=//div[@class='pcp-donate']/a");
375 if ($campaignType == 'contribute') {
376 $this->waitForElementPresent("_qf_Main_upload-bottom");
377 $emailElement = "email-5";
379 elseif ($campaignType == 'event') {
380 $this->waitForElementPresent('_qf_Register_upload-bottom');
381 $emailElement = "email-Primary";
384 if ($campaignType == 'contribute') {
385 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", "$contributionAmount");
388 elseif ($campaignType == 'event') {
389 $contributionAmount = '250.00';
392 $firstNameDonar = 'Andrew' . substr(sha1(rand()), 0, 7);
393 $lastNameDonar = 'Roger' . substr(sha1(rand()), 0, 7);
394 $middleNameDonar = 'Nicholas' . substr(sha1(rand()), 0, 7);
396 if ($this->isElementPresent("first_name")) {
397 $this->type('first_name', $firstNameDonar);
400 if ($this->isElementPresent("last_name")) {
401 $this->type('last_name', $lastNameDonar);
403 $this->type("{$emailElement}", $firstNameDonar . "@example.com");
404 $this->webtestAddCreditCardDetails();
405 $this->webtestAddBillingDetails($firstNameDonar, $middleNameDonar, $lastNameDonar);
407 if ($campaignType == 'contribute') {
408 $this->click("_qf_Main_upload-bottom");
410 elseif ($campaignType == 'event') {
411 $this->click('_qf_Register_upload-bottom');
414 $this->waitForPageToLoad($this->getTimeoutMsec());
415 $this->waitForElementPresent("_qf_Confirm_next-bottom");
416 $this->click("_qf_Confirm_next-bottom");
418 if ($campaignType == 'contribute') {
419 $this->waitForTextPresent("Your transaction has been processed successfully");
421 elseif ($campaignType == 'event') {
422 $this->waitForTextPresent("Thank You for Registering");
425 //login to check contribution
426 $this->webtestLogin();
428 if ($campaignType == 'event') {
429 $this->_testParticipantSearchEventName($eventTitle, $lastNameDonar, $firstNameDonar, $firstName, $lastName, $contributionAmount);
431 elseif ($campaignType == 'contribute') {
432 $this->_testSearchTest($firstNameDonar, $lastNameDonar, $firstName, $lastName, $contributionAmount);
437 * @param $campaignType
438 * @param $contributionPageId
442 function _testEventPcpAdd($campaignType, $contributionPageId) {
443 $hash = substr(sha1(rand()), 0, 7);
444 $isPcpApprovalNeeded = TRUE;
446 // fill in step 9 (Enable Personal Campaign Pages)
447 $this->click('link=Personal Campaigns');
448 $this->waitForElementPresent('pcp_active');
449 $this->click('pcp_active');
450 $this->waitForElementPresent('_qf_Event_upload-bottom');
452 $this->select('target_entity_type', "value={$campaignType}");
454 if ($campaignType == 'contribute' && !empty($contributionPageId)) {
456 $this->select('target_entity_id', "value={$contributionPageId}");
460 if (!$isPcpApprovalNeeded) {
462 $this->click('is_approval_needed');
465 $this->type('notify_email', "$hash@example.name");
466 $this->select('supporter_profile_id', 'value=2');
467 $this->type('tellfriend_limit', 7);
468 $this->type('link_text', "'Create Personal Campaign Page' link text $hash");
470 $this->click('_qf_Event_upload-bottom');
471 $this->waitForElementPresent('_qf_Event_upload-bottom');
472 $text = "'Personal Campaigns' information has been saved.";
473 $this->waitForText('crm-notification-container', $text);
475 // parse URL to grab the contribution page id
476 return $this->urlArg('id');
481 * @param $lastNameDonar
482 * @param $firstNameDonar
483 * @param $firstNameCreator
484 * @param $lastNameCreator
487 function _testParticipantSearchEventName($eventName, $lastNameDonar, $firstNameDonar, $firstNameCreator, $lastNameCreator, $amount) {
488 $sortName = $lastNameDonar . ', ' . $firstNameDonar;
489 $this->openCiviPage("event/search", "reset=1");
491 $this->select2("event_id", $eventName);
493 $this->click("_qf_Search_refresh");
494 $this->waitForPageToLoad($this->getTimeoutMsec());
496 $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);
497 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr/td[8]/span/a[text()='View']");
498 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
500 $this->webtestVerifyTabularData(
502 'From' => "{$firstNameDonar} {$lastNameDonar}",
503 'Total Amount' => $amount,
504 'Contribution Status' => 'Completed',
507 $softCreditor = "{$firstNameCreator} {$lastNameCreator}";
508 $this->verifyText("xpath=//div[@id='PCPView']/div[2]//table[@class='crm-info-panel']/tbody/tr[2]/td[2]", preg_quote($softCreditor), 'In line ' . __LINE__
);
514 * @param $pcpCreatorFirstName
515 * @param $pcpCreatorLastName
518 function _testSearchTest($firstName, $lastName, $pcpCreatorFirstName, $pcpCreatorLastName, $amount) {
519 $sortName = "$pcpCreatorLastName, $pcpCreatorFirstName";
520 $displayName = "$firstName $lastName";
522 // visit contact search page
523 $this->openCiviPage("contact/search", "reset=1");
525 // fill name as first_name
526 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $pcpCreatorFirstName);
529 $this->click("_qf_Basic_refresh");
530 $this->waitForPageToLoad($this->getTimeoutMsec());
532 $this->click("xpath=//div[@class='crm-search-results']//table/tbody//tr/td[3]/a[text()='{$sortName}']");
533 $this->waitForPageToLoad($this->getTimeoutMsec());
535 $this->click("css=li#tab_contribute a");
536 $this->waitForElementPresent("xpath=//form[@id='Search']/div[@class='view-content']/table[2]/tbody/tr[@id='rowid']/td/a[text()='$displayName']");
537 $this->click("xpath=//form[@id='Search']/div[@class='view-content']/table[2]/tbody/tr[@id='rowid']/td[8]/a[text()='View']");
538 $this->waitForPageToLoad($this->getTimeoutMsec());
540 $this->webtestVerifyTabularData(
542 'From' => "{$firstName} {$lastName}",
543 'Net Amount' => $amount,
544 'Contribution Status' => 'Completed',
547 $softCreditor = "{$pcpCreatorFirstName} {$pcpCreatorLastName}";
548 $this->verifyText("xpath=//div[@id='PCPView']/div[2]//table[@class='crm-info-panel']/tbody/tr[2]/td[2]", preg_quote($softCreditor), 'In line ' . __LINE__
);