3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public function testPCPAdd() {
39 //give permissions to anonymous user
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'
46 $this->changePermissions($permission);
48 // Log in as normal user
49 $this->webtestLogin();
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);
62 $this->click('_qf_Domain_next_view-bottom');
63 $this->waitForPageToLoad($this->getTimeoutMsec());
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;
74 $conRecurring = FALSE;
75 $conMemberships = FALSE;
76 $conMemPriceSetId = NULL;
78 $conProfilePreId = NULL;
79 $conProfilePostId = NULL;
83 $conIsAprovalNeeded = TRUE;
85 // Use default payment processor
86 $processorName = 'Test Processor';
88 //create contribution page for event pcp with campaign type as contribution
89 $contributionPageId = $this->webtestAddContributionPage($conHash,
91 $contributionPageTitle,
92 array($processorName => $conProcessorType),
110 //event add for contribute campaign type
111 $campaignType = 'contribute';
112 $this->_testAddEventForPCP($processorName, $campaignType, $contributionPageId, $firstName, $lastName, $middleName, $email);
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);
124 * @param string $processorName
125 * @param $campaignType
126 * @param int $contributionPageId
127 * @param string $firstName
128 * @param string $lastName
129 * @param string $middleName
132 public function _testAddEventForPCP($processorName, $campaignType, $contributionPageId = NULL, $firstName, $lastName, $middleName, $email) {
134 $this->openCiviPage("event/add", "reset=1&action=add");
136 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
137 $eventDescription = "Here is a description for this conference.";
138 $this->_testAddEventInfo($eventTitle, $eventDescription);
140 $streetAddress = "100 Main Street";
141 $this->_testAddLocation($streetAddress);
143 $this->_testAddFees(FALSE, FALSE, $processorName);
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);
150 $pageId = $this->_testEventPcpAdd($campaignType, $contributionPageId);
151 $this->_testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, '', $campaignType, TRUE);
156 * @param $eventDescription
158 public function _testAddEventInfo($eventTitle, $eventDescription) {
159 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
161 $this->select("event_type_id", "value=1");
163 // Attendee role s/b selected now.
164 $this->select("default_role_id", "value=1");
166 // Enter Event Title, Summary and Description
167 $this->type("title", $eventTitle);
168 $this->type("summary", "This is a great conference. Sign up now!");
170 // Type description in ckEditor (fieldname, text to type, editor)
171 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
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 ");
178 $this->type("max_participants", "50");
179 $this->click("is_map");
180 $this->click("_qf_EventInfo_upload-bottom");
184 * @param $streetAddress
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");
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");
199 $this->click("_qf_Location_upload-bottom");
201 // Wait for "saved" status msg
202 $this->waitForElementPresent("_qf_Location_upload-bottom");
203 $this->waitForTextPresent("'Event Location' information has been saved.");
207 * @param bool $discount
208 * @param bool $priceSet
209 * @param string $processorName
211 public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro") {
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']");
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");
227 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
231 // enter early bird discounts TBD
234 $this->click("_qf_Fee_upload-bottom");
236 // Wait for "saved" status msg
237 $this->waitForElementPresent("_qf_Fee_upload-bottom");
238 $this->waitForTextPresent("'Fees' information has been saved.");
242 * @param $registerIntro
243 * @param bool $multipleRegistrations
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");
250 $this->check("is_online_registration");
252 $this->assertChecked("is_online_registration");
253 if ($multipleRegistrations) {
254 $this->check("is_multiple_registrations");
255 $this->assertChecked("is_multiple_registrations");
258 $this->click('intro_text-plain');
259 $this->fillRichTextField("intro_text", $registerIntro);
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");
266 $this->click("_qf_Registration_upload-bottom");
267 $this->waitForElementPresent("_qf_Registration_upload-bottom");
268 $this->waitForTextPresent("'Online Registration' information has been saved.");
274 * @param string $firstName
275 * @param string $lastName
276 * @param string $middleName
278 * @param int $numberRegistrations
279 * @param $campaignType
280 * @param bool $anonymous
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;
286 // registering online
288 $this->webtestLogout();
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";
296 $registerUrl = "civicrm/event/register?id={$pageId}&reset=1";
297 $this->open($this->sboxPath
. $registerUrl);
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");
316 $this->click("_qf_Register_upload-bottom");
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");
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);
337 //pcp creation via different user
338 $this->openCiviPage('contribute/campaign', "action=add&reset=1&pageId={$pageId}&component=event", "_qf_PCPAccount_next-bottom");
340 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
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");
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());
359 //login to check contribution
361 // Log in using webtestLogin() method
362 $this->webtestLogin();
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']");
372 $this->waitForPageToLoad($this->getTimeoutMsec());
374 $this->webtestLogout();
376 $this->open($this->sboxPath
. $pcpUrl);
377 $this->waitForElementPresent("xpath=//div[@class='pcp-donate']/a");
378 $this->click("xpath=//div[@class='pcp-donate']/a");
380 if ($campaignType == 'contribute') {
381 $this->waitForElementPresent("_qf_Main_upload-bottom");
382 $emailElement = "email-5";
384 elseif ($campaignType == 'event') {
385 $this->waitForElementPresent('_qf_Register_upload-bottom');
386 $emailElement = "email-Primary";
389 if ($campaignType == 'contribute') {
390 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", "$contributionAmount");
393 elseif ($campaignType == 'event') {
394 $contributionAmount = '250.00';
397 $firstNameDonar = 'Andrew' . substr(sha1(rand()), 0, 7);
398 $lastNameDonar = 'Roger' . substr(sha1(rand()), 0, 7);
399 $middleNameDonar = 'Nicholas' . substr(sha1(rand()), 0, 7);
401 if ($this->isElementPresent("first_name")) {
402 $this->type('first_name', $firstNameDonar);
405 if ($this->isElementPresent("last_name")) {
406 $this->type('last_name', $lastNameDonar);
408 $this->type("{$emailElement}", $firstNameDonar . "@example.com");
409 $this->webtestAddCreditCardDetails();
410 $this->webtestAddBillingDetails($firstNameDonar, $middleNameDonar, $lastNameDonar);
412 if ($campaignType == 'contribute') {
413 $this->click("_qf_Main_upload-bottom");
415 elseif ($campaignType == 'event') {
416 $this->click('_qf_Register_upload-bottom');
419 $this->waitForPageToLoad($this->getTimeoutMsec());
420 $this->waitForElementPresent("_qf_Confirm_next-bottom");
421 $this->click("_qf_Confirm_next-bottom");
423 if ($campaignType == 'contribute') {
424 $this->waitForTextPresent("Your transaction has been processed successfully");
426 elseif ($campaignType == 'event') {
427 $this->waitForTextPresent("Thank You for Registering");
430 //login to check contribution
431 $this->webtestLogin();
433 if ($campaignType == 'event') {
434 $this->_testParticipantSearchEventName($eventTitle, $lastNameDonar, $firstNameDonar, $firstName, $lastName, $contributionAmount);
436 elseif ($campaignType == 'contribute') {
437 $this->_testSearchTest($firstNameDonar, $lastNameDonar, $firstName, $lastName, $contributionAmount);
442 * @param $campaignType
443 * @param int $contributionPageId
447 public function _testEventPcpAdd($campaignType, $contributionPageId) {
448 $hash = substr(sha1(rand()), 0, 7);
449 $isPcpApprovalNeeded = TRUE;
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');
457 $this->select('target_entity_type', "value={$campaignType}");
459 if ($campaignType == 'contribute' && !empty($contributionPageId)) {
461 $this->select('target_entity_id', "value={$contributionPageId}");
465 if (!$isPcpApprovalNeeded) {
467 $this->click('is_approval_needed');
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");
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);
480 // parse URL to grab the contribution page id
481 return $this->urlArg('id');
485 * @param string $eventName
486 * @param string $lastNameDonar
487 * @param string $firstNameDonar
488 * @param string $firstNameCreator
489 * @param string $lastNameCreator
492 public function _testParticipantSearchEventName($eventName, $lastNameDonar, $firstNameDonar, $firstNameCreator, $lastNameCreator, $amount) {
493 $sortName = $lastNameDonar . ', ' . $firstNameDonar;
494 $this->openCiviPage("event/search", "reset=1");
496 $this->select2("event_id", $eventName);
498 $this->clickLink("_qf_Search_refresh");
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);
503 $this->webtestVerifyTabularData(
505 'From' => "{$firstNameDonar} {$lastNameDonar}",
506 'Total Amount' => $amount,
507 'Contribution Status' => 'Completed',
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), 'In line ' . __LINE__
);
515 * @param string $firstName
517 * @param $pcpCreatorFirstName
518 * @param $pcpCreatorLastName
521 public function _testSearchTest($firstName, $lastName, $pcpCreatorFirstName, $pcpCreatorLastName, $amount) {
522 $sortName = "$pcpCreatorLastName, $pcpCreatorFirstName";
523 $displayName = "$firstName $lastName";
525 // visit contact search page
526 $this->openCiviPage("contact/search", "reset=1");
528 // fill name as first_name
529 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $pcpCreatorFirstName);
532 $this->clickLink("_qf_Basic_refresh");
534 $this->click("xpath=//div[@class='crm-search-results']//table/tbody//tr/td[3]/a[text()='{$sortName}']");
535 $this->waitForPageToLoad($this->getTimeoutMsec());
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
543 $amount = $amount - $feeAmount;
545 $this->webtestVerifyTabularData(
547 'From' => "{$firstName} {$lastName}",
548 'Net Amount' => $amount,
549 'Contribution Status' => 'Completed',
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), 'In line ' . __LINE__
);