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';
28 require_once 'WebTest/Event/AddEventTest.php';
31 * Class WebTest_Event_PCPAddTest
33 class WebTest_Event_PCPAddTest
extends CiviSeleniumTestCase
{
35 protected function setUp() {
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);
44 // Log in as normal user
45 $this->webtestLogin();
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);
58 $this->click('_qf_Domain_next_view-bottom');
59 $this->waitForPageToLoad($this->getTimeoutMsec());
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;
70 $conRecurring = FALSE;
71 $conMemberships = FALSE;
72 $conMemPriceSetId = NULL;
74 $conProfilePreId = NULL;
75 $conProfilePostId = NULL;
79 $conIsAprovalNeeded = TRUE;
81 // We need a payment processor
82 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
84 //create contribution page for event pcp with campaign type as contribution
85 $contributionPageId = $this->webtestAddContributionPage($conHash,
87 $contributionPageTitle,
88 array($processorName => $conProcessorType),
106 //event add for contribute campaign type
107 $campaignType = 'contribute';
108 $this->_testAddEventForPCP($processorName, $campaignType, $contributionPageId, $firstName, $lastName, $middleName, $email);
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);
120 * @param $processorName
121 * @param $campaignType
122 * @param null $contributionPageId
128 function _testAddEventForPCP($processorName, $campaignType, $contributionPageId = NULL, $firstName, $lastName, $middleName, $email) {
130 $this->openCiviPage("event/add", "reset=1&action=add");
132 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
133 $eventDescription = "Here is a description for this conference.";
134 $this->_testAddEventInfo($eventTitle, $eventDescription);
136 $streetAddress = "100 Main Street";
137 $this->_testAddLocation($streetAddress);
139 $this->_testAddFees(FALSE, FALSE, $processorName);
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);
146 $pageId = $this->_testEventPcpAdd($campaignType, $contributionPageId);
147 $this->_testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, '', $campaignType, TRUE);
152 * @param $eventDescription
154 function _testAddEventInfo($eventTitle, $eventDescription) {
155 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
157 $this->select("event_type_id", "value=1");
159 // Attendee role s/b selected now.
160 $this->select("default_role_id", "value=1");
162 // Enter Event Title, Summary and Description
163 $this->type("title", $eventTitle);
164 $this->type("summary", "This is a great conference. Sign up now!");
166 // Type description in ckEditor (fieldname, text to type, editor)
167 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
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 ");
174 $this->type("max_participants", "50");
175 $this->click("is_map");
176 $this->click("_qf_EventInfo_upload-bottom");
180 * @param $streetAddress
182 function _testAddLocation($streetAddress) {
183 // Wait for Location tab form to load
184 $this->waitForPageToLoad($this->getTimeoutMsec());
185 $this->waitForElementPresent("_qf_Location_upload-bottom");
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");
195 $this->click("_qf_Location_upload-bottom");
197 // Wait for "saved" status msg
198 $this->waitForElementPresent("_qf_Location_upload-bottom");
199 $this->waitForTextPresent("'Event Location' information has been saved.");
203 * @param bool $discount
204 * @param bool $priceSet
205 * @param string $processorName
207 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro") {
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']");
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");
223 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
227 // enter early bird discounts TBD
230 $this->click("_qf_Fee_upload-bottom");
232 // Wait for "saved" status msg
233 $this->waitForElementPresent("_qf_Fee_upload-bottom");
234 $this->waitForTextPresent("'Fees' information has been saved.");
238 * @param $registerIntro
239 * @param bool $multipleRegistrations
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");
246 $this->check("is_online_registration");
248 $this->assertChecked("is_online_registration");
249 if ($multipleRegistrations) {
250 $this->check("is_multiple_registrations");
251 $this->assertChecked("is_multiple_registrations");
254 $this->click('intro_text-plain');
255 $this->fillRichTextField("intro_text", $registerIntro);
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");
262 $this->click("_qf_Registration_upload-bottom");
263 $this->waitForElementPresent("_qf_Registration_upload-bottom");
264 $this->waitForTextPresent("'Online Registration' information has been saved.");
274 * @param int $numberRegistrations
275 * @param $campaignType
276 * @param bool $anonymous
278 function _testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, $numberRegistrations = 1, $campaignType, $anonymous = TRUE) {
279 $hash = substr(sha1(rand()), 0, 7);
280 $contributionAmount = 600;
282 // registering online
284 $this->webtestLogout();
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";
292 $registerUrl = "civicrm/event/register?id={$pageId}&reset=1";
293 $this->open($this->sboxPath
. $registerUrl);
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");
312 $this->click("_qf_Register_upload-bottom");
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");
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);
333 //pcp creation via different user
334 $this->openCiviPage('contribute/campaign', "action=add&reset=1&pageId={$pageId}&component=event", "_qf_PCPAccount_next-bottom");
336 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
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");
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());
355 //login to check contribution
357 // Log in using webtestLogin() method
358 $this->webtestLogin();
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']");
368 $this->waitForPageToLoad($this->getTimeoutMsec());
370 $this->webtestLogout();
372 $this->open($this->sboxPath
. $pcpUrl);
373 $this->waitForElementPresent("xpath=//div[@class='pcp-donate']/a");
374 $this->click("xpath=//div[@class='pcp-donate']/a");
376 if ($campaignType == 'contribute') {
377 $this->waitForElementPresent("_qf_Main_upload-bottom");
378 $emailElement = "email-5";
380 elseif ($campaignType == 'event') {
381 $this->waitForElementPresent('_qf_Register_upload-bottom');
382 $emailElement = "email-Primary";
385 if ($campaignType == 'contribute') {
386 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", "$contributionAmount");
389 elseif ($campaignType == 'event') {
390 $contributionAmount = '250.00';
393 $firstNameDonar = 'Andrew' . substr(sha1(rand()), 0, 7);
394 $lastNameDonar = 'Roger' . substr(sha1(rand()), 0, 7);
395 $middleNameDonar = 'Nicholas' . substr(sha1(rand()), 0, 7);
397 if ($this->isElementPresent("first_name")) {
398 $this->type('first_name', $firstNameDonar);
401 if ($this->isElementPresent("last_name")) {
402 $this->type('last_name', $lastNameDonar);
404 $this->type("{$emailElement}", $firstNameDonar . "@example.com");
405 $this->webtestAddCreditCardDetails();
406 $this->webtestAddBillingDetails($firstNameDonar, $middleNameDonar, $lastNameDonar);
408 if ($campaignType == 'contribute') {
409 $this->click("_qf_Main_upload-bottom");
411 elseif ($campaignType == 'event') {
412 $this->click('_qf_Register_upload-bottom');
415 $this->waitForPageToLoad($this->getTimeoutMsec());
416 $this->waitForElementPresent("_qf_Confirm_next-bottom");
417 $this->click("_qf_Confirm_next-bottom");
419 if ($campaignType == 'contribute') {
420 $this->waitForTextPresent("Your transaction has been processed successfully");
422 elseif ($campaignType == 'event') {
423 $this->waitForTextPresent("Thank You for Registering");
426 //login to check contribution
427 $this->webtestLogin();
429 if ($campaignType == 'event') {
430 $this->_testParticipantSearchEventName($eventTitle, $lastNameDonar, $firstNameDonar, $firstName, $lastName, $contributionAmount);
432 elseif ($campaignType == 'contribute') {
433 $this->_testSearchTest($firstNameDonar, $lastNameDonar, $firstName, $lastName, $contributionAmount);
438 * @param $campaignType
439 * @param $contributionPageId
443 function _testEventPcpAdd($campaignType, $contributionPageId) {
444 $hash = substr(sha1(rand()), 0, 7);
445 $isPcpApprovalNeeded = TRUE;
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');
453 $this->select('target_entity_type', "value={$campaignType}");
455 if ($campaignType == 'contribute' && !empty($contributionPageId)) {
457 $this->select('target_entity_id', "value={$contributionPageId}");
461 if (!$isPcpApprovalNeeded) {
463 $this->click('is_approval_needed');
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");
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);
476 // parse URL to grab the contribution page id
477 return $this->urlArg('id');
482 * @param $lastNameDonar
483 * @param $firstNameDonar
484 * @param $firstNameCreator
485 * @param $lastNameCreator
488 function _testParticipantSearchEventName($eventName, $lastNameDonar, $firstNameDonar, $firstNameCreator, $lastNameCreator, $amount) {
489 $sortName = $lastNameDonar . ', ' . $firstNameDonar;
490 $this->openCiviPage("event/search", "reset=1");
492 $this->select2("event_id", $eventName);
494 $this->click("_qf_Search_refresh");
495 $this->waitForPageToLoad($this->getTimeoutMsec());
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');
501 $this->webtestVerifyTabularData(
503 'From' => "{$firstNameDonar} {$lastNameDonar}",
504 'Total Amount' => $amount,
505 'Contribution Status' => 'Completed',
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__
);
515 * @param $pcpCreatorFirstName
516 * @param $pcpCreatorLastName
519 function _testSearchTest($firstName, $lastName, $pcpCreatorFirstName, $pcpCreatorLastName, $amount) {
520 $sortName = "$pcpCreatorLastName, $pcpCreatorFirstName";
521 $displayName = "$firstName $lastName";
523 // visit contact search page
524 $this->openCiviPage("contact/search", "reset=1");
526 // fill name as first_name
527 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $pcpCreatorFirstName);
530 $this->click("_qf_Basic_refresh");
531 $this->waitForPageToLoad($this->getTimeoutMsec());
533 $this->click("xpath=//div[@class='crm-search-results']//table/tbody//tr/td[3]/a[text()='{$sortName}']");
534 $this->waitForPageToLoad($this->getTimeoutMsec());
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());
541 $this->webtestVerifyTabularData(
543 'From' => "{$firstName} {$lastName}",
544 'Net Amount' => $amount,
545 'Contribution Status' => 'Completed',
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__
);