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_Contribute_ContributionPageAddTest
32 class WebTest_Contribute_ContributionPageAddTest
extends CiviSeleniumTestCase
{
33 public function testContributionPageAdd() {
34 // open browser, login
35 $this->webtestLogin();
37 // a random 7-char string and an even number to make this pass unique
38 $hash = substr(sha1(rand()), 0, 7);
39 $rand = 2 * rand(2, 50);
40 $pageTitle = 'Donate Online ' . $hash;
41 // create contribution page with randomized title and default params
42 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'), TRUE, TRUE, 'required');
44 $this->openCiviPage("admin/contribute", "reset=1");
46 // search for the new contrib page and go to its test version
47 $this->type('title', $pageTitle);
48 $this->click('_qf_SearchContribution_refresh');
49 $this->waitForPageToLoad($this->getTimeoutMsec());
51 // select testdrive mode
52 $this->isTextPresent($pageTitle);
53 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
55 // verify whatever’s possible to verify
56 // FIXME: ideally should be expanded
58 "Title - New Membership $hash",
59 "This is introductory message for $pageTitle",
61 "Label $hash - $ $rand.00",
62 "Pay later label $hash",
63 'Organization Details',
65 'I pledge to contribute this amount every',
69 foreach ($texts as $text) {
70 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
71 $this->waitForAjaxContent();
74 // Disable and re-enable Other Amounts (verify fix for CRM-15021)
75 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_next-bottom');
76 $this->click("is_allow_other_amount");
77 $this->clickLink("_qf_Amount_upload_done-bottom");
78 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
79 $this->assertFalse($this->isTextPresent('Other Amount'), 'Other Amount present but not expected.');
80 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_next-bottom');
81 $this->click("is_allow_other_amount");
82 $this->clickLink("_qf_Amount_upload_done-bottom");
83 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
84 $this->assertTrue($this->isTextPresent('Other Amount'), 'Other Amount not present but expected.');
85 $this->isElementPresent("xpath=//div[@class='content other_amount-content']/input");
89 * CRM-12510 Test copy contribution page
91 public function testContributionPageCopy() {
92 // open browser, login
93 $this->webtestLogin();
95 // a random 7-char string and an even number to make this pass unique
96 $hash = substr(sha1(rand()), 0, 7);
97 $rand = 2 * rand(2, 50);
98 $pageTitle = 'Donate Online ' . $hash;
99 // create contribution page with randomized title and default params
100 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'), TRUE, TRUE, 'required');
102 $this->openCiviPage("admin/contribute", "reset=1");
104 // search for the new contrib page and go to its test version
105 $this->type('title', $pageTitle);
106 $this->click('_qf_SearchContribution_refresh');
107 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->isTextPresent($pageTitle);
111 // Call URL to make a copy of the page
112 $this->openCiviPage("admin/contribute", "action=copy&gid=$pageId");
114 // search for the new copy page and go to its test version
115 $this->type('title', 'Copy of ' . $pageTitle);
116 $this->click('_qf_SearchContribution_refresh');
117 $this->waitForPageToLoad($this->getTimeoutMsec());
119 $this->isTextPresent('Copy of ' . $pageTitle);
120 // get page id of the copy
121 // $copyPageId = $this->getText("xpath=//div[@id='configure_contribution_page']/tr[@id='row_4']/td[2]");
122 $copyPageId = $this->getText("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody/tr[1]/td[2]");
123 // select testdrive mode
124 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$copyPageId", '_qf_Main_upload-bottom');
126 // verify whatever’s possible to verify
127 // FIXME: ideally should be expanded
129 "Title - New Membership $hash",
130 "This is introductory message for $pageTitle",
132 "Label $hash - $ $rand.00",
133 "Pay later label $hash",
134 'Organization Details',
136 'I pledge to contribute this amount every',
140 foreach ($texts as $text) {
141 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
142 $this->waitForAjaxContent();
149 public function testContributionPageSeparatePayment() {
150 // open browser, login
151 $this->webtestLogin();
153 // a random 7-char string and an even number to make this pass unique
154 $hash = substr(sha1(rand()), 0, 7);
155 $rand = 2 * rand(2, 50);
156 $pageTitle = 'Donate Online ' . $hash;
158 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
159 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'),
160 TRUE, TRUE, 'required', TRUE, FALSE, TRUE, NULL, TRUE,
161 1, 7, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE
164 $this->openCiviPage("admin/contribute", "reset=1");
166 // search for the new contrib page and go to its test version
167 $this->type('title', $pageTitle);
168 $this->click('_qf_SearchContribution_refresh');
169 $this->waitForPageToLoad($this->getTimeoutMsec());
171 // select testdrive mode
172 $this->isTextPresent($pageTitle);
173 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
176 "Title - New Membership $hash",
177 "This is introductory message for $pageTitle",
178 "Label $hash - $ $rand.00",
179 "Pay later label $hash",
180 'Organization Details',
182 'I pledge to contribute this amount every',
186 foreach ($texts as $text) {
187 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
188 $this->waitForAjaxContent();
195 public function testContributionPageSeparatePaymentPayLater() {
196 // open browser, login
197 $this->webtestLogin();
199 // a random 7-char string and an even number to make this pass unique
200 $hash = substr(sha1(rand()), 0, 7);
201 $rand = 2 * rand(2, 50);
202 $pageTitle = 'Donate Online ' . $hash;
204 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
205 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, NULL,
206 TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, NULL, FALSE,
207 1, 0, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE
210 $this->openCiviPage("admin/contribute", "reset=1");
212 // search for the new contrib page and go to its test version
213 $this->type('title', $pageTitle);
214 $this->click('_qf_SearchContribution_refresh');
215 $this->waitForPageToLoad($this->getTimeoutMsec());
218 $this->webtestLogout();
220 //Open Live Contribution Page
221 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
223 $firstName = 'Ya' . substr(sha1(rand()), 0, 4);
224 $lastName = 'Cha' . substr(sha1(rand()), 0, 7);
226 $this->type('email-5', $firstName . '@example.com');
227 $this->type('first_name', $firstName);
228 $this->type('last_name', $lastName);
230 $this->select('state_province-1', "value=1002");
231 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
233 $this->click('_qf_Confirm_next-bottom');
234 $this->waitForPageToLoad($this->getTimeoutMsec());
236 //login to check contribution
237 $this->webtestLogin();
240 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
242 $this->type('sort_name', "$lastName $firstName");
243 $this->select('financial_type_id', "label=Member Dues");
244 $this->clickLink('_qf_Search_refresh', "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", FALSE);
245 $this->clickLink("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
247 'From' => "{$firstName} {$lastName}",
248 'Financial Type' => 'Member Dues',
249 'Total Amount' => '$ 50.00',
250 'Contribution Status' => 'Pending : Pay Later',
252 $this->webtestVerifyTabularData($expected);
253 $this->click('_qf_ContributionView_cancel-bottom');
255 //View Contribution for separate contribution
256 $this->waitForElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[10]/span//a[text()='View']");
257 // Open search criteria again
258 $this->click("xpath=id('Search')/div[2]/div/div[1]");
259 $this->waitForElementPresent("financial_type_id");
260 $this->type("sort_name", $firstName);
261 $this->select('financial_type_id', "label=Donation");
262 $this->clickLink('_qf_Search_refresh', "xpath=//table[@class='selector row-highlight']/tbody/tr/td[10]/span//a[text()='View']", FALSE);
263 $this->click("xpath=//div[@id='contributionSearch']/table[@class='selector row-highlight']/tbody/tr/td[10]/span//a[text()='View']");
264 $this->waitForAjaxContent();
266 'From' => "{$firstName} {$lastName}",
267 'Financial Type' => 'Donation',
268 'Contribution Status' => 'Pending : Pay Later',
270 $this->webtestVerifyTabularData($expected);
271 $this->click('_qf_ContributionView_cancel-bottom');
274 $this->openCiviPage("member/search", "reset=1", 'member_source');
275 $this->type('sort_name', "$lastName $firstName");
276 $this->clickLink('_qf_Search_refresh', "xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[11]/span//a[text()='View']", FALSE);
277 $this->click("xpath=//table[@class='selector row-highlight']/tbody/tr[1]/td[11]/span//a[text()='View']");
278 $this->waitForAjaxContent();
280 //View Membership Record
282 'Member' => "{$firstName} {$lastName}",
283 'Membership Type' => 'Student',
284 'Status' => 'Pending',
286 $this->webtestVerifyTabularData($expected);
287 $this->click('_qf_MembershipView_cancel-bottom');
293 public function testContributionPageAddPremiumRequiredField() {
294 // open browser, login
295 $this->webtestLogin();
297 // a random 7-char string and an even number to make this pass unique
298 $hash = substr(sha1(rand()), 0, 7);
299 $rand = 2 * rand(2, 50);
300 $pageTitle = 'Donate Online ' . $hash;
301 $processor = array('Test Processor' => 'Dummy');
303 // Create a new payment processor
304 while (list($processorName, $processorType) = each($processor)) {
305 $this->webtestAddPaymentProcessor($processorName, $processorType);
308 // go to the New Contribution Page page
309 $this->openCiviPage('admin/contribute', 'action=add&reset=1');
311 // fill in Title and Settings
312 $this->type('title', $pageTitle);
314 // to select financial type
315 $this->select('financial_type_id', "label=Donation");
317 $this->click('is_organization');
318 $this->select("xpath=//*[@class='crm-contribution-onbehalf_profile_id']//span[@class='crm-profile-selector-select']//select", 'label=On Behalf Of Organization');
319 $this->type('for_organization', "On behalf $hash");
320 // make onBehalf optional
321 $this->click('CIVICRM_QFID_1_2');
323 $this->fillRichTextField('intro_text', 'This is introductory message for ' . $pageTitle, 'CKEditor');
324 $this->fillRichTextField('footer_text', 'This is footer message for ' . $pageTitle, 'CKEditor');
326 $this->type('goal_amount', 10 * $rand);
329 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
331 // Get contribution page id
332 $pageId = $this->urlArg('id');
334 // fill in Processor, Amounts
335 if (!empty($processor)) {
337 while (list($processorName) = each($processor)) {
338 // select newly created processor
339 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
340 $this->assertTrue($this->isTextPresent($processorName));
341 $this->check($xpath);
345 // fill in labels & values in Fixed Contribution Options
346 $this->type('label_1', 'Fixed Amount 1');
347 $this->type('value_1', 1);
348 $this->type('label_2', 'Fixed Amount 2');
349 $this->type('value_2', 2);
350 $this->type('label_3', 'Fixed Amount 3');
351 $this->type('value_3', 3);
352 $this->click('CIVICRM_QFID_1_4');
353 $this->click('_qf_Amount_submit_savenext-bottom');
354 $this->waitForPageToLoad($this->getTimeoutMsec());
356 // click through to the membership view screen
357 $this->click("css=li#tab_thankyou a");
358 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
360 // fill in Receipt details
361 $this->type('thankyou_title', "Thank-you Page Title $hash");
362 $this->fillRichTextField('thankyou_text', 'This is thankyou message for ' . $pageTitle, 'CKEditor', TRUE);
363 $this->fillRichTextField('thankyou_footer', 'This is thankyou footer message for ' . $pageTitle, 'CKEditor', TRUE);
364 $this->click('is_email_receipt');
365 $this->waitForElementPresent('bcc_receipt');
366 $this->type('receipt_from_name', "Receipt From Name $hash");
367 $this->type('receipt_from_email', "$hash@example.org");
368 $this->type('receipt_text', "Receipt Message $hash");
369 $this->type('cc_receipt', "$hash@example.net");
370 $this->type('bcc_receipt', "$hash@example.com");
372 $this->click('_qf_ThankYou_next');
373 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
374 $this->waitForPageToLoad($this->getTimeoutMsec());
375 $receiptText = "'ThankYou' information has been saved.";
376 $this->assertTrue($this->isTextPresent($receiptText), 'Missing text: ' . $receiptText);
378 $this->click('link=Premiums');
379 $this->waitForElementPresent('_qf_Premium_submit_savenext-bottom');
380 $assertPremiumsCheck = FALSE;
381 if (!$this->isChecked('premiums_active')) {
382 $assertPremiumsCheck = TRUE;
384 $this->assertTrue($assertPremiumsCheck, 'Premiums Section is not unchecked by default.');
385 $this->click('_qf_Premium_submit_savenext-bottom');
386 $this->waitForPageToLoad($this->getTimeoutMsec());
387 $premiumText = "'Premium' information has been saved.";
388 // check if clicking Save & Next button
389 // Premium is saved rather than required validation error
390 // for No Thank-you Label textfield
391 $this->assertTrue($this->isTextPresent($premiumText));
393 $this->openCiviPage("admin/contribute", "reset=1");
395 // search for the new contrib page and go to its test version
396 $this->type('title', $pageTitle);
397 $this->click('_qf_SearchContribution_refresh');
398 $this->waitForPageToLoad($this->getTimeoutMsec());
399 $this->isElementPresent("xpath=//table[@class='display dataTable no-footer']/tbody/tr/td[1]/strong[text()='$pageTitle']");
400 $this->waitForElementPresent("xpath=//table[@class='display dataTable no-footer']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
401 $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
402 $this->waitForElementPresent("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']/ul[@class='panel']/li[8]/a[@title='Premiums']");
403 $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']/ul[@class='panel']/li[8]/a[@title='Premiums']");
404 $this->waitForPageToLoad($this->getTimeoutMsec());
405 $this->waitForElementPresent('premiums_active');
406 $this->waitForElementPresent('_qf_Premium_cancel-bottom');
408 // click on Premiums Section Enabled? checkbox
409 $this->click('premiums_active');
410 $this->waitForElementPresent("xpath=//div[@id='premiumSettings']");
411 $this->waitForElementPresent('premiums_nothankyou_position');
412 $this->type('premiums_intro_title', 'Premiums Intro Title');
413 $this->type('premiums_intro_text', 'Premiums Into Text');
414 $this->type('premiums_contact_email', "$hash@example.net");
416 // let No Thank-you Label text be blank
417 // so that validation error appears
418 // $this->type('premiums_nothankyou_label', );
419 $this->select('premiums_nothankyou_position', 'value=2');
421 // click on save & next button
422 $this->click('_qf_Premium_submit_savenext-bottom');
423 $this->waitForPageToLoad($this->getTimeoutMsec());
424 $premiumRequiredText = "No Thank-you Label is a required field.";
425 // check if clicking Save & Next button
426 // required validation error appears
427 // for No Thank-you Label textfield
428 $this->waitForElementPresent("xpath=//*[@id='premiumSettings']/div/div[2]/table/tbody/tr[6]/td[2]/span[1]");
429 $this->assertTrue($this->isTextPresent($premiumRequiredText));
431 // fill in value for Premiums No Thank-you Label textfield
432 $this->type('premiums_nothankyou_label', 'Premiums No Thank-you Label');
433 $this->waitForElementPresent('_qf_Premium_upload_done-bottom');
435 // click save & done button
436 $this->click('_qf_Premium_upload_done-bottom');
437 $this->waitForPageToLoad($this->getTimeoutMsec());
438 $premiumSavedText = "'Premium' information has been saved.";
439 // check if clicking Save & Done button
440 // contribution page is saved.
441 $this->assertTrue($this->isTextPresent($premiumSavedText));