3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 $this->markTestSkipped('Skipping for now as it works fine locally.');
40 //give permissions to anonymous user
42 'edit-1-profile-listings-and-forms',
43 'edit-1-access-all-custom-data',
44 'edit-1-register-for-events',
45 'edit-1-make-online-contributions',
47 $this->changePermissions($permission);
49 // Log in as normal user
50 $this->webtestLogin();
53 $domainNameValue = 'civicrm organization ';
54 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
55 $lastName = 'An' . substr(sha1(rand()), 0, 7);
56 $middleName = 'Mid' . substr(sha1(rand()), 0, 7);
57 $email = substr(sha1(rand()), 0, 7) . '@example.org';
58 $this->openCiviPage("admin/domain", "action=update&reset=1", '_qf_Domain_cancel-bottom');
59 $this->type('name', $domainNameValue);
60 $this->type('email_name', $firstName);
61 $this->type('email_address', $email);
63 $this->click('_qf_Domain_next_view-bottom');
64 $this->waitForPageToLoad($this->getTimeoutMsec());
66 // a random 7-char string and an even number to make this pass unique
67 $conHash = substr(sha1(rand()), 0, 7);
68 $conRand = $contributionAmount = 1000;
69 $contributionPageTitle = 'Contribution page for pcp' . $conHash;
70 $conProcessorType = 'Dummy';
71 $conAmountSection = TRUE;
75 $conRecurring = FALSE;
76 $conMemberships = FALSE;
77 $conMemPriceSetId = NULL;
79 $conProfilePreId = NULL;
80 $conProfilePostId = NULL;
84 $conIsAprovalNeeded = TRUE;
86 // Use default payment processor
87 $processorName = 'Test Processor';
89 //create contribution page for event pcp with campaign type as contribution
90 $contributionPageId = $this->webtestAddContributionPage($conHash,
92 $contributionPageTitle,
93 array($processorName => $conProcessorType),
111 //event add for contribute campaign type
112 $campaignType = 'contribute';
113 $this->_testAddEventForPCP($processorName, $campaignType, $contributionPageId, $firstName, $lastName, $middleName, $email);
115 //event add for contribute campaign type
116 $campaignType = 'event';
117 $firstName = 'Pa' . substr(sha1(rand()), 0, 4);
118 $lastName = 'Cn' . substr(sha1(rand()), 0, 7);
119 $middleName = 'PCid' . substr(sha1(rand()), 0, 7);
120 $email = substr(sha1(rand()), 0, 7) . '@example.org';
121 $this->_testAddEventForPCP($processorName, $campaignType, NULL, $firstName, $lastName, $middleName, $email);
125 * @param string $processorName
126 * @param $campaignType
127 * @param int $contributionPageId
128 * @param string $firstName
129 * @param string $lastName
130 * @param string $middleName
133 public function _testAddEventForPCP($processorName, $campaignType, $contributionPageId = NULL, $firstName, $lastName, $middleName, $email) {
135 $this->openCiviPage("event/add", "reset=1&action=add");
137 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
138 $eventDescription = "Here is a description for this conference.";
139 $this->_testAddEventInfo($eventTitle, $eventDescription);
141 $streetAddress = "100 Main Street";
142 $this->_testAddLocation($streetAddress);
144 $this->_testAddFees(FALSE, FALSE, $processorName);
146 // intro text for registration page
147 $registerIntro = "Fill in all the fields below and click Continue.";
148 $multipleRegistrations = TRUE;
149 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
151 $pageId = $this->_testEventPcpAdd($campaignType, $contributionPageId);
152 $this->_testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, '', $campaignType, TRUE);
157 * @param $eventDescription
159 public function _testAddEventInfo($eventTitle, $eventDescription) {
160 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
162 $this->select("event_type_id", "value=1");
164 // Attendee role s/b selected now.
165 $this->select("default_role_id", "value=1");
167 // Enter Event Title, Summary and Description
168 $this->type("title", $eventTitle);
169 $this->type("summary", "This is a great conference. Sign up now!");
171 // Type description in ckEditor (fieldname, text to type, editor)
172 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
174 // Choose Start and End dates.
175 // Using helper webtestFillDate function.
176 $this->webtestFillDateTime("start_date", "+1 week");
177 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
179 $this->type("max_participants", "50");
180 $this->click("is_map");
181 $this->click("_qf_EventInfo_upload-bottom");
185 * @param $streetAddress
187 public function _testAddLocation($streetAddress) {
188 // Wait for Location tab form to load
189 $this->waitForPageToLoad($this->getTimeoutMsec());
190 $this->waitForElementPresent("_qf_Location_upload-bottom");
192 // Fill in address fields
193 $streetAddress = "100 Main Street";
194 $this->type("address_1_street_address", $streetAddress);
195 $this->type("address_1_city", "San Francisco");
196 $this->type("address_1_postal_code", "94117");
197 $this->select("address_1_state_province_id", "value=1004");
198 $this->type("email_1_email", "info@civicrm.org");
200 $this->click("_qf_Location_upload-bottom");
202 // Wait for "saved" status msg
203 $this->waitForElementPresent("_qf_Location_upload-bottom");
204 $this->waitForTextPresent("'Event Location' information has been saved.");
208 * @param bool $discount
209 * @param bool $priceSet
210 * @param string $processorName
212 public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro") {
214 $this->click("link=Fees");
215 $this->waitForElementPresent("_qf_Fee_upload-bottom");
216 $this->click("CIVICRM_QFID_1_is_monetary");
217 $this->select2('payment_processor', $processorName, TRUE);
222 $this->select("financial_type_id", "label=Donation");
223 $this->type("label_1", "Member");
224 $this->type("value_1", "250.00");
225 $this->type("label_2", "Non-member");
226 $this->type("value_2", "325.00");
228 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
232 // enter early bird discounts TBD
235 $this->click("_qf_Fee_upload-bottom");
237 // Wait for "saved" status msg
238 $this->waitForElementPresent("_qf_Fee_upload-bottom");
239 $this->waitForTextPresent("'Fees' information has been saved.");
243 * @param $registerIntro
244 * @param bool $multipleRegistrations
246 public function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
247 // Go to Online Registration tab
248 $this->click("link=Online Registration");
249 $this->waitForElementPresent("_qf_Registration_upload-bottom");
251 $this->check("is_online_registration");
253 $this->assertChecked("is_online_registration");
254 if ($multipleRegistrations) {
255 $this->check("is_multiple_registrations");
256 $this->assertChecked("is_multiple_registrations");
259 $this->click('intro_text');
260 $this->fillRichTextField('intro_text', $registerIntro, 'CKEditor', TRUE);
262 // enable confirmation email
263 $this->click("CIVICRM_QFID_1_is_email_confirm");
264 $this->type("confirm_from_name", "Jane Doe");
265 $this->type("confirm_from_email", "jane.doe@example.org");
267 $this->click("_qf_Registration_upload-bottom");
268 $this->waitForElementPresent("_qf_Registration_upload-bottom");
269 $this->waitForTextPresent("'Online Registration' information has been saved.");
275 * @param string $firstName
276 * @param string $lastName
277 * @param string $middleName
279 * @param int $numberRegistrations
280 * @param $campaignType
281 * @param bool $anonymous
283 public function _testOnlineRegistration($eventTitle, $pageId, $firstName, $lastName, $middleName, $email, $numberRegistrations = 1, $campaignType, $anonymous = TRUE) {
284 $hash = substr(sha1(rand()), 0, 7);
285 $contributionAmount = 600;
287 // registering online
289 $this->webtestLogout();
292 //participant registeration
293 $firstNameParticipants = 'Jane' . substr(sha1(rand()), 0, 7);
294 $lastNameParticipants = 'Smith' . substr(sha1(rand()), 0, 7);
295 $emailParticipants = 'jane' . substr(sha1(rand()), 0, 7) . "@example.org";
297 $registerUrl = "civicrm/event/register?id={$pageId}&reset=1";
298 $this->open($this->sboxPath
. $registerUrl);
300 $this->type("first_name", "{$firstNameParticipants}");
301 $this->type("last_name", "{$lastNameParticipants}");
302 $this->select("additional_participants", "value=" . $numberRegistrations);
303 $this->type("email-Primary", $emailParticipants);
304 $this->select("credit_card_type", "value=Visa");
305 $this->type("credit_card_number", "4111111111111111");
306 $this->type("cvv2", "000");
307 $this->select("credit_card_exp_date[M]", "value=1");
308 $this->select("credit_card_exp_date[Y]", "value=2020");
309 $this->type("billing_first_name", "{$firstNameParticipants}");
310 $this->type("billing_last_name", "{$lastNameParticipants}");
311 $this->type("billing_street_address-5", "15 Main St.");
312 $this->type(" billing_city-5", "San Jose");
313 $this->select("billing_country_id-5", "value=1228");
314 $this->select("billing_state_province_id-5", "value=1004");
315 $this->type("billing_postal_code-5", "94129");
317 $this->click("_qf_Register_upload-bottom");
319 if ($numberRegistrations > 1) {
320 for ($i = 1; $i <= $numberRegistrations; $i++
) {
321 $this->waitForPageToLoad($this->getTimeoutMsec());
322 // Look for Skip button
323 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
324 $this->type("email-Primary", "{$firstName}" . substr(sha1(rand()), 0, 7) . "@example.org");
325 $this->click("_qf_Participant_{$i}_next");
329 $this->waitForPageToLoad($this->getTimeoutMsec());
330 $this->waitForElementPresent("_qf_Confirm_next-bottom");
331 $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information");
332 $this->assertStringsPresent($confirmStrings);
333 $this->click("_qf_Confirm_next-bottom");
334 $this->waitForPageToLoad($this->getTimeoutMsec());
335 $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date");
336 $this->assertStringsPresent($thankStrings);
338 //pcp creation via different user
339 $this->openCiviPage('contribute/campaign', "action=add&reset=1&pageId={$pageId}&component=event", "_qf_PCPAccount_next-bottom");
341 $cmsUserName = 'CmsUser' . substr(sha1(rand()), 0, 7);
343 $this->type("cms_name", $cmsUserName);
344 $this->click("checkavailability");
345 $this->waitForTextPresent('This username is currently available');
346 $this->type("first_name", $firstName);
347 $this->type("last_name", $lastName);
348 $this->type("email-Primary", $email);
349 $this->click("_qf_PCPAccount_next-bottom");
350 $this->waitForElementPresent("_qf_Campaign_upload-bottom");
352 $pcpTitle = 'PCPTitle' . substr(sha1(rand()), 0, 7);
353 $this->type("pcp_title", $pcpTitle);
354 $this->type("pcp_intro_text", "Welcome Text $hash");
355 $this->type("goal_amount", $contributionAmount);
356 $this->click("_qf_Campaign_upload-bottom");
357 $this->waitForPageToLoad($this->getTimeoutMsec());
360 //login to check contribution
362 // Log in using webtestLogin() method
363 $this->webtestLogin();
365 $this->openCiviPage('admin/pcp', 'reset=1&page_type=event', "_qf_PCP_refresh");
366 $this->select('status_id', 'value=1');
367 $this->click("_qf_PCP_refresh");
368 $this->waitForElementPresent("_qf_PCP_refresh");
369 $id = explode('id=', $this->getAttribute("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody//tr/td/a[text()='$pcpTitle']@href"));
370 $pcpUrl = "civicrm/pcp/info?reset=1&id=$id[1]";
371 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td/a[text()='$pcpTitle']/../../td[7]/span[1]/a[2][text()='Approve']");
373 $this->waitForPageToLoad($this->getTimeoutMsec());
375 $this->webtestLogout();
377 $this->open($this->sboxPath
. $pcpUrl);
378 $this->waitForElementPresent("xpath=//div[@class='pcp-donate']/a");
379 $this->click("xpath=//div[@class='pcp-donate']/a");
381 if ($campaignType == 'contribute') {
382 $this->waitForElementPresent("_qf_Main_upload-bottom");
383 $emailElement = "email-5";
385 elseif ($campaignType == 'event') {
386 $this->waitForElementPresent('_qf_Register_upload-bottom');
387 $emailElement = "email-Primary";
390 if ($campaignType == 'contribute') {
391 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", "$contributionAmount");
394 elseif ($campaignType == 'event') {
395 $contributionAmount = '250.00';
398 $firstNameDonar = 'Andrew' . substr(sha1(rand()), 0, 7);
399 $lastNameDonar = 'Roger' . substr(sha1(rand()), 0, 7);
400 $middleNameDonar = 'Nicholas' . substr(sha1(rand()), 0, 7);
402 if ($this->isElementPresent("first_name")) {
403 $this->type('first_name', $firstNameDonar);
406 if ($this->isElementPresent("last_name")) {
407 $this->type('last_name', $lastNameDonar);
409 $this->type("{$emailElement}", $firstNameDonar . "@example.com");
410 $this->webtestAddCreditCardDetails();
411 $this->webtestAddBillingDetails($firstNameDonar, $middleNameDonar, $lastNameDonar);
413 if ($campaignType == 'contribute') {
414 $this->click("_qf_Main_upload-bottom");
416 elseif ($campaignType == 'event') {
417 $this->click('_qf_Register_upload-bottom');
420 $this->waitForPageToLoad($this->getTimeoutMsec());
421 $this->waitForElementPresent("_qf_Confirm_next-bottom");
422 $this->click("_qf_Confirm_next-bottom");
424 if ($campaignType == 'contribute') {
425 $this->waitForTextPresent("Your transaction has been processed successfully");
427 elseif ($campaignType == 'event') {
428 $this->waitForTextPresent("Thank You for Registering");
431 //login to check contribution
432 $this->webtestLogin();
434 if ($campaignType == 'event') {
435 $this->_testParticipantSearchEventName($eventTitle, $lastNameDonar, $firstNameDonar, $firstName, $lastName, $contributionAmount);
437 elseif ($campaignType == 'contribute') {
438 $this->_testSearchTest($firstNameDonar, $lastNameDonar, $firstName, $lastName, $contributionAmount);
443 * @param $campaignType
444 * @param int $contributionPageId
448 public function _testEventPcpAdd($campaignType, $contributionPageId) {
449 $hash = substr(sha1(rand()), 0, 7);
450 $isPcpApprovalNeeded = TRUE;
452 // fill in step 9 (Enable Personal Campaign Pages)
453 $this->click('link=Personal Campaigns');
454 $this->waitForElementPresent('pcp_active');
455 $this->click('pcp_active');
456 $this->waitForElementPresent('_qf_Event_upload-bottom');
458 $this->select('target_entity_type', "value={$campaignType}");
460 if ($campaignType == 'contribute' && !empty($contributionPageId)) {
462 $this->select('target_entity_id', "value={$contributionPageId}");
466 if (!$isPcpApprovalNeeded) {
468 $this->click('is_approval_needed');
471 $this->type('notify_email', "$hash@example.name");
472 $this->select('supporter_profile_id', 'value=2');
473 $this->type('tellfriend_limit', 7);
474 $this->type('link_text', "'Create Personal Campaign Page' link text $hash");
476 $this->click('_qf_Event_upload-bottom');
477 $this->waitForElementPresent('_qf_Event_upload-bottom');
478 $text = "'Personal Campaigns' information has been saved.";
479 $this->waitForText('crm-notification-container', $text);
481 // parse URL to grab the contribution page id
482 return $this->urlArg('id');
486 * @param string $eventName
487 * @param string $lastNameDonar
488 * @param string $firstNameDonar
489 * @param string $firstNameCreator
490 * @param string $lastNameCreator
493 public function _testParticipantSearchEventName($eventName, $lastNameDonar, $firstNameDonar, $firstNameCreator, $lastNameCreator, $amount) {
494 $sortName = $lastNameDonar . ', ' . $firstNameDonar;
495 $this->openCiviPage("event/search", "reset=1");
497 $this->select2("event_id", $eventName);
499 $this->clickLink("_qf_Search_refresh");
501 $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);
502 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']", "_qf_ParticipantView_cancel-bottom", FALSE);
504 $this->webtestVerifyTabularData(
506 'From' => "{$firstNameDonar} {$lastNameDonar}",
507 'Total Amount' => $amount,
508 'Contribution Status' => 'Completed',
511 $softCreditor = "{$firstNameCreator} {$lastNameCreator}";
512 $this->verifyText("xpath=//div[@id='PCPView']/div[2]//table[@class='crm-info-panel']/tbody/tr[2]/td[2]", preg_quote($softCreditor));
516 * @param string $firstName
518 * @param $pcpCreatorFirstName
519 * @param $pcpCreatorLastName
522 public function _testSearchTest($firstName, $lastName, $pcpCreatorFirstName, $pcpCreatorLastName, $amount) {
523 $sortName = "$pcpCreatorLastName, $pcpCreatorFirstName";
524 $displayName = "$firstName $lastName";
526 // visit contact search page
527 $this->openCiviPage("contact/search", "reset=1");
529 // fill name as first_name
530 $this->type("css=.crm-basic-criteria-form-block input#sort_name", $pcpCreatorFirstName);
533 $this->clickLink("_qf_Basic_refresh");
535 $this->click("xpath=//div[@class='crm-search-results']//table/tbody//tr/td[3]/a[text()='{$sortName}']");
536 $this->waitForPageToLoad($this->getTimeoutMsec());
538 $this->click("css=li#tab_contribute a");
539 $this->waitForElementPresent("xpath=//form[@id='Search']/div[@class='view-content']/table[2]/tbody/tr[@id='rowid']/td/a[text()='$displayName']");
540 $this->click("xpath=//form[@id='Search']/div[@class='view-content']/table[2]/tbody/tr[@id='rowid']/td[8]/a[text()='View']");
541 $this->waitForPageToLoad($this->getTimeoutMsec());
542 // as per changes made in CRM-15407
544 $amount = $amount - $feeAmount;
546 $this->webtestVerifyTabularData(
548 'From' => "{$firstName} {$lastName}",
549 'Net Amount' => $amount,
550 'Contribution Status' => 'Completed',
553 $softCreditor = "{$pcpCreatorFirstName} {$pcpCreatorLastName}";
554 $this->verifyText("xpath=//div[@id='PCPView']/div[2]//table[@class='crm-info-panel']/tbody/tr[2]/td[2]", preg_quote($softCreditor));