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_Contribute_ContributionPageAddTest
32 class WebTest_Contribute_ContributionPageAddTest
extends CiviSeleniumTestCase
{
33 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 "$ $rand.00 Label $hash",
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);
73 // Disable and re-enable Other Amounts (verify fix for CRM-15021)
74 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_next-bottom');
75 $this->click("is_allow_other_amount");
76 $this->clickLink("_qf_Amount_upload_done-bottom");
77 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
78 $this->assertFalse($this->isTextPresent('Other Amount'), 'Other Amount present but not expected.');
79 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_next-bottom');
80 $this->click("is_allow_other_amount");
81 $this->clickLink("_qf_Amount_upload_done-bottom");
82 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
83 $this->assertTrue($this->isTextPresent('Other Amount'), 'Other Amount not present but expected.');
84 $this->isElementPresent("xpath=//div[@class='content other_amount-content']/input");
87 // CRM-12510 Test copy contribution page
88 function testContributionPageCopy() {
89 // open browser, login
90 $this->webtestLogin();
92 // a random 7-char string and an even number to make this pass unique
93 $hash = substr(sha1(rand()), 0, 7);
94 $rand = 2 * rand(2, 50);
95 $pageTitle = 'Donate Online ' . $hash;
96 // create contribution page with randomized title and default params
97 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'), TRUE, TRUE, 'required');
99 $this->openCiviPage("admin/contribute", "reset=1");
101 // search for the new contrib page and go to its test version
102 $this->type('title', $pageTitle);
103 $this->click('_qf_SearchContribution_refresh');
104 $this->waitForPageToLoad($this->getTimeoutMsec());
106 $this->isTextPresent($pageTitle);
108 // Call URL to make a copy of the page
109 $this->openCiviPage("admin/contribute", "action=copy&gid=$pageId");
111 // search for the new copy page and go to its test version
112 $this->type('title', 'Copy of ' . $pageTitle);
113 $this->click('_qf_SearchContribution_refresh');
114 $this->waitForPageToLoad($this->getTimeoutMsec());
116 $this->isTextPresent('Copy of ' . $pageTitle);
117 // get page id of the copy
118 // $copyPageId = $this->getText("xpath=//div[@id='configure_contribution_page']/tr[@id='row_4']/td[2]");
119 $copyPageId = $this->getText("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody/tr[1]/td[2]");
120 // select testdrive mode
121 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$copyPageId", '_qf_Main_upload-bottom');
123 // verify whatever’s possible to verify
124 // FIXME: ideally should be expanded
126 "Title - New Membership $hash",
127 "This is introductory message for $pageTitle",
129 "$ $rand.00 Label $hash",
130 "Pay later label $hash",
131 'Organization Details',
133 'I pledge to contribute this amount every',
137 foreach ($texts as $text) {
138 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
145 function testContributionPageSeparatePayment() {
146 // open browser, login
147 $this->webtestLogin();
149 // a random 7-char string and an even number to make this pass unique
150 $hash = substr(sha1(rand()), 0, 7);
151 $rand = 2 * rand(2, 50);
152 $pageTitle = 'Donate Online ' . $hash;
154 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
155 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'),
156 TRUE, TRUE, 'required', TRUE, FALSE, TRUE, NULL, TRUE,
157 1, 7, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE
160 $this->openCiviPage("admin/contribute", "reset=1");
162 // search for the new contrib page and go to its test version
163 $this->type('title', $pageTitle);
164 $this->click('_qf_SearchContribution_refresh');
165 $this->waitForPageToLoad($this->getTimeoutMsec());
167 // select testdrive mode
168 $this->isTextPresent($pageTitle);
169 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
172 "Title - New Membership $hash",
173 "This is introductory message for $pageTitle",
174 "$ $rand.00 Label $hash",
175 "Pay later label $hash",
176 'Organization Details',
178 'I pledge to contribute this amount every',
182 foreach ($texts as $text) {
183 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
190 function testContributionPageSeparatePaymentPayLater() {
191 // open browser, login
192 $this->webtestLogin();
194 // a random 7-char string and an even number to make this pass unique
195 $hash = substr(sha1(rand()), 0, 7);
196 $rand = 2 * rand(2, 50);
197 $pageTitle = 'Donate Online ' . $hash;
199 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
200 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, NULL,
201 TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, NULL, FALSE,
202 1, 0, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE
205 $this->openCiviPage("admin/contribute", "reset=1");
207 // search for the new contrib page and go to its test version
208 $this->type('title', $pageTitle);
209 $this->click('_qf_SearchContribution_refresh');
210 $this->waitForPageToLoad($this->getTimeoutMsec());
213 $this->webtestLogout();
215 //Open Live Contribution Page
216 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
218 $firstName = 'Ya' . substr(sha1(rand()), 0, 4);
219 $lastName = 'Cha' . substr(sha1(rand()), 0, 7);
221 $this->type('email-5', $firstName . '@example.com');
222 $this->type('first_name', $firstName);
223 $this->type('last_name', $lastName);
225 $this->select('state_province-1',"value=1002");
226 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
228 $this->click('_qf_Confirm_next-bottom');
229 $this->waitForPageToLoad($this->getTimeoutMsec());
231 //login to check contribution
232 $this->webtestLogin();
235 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
237 $this->type('sort_name', "$firstName $lastName");
238 $this->select('financial_type_id',"label=Member Dues");
239 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
240 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
242 'From' => "{$firstName} {$lastName}",
243 'Financial Type' => 'Member Dues',
244 'Total Amount' => '$ 50.00',
245 'Contribution Status' => 'Pending : Pay Later',
247 $this->webtestVerifyTabularData($expected);
248 $this->click('_qf_ContributionView_cancel-bottom');
250 //View Contribution for separate contribution
251 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
252 // Open search criteria again
253 $this->click("xpath=id('Search')/div[2]/div/div[1]");
254 $this->waitForElementPresent("financial_type_id");
255 $this->type("sort_name", $firstName);
256 $this->select('financial_type_id',"label=Donation");
257 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
259 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
261 'From' => "{$firstName} {$lastName}",
262 'Financial Type' => 'Donation',
263 'Contribution Status' => 'Pending : Pay Later',
265 $this->webtestVerifyTabularData($expected);
266 $this->click('_qf_ContributionView_cancel-bottom');
269 $this->openCiviPage("member/search", "reset=1", 'member_source');
270 $this->type('sort_name', "$firstName $lastName");
271 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", FALSE);
272 $this->clickLink("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_MembershipView_cancel-bottom', FALSE);
274 //View Membership Record
276 'Member' => "{$firstName} {$lastName}",
277 'Membership Type' => 'Student',
278 'Status' => 'Pending',
280 $this->webtestVerifyTabularData($expected);
281 $this->click('_qf_MembershipView_cancel-bottom');
287 function testContributionPageAddPremiumRequiredField() {
288 // open browser, login
289 $this->webtestLogin();
291 // a random 7-char string and an even number to make this pass unique
292 $hash = substr(sha1(rand()), 0, 7);
293 $rand = 2 * rand(2, 50);
294 $pageTitle = 'Donate Online ' . $hash;
295 $processor = array('Test Processor' => 'Dummy');
297 // Create a new payment processor
298 while (list($processorName, $processorType) = each($processor)) {
299 $this->webtestAddPaymentProcessor($processorName, $processorType);
302 // go to the New Contribution Page page
303 $this->openCiviPage('admin/contribute', 'action=add&reset=1');
305 // fill in Title and Settings
306 $this->type('title', $pageTitle);
308 // to select financial type
309 $this->select('financial_type_id', "label=Donation");
311 $this->click('is_organization');
312 $this->select("xpath=//*[@class='crm-contribution-onbehalf_profile_id']//span[@class='crm-profile-selector-select']//select", 'label=On Behalf Of Organization');
313 $this->type('for_organization', "On behalf $hash");
314 // make onBehalf optional
315 $this->click('CIVICRM_QFID_1_2');
317 $this->fillRichTextField('intro_text', 'This is introductory message for ' . $pageTitle, 'CKEditor');
318 $this->fillRichTextField('footer_text', 'This is footer message for ' . $pageTitle, 'CKEditor');
320 $this->type('goal_amount', 10 * $rand);
323 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
325 // Get contribution page id
326 $pageId = $this->urlArg('id');
328 // fill in Processor, Amounts
329 if (!empty($processor)) {
331 while (list($processorName) = each($processor)) {
332 // select newly created processor
333 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
334 $this->assertTrue($this->isTextPresent($processorName));
335 $this->check($xpath);
339 // fill in labels & values in Fixed Contribution Options
340 $this->type('label_1', 'Fixed Amount 1');
341 $this->type('value_1', 1);
342 $this->type('label_2', 'Fixed Amount 2');
343 $this->type('value_2', 2);
344 $this->type('label_3', 'Fixed Amount 3');
345 $this->type('value_3', 3);
346 $this->click('CIVICRM_QFID_1_4');
347 $this->click('_qf_Amount_submit_savenext-bottom');
348 $this->waitForPageToLoad($this->getTimeoutMsec());
350 // click through to the membership view screen
351 $this->click("css=li#tab_thankyou a");
352 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
354 // fill in Receipt details
355 $this->type('thankyou_title', "Thank-you Page Title $hash");
356 $this->fillRichTextField('thankyou_text', 'This is thankyou message for ' . $pageTitle, 'CKEditor');
357 $this->fillRichTextField('thankyou_footer', 'This is thankyou footer message for ' . $pageTitle, 'CKEditor');
358 $this->click('is_email_receipt');
359 $this->waitForElementPresent('bcc_receipt');
360 $this->type('receipt_from_name', "Receipt From Name $hash");
361 $this->type('receipt_from_email', "$hash@example.org");
362 $this->type('receipt_text', "Receipt Message $hash");
363 $this->type('cc_receipt', "$hash@example.net");
364 $this->type('bcc_receipt', "$hash@example.com");
366 $this->click('_qf_ThankYou_next');
367 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
368 $this->waitForPageToLoad($this->getTimeoutMsec());
369 $receiptText = "'ThankYou' information has been saved.";
370 $this->assertTrue($this->isTextPresent($receiptText), 'Missing text: ' . $receiptText);
372 $this->click('link=Premiums');
373 $this->waitForElementPresent('_qf_Premium_submit_savenext-bottom');
374 $assertPremiumsCheck = FALSE;
375 if (!$this->isChecked('premiums_active')) {
376 $assertPremiumsCheck = TRUE;
378 $this->assertTrue($assertPremiumsCheck, 'Premiums Section is not unchecked by default.');
379 $this->click('_qf_Premium_submit_savenext-bottom');
380 $this->waitForPageToLoad($this->getTimeoutMsec());
381 $premiumText = "'Premium' information has been saved.";
382 // check if clicking Save & Next button
383 // Premium is saved rather than required validation error
384 // for No Thank-you Label textfield
385 $this->assertTrue($this->isTextPresent($premiumText));
387 $this->openCiviPage("admin/contribute", "reset=1");
389 // search for the new contrib page and go to its test version
390 $this->type('title', $pageTitle);
391 $this->click('_qf_SearchContribution_refresh');
392 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->isElementPresent("xpath=//table[@id='option11_wrapper']/tbody/tr/td/strong[text()='$pageTitle']");
394 $this->waitForElementPresent("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
395 $this->click("xpath=//table[@id='option11']/tbody/tr/td[4]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
396 $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']");
397 $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']");
398 $this->waitForPageToLoad($this->getTimeoutMsec());
399 $this->waitForElementPresent('premiums_active');
400 $this->waitForElementPresent('_qf_Premium_cancel-bottom');
402 // click on Premiums Section Enabled? checkbox
403 $this->click('premiums_active');
404 $this->waitForElementPresent("xpath=//div[@id='premiumSettings']");
405 $this->waitForElementPresent('premiums_nothankyou_position');
406 $this->type('premiums_intro_title', 'Premiums Intro Title');
407 $this->type('premiums_intro_text', 'Premiums Into Text');
408 $this->type('premiums_contact_email', "$hash@example.net");
410 // let No Thank-you Label text be blank
411 // so that validation error appears
412 // $this->type('premiums_nothankyou_label', );
413 $this->select('premiums_nothankyou_position', 'value=2');
415 // click on save & next button
416 $this->click('_qf_Premium_submit_savenext-bottom');
417 $this->waitForPageToLoad($this->getTimeoutMsec());
418 $premiumRequiredText = "No Thank-you Label is a required field.";
419 // check if clicking Save & Next button
420 // required validation error appears
421 // for No Thank-you Label textfield
422 $this->waitForElementPresent("xpath=//*[@id='premiumSettings']/div/div[2]/table/tbody/tr[6]/td[2]/span[1]");
423 $this->assertTrue($this->isTextPresent($premiumRequiredText));
425 // fill in value for Premiums No Thank-you Label textfield
426 $this->type('premiums_nothankyou_label', 'Premiums No Thank-you Label');
427 $this->waitForElementPresent('_qf_Premium_upload_done-bottom');
429 // click save & done button
430 $this->click('_qf_Premium_upload_done-bottom');
431 $this->waitForPageToLoad($this->getTimeoutMsec());
432 $premiumSavedText = "'Premium' information has been saved.";
433 // check if clicking Save & Done button
434 // contribution page is saved.
435 $this->assertTrue($this->isTextPresent($premiumSavedText));