Merge pull request #4199 from pradpnayak/CRM-15055
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / ContributionPageAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25*/
26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contribute_ContributionPageAddTest
31 */
6a488035
TO
32class WebTest_Contribute_ContributionPageAddTest extends CiviSeleniumTestCase {
33 function testContributionPageAdd() {
34 // open browser, login
6a488035
TO
35 $this->webtestLogin();
36
37 // a random 7-char string and an even number to make this pass unique
42daf119
CW
38 $hash = substr(sha1(rand()), 0, 7);
39 $rand = 2 * rand(2, 50);
6a488035
TO
40 $pageTitle = 'Donate Online ' . $hash;
41 // create contribution page with randomized title and default params
c3ad8633 42 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'), TRUE, TRUE, 'required');
6a488035 43
071a6d2e 44 $this->openCiviPage("admin/contribute", "reset=1");
6a488035
TO
45
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());
50
51 // select testdrive mode
52 $this->isTextPresent($pageTitle);
b45c587e 53 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
071a6d2e 54
6a488035
TO
55 // verify whatever’s possible to verify
56 // FIXME: ideally should be expanded
57 $texts = array(
58 "Title - New Membership $hash",
59 "This is introductory message for $pageTitle",
60 '$ 50.00 Student',
61 "$ $rand.00 Label $hash",
62 "Pay later label $hash",
05f3c31c
DG
63 'Organization Details',
64 'Other Amount',
65 'I pledge to contribute this amount every',
05f3c31c
DG
66 'Name and Address',
67 'Summary Overlay',
68 );
69 foreach ($texts as $text) {
70 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
71 }
11b9c22d
JP
72
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");
05f3c31c 85 }
e9479dcf 86
05f3c31c
DG
87 // CRM-12510 Test copy contribution page
88 function testContributionPageCopy() {
89 // open browser, login
90 $this->webtestLogin();
91
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
c3ad8633 97 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'), TRUE, TRUE, 'required');
05f3c31c
DG
98
99 $this->openCiviPage("admin/contribute", "reset=1");
100
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());
105
106 $this->isTextPresent($pageTitle);
107
108 // Call URL to make a copy of the page
109 $this->openCiviPage("admin/contribute", "action=copy&gid=$pageId");
e9479dcf 110
05f3c31c
DG
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());
e9479dcf 115
05f3c31c
DG
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');
122
123 // verify whatever’s possible to verify
124 // FIXME: ideally should be expanded
125 $texts = array(
126 "Title - New Membership $hash",
127 "This is introductory message for $pageTitle",
128 '$ 50.00 Student',
129 "$ $rand.00 Label $hash",
130 "Pay later label $hash",
6a488035
TO
131 'Organization Details',
132 'Other Amount',
133 'I pledge to contribute this amount every',
6a488035
TO
134 'Name and Address',
135 'Summary Overlay',
136 );
137 foreach ($texts as $text) {
138 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
139 }
140 }
141
b45c587e
CW
142 /**
143 * check CRM-7943
144 */
6a488035
TO
145 function testContributionPageSeparatePayment() {
146 // open browser, login
6a488035
TO
147 $this->webtestLogin();
148
149 // a random 7-char string and an even number to make this pass unique
42daf119
CW
150 $hash = substr(sha1(rand()), 0, 7);
151 $rand = 2 * rand(2, 50);
6a488035
TO
152 $pageTitle = 'Donate Online ' . $hash;
153
154 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
c3ad8633 155 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array('Test Processor' => 'Dummy'),
6a488035
TO
156 TRUE, TRUE, 'required', TRUE, FALSE, TRUE, NULL, TRUE,
157 1, 7, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE
158 );
159
071a6d2e 160 $this->openCiviPage("admin/contribute", "reset=1");
6a488035
TO
161
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());
166
167 // select testdrive mode
168 $this->isTextPresent($pageTitle);
b45c587e 169 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
6a488035 170
6a488035
TO
171 $texts = array(
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',
177 'Other Amount',
178 'I pledge to contribute this amount every',
6a488035
TO
179 'Name and Address',
180 'Summary Overlay',
181 );
182 foreach ($texts as $text) {
183 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
184 }
185 }
186
b45c587e
CW
187 /**
188 * check CRM-7949
189 */
6a488035
TO
190 function testContributionPageSeparatePaymentPayLater() {
191 // open browser, login
6a488035
TO
192 $this->webtestLogin();
193
194 // a random 7-char string and an even number to make this pass unique
42daf119
CW
195 $hash = substr(sha1(rand()), 0, 7);
196 $rand = 2 * rand(2, 50);
6a488035
TO
197 $pageTitle = 'Donate Online ' . $hash;
198
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
203 );
204
071a6d2e 205 $this->openCiviPage("admin/contribute", "reset=1");
6a488035
TO
206
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());
211
6a488035 212 //logout
42daf119 213 $this->webtestLogout();
6a488035
TO
214
215 //Open Live Contribution Page
b45c587e 216 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
6a488035
TO
217
218 $firstName = 'Ya' . substr(sha1(rand()), 0, 4);
219 $lastName = 'Cha' . substr(sha1(rand()), 0, 7);
220
221 $this->type('email-5', $firstName . '@example.com');
222 $this->type('first_name', $firstName);
223 $this->type('last_name', $lastName);
b45c587e 224
77f1e6b1 225 $this->select('state_province-1',"value=1002");
225a8648 226 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
6a488035
TO
227
228 $this->click('_qf_Confirm_next-bottom');
229 $this->waitForPageToLoad($this->getTimeoutMsec());
230
231 //login to check contribution
6a488035
TO
232 $this->webtestLogin();
233
234 //Find Contribution
42daf119 235 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
6a488035
TO
236
237 $this->type('sort_name', "$firstName $lastName");
b68dea89 238 $this->select('financial_type_id',"label=Member Dues");
225a8648 239 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
77f1e6b1 240 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
6a488035 241 $expected = array(
42daf119
CW
242 'From' => "{$firstName} {$lastName}",
243 'Financial Type' => 'Member Dues',
b68dea89
DG
244 'Total Amount' => '$ 50.00',
245 'Contribution Status' => 'Pending : Pay Later',
6a488035 246 );
b68dea89
DG
247 $this->webtestVerifyTabularData($expected);
248 $this->click('_qf_ContributionView_cancel-bottom');
249
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
1a599e05 253 $this->click("xpath=id('Search')/div[2]/div/div[1]");
b68dea89 254 $this->waitForElementPresent("financial_type_id");
1a599e05 255 $this->type("sort_name", $firstName);
b68dea89 256 $this->select('financial_type_id',"label=Donation");
225a8648 257 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
b68dea89 258
77f1e6b1 259 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom', FALSE);
b68dea89 260 $expected = array(
42daf119
CW
261 'From' => "{$firstName} {$lastName}",
262 'Financial Type' => 'Donation',
b68dea89
DG
263 'Contribution Status' => 'Pending : Pay Later',
264 );
265 $this->webtestVerifyTabularData($expected);
6a488035
TO
266 $this->click('_qf_ContributionView_cancel-bottom');
267
6a488035 268 //Find Member
42daf119 269 $this->openCiviPage("member/search", "reset=1", 'member_source');
6a488035 270 $this->type('sort_name', "$firstName $lastName");
77f1e6b1 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);
6a488035
TO
273
274 //View Membership Record
275 $expected = array(
b68dea89
DG
276 'Member' => "{$firstName} {$lastName}",
277 'Membership Type' => 'Student',
278 'Status' => 'Pending',
6a488035 279 );
b68dea89 280 $this->webtestVerifyTabularData($expected);
6a488035
TO
281 $this->click('_qf_MembershipView_cancel-bottom');
282 }
2560550d
AW
283
284 /**
e9479dcf 285 * CRM-12994
2560550d
AW
286 */
287 function testContributionPageAddPremiumRequiredField() {
288 // open browser, login
289 $this->webtestLogin();
290
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;
c3ad8633 295 $processor = array('Test Processor' => 'Dummy');
2560550d
AW
296
297 // Create a new payment processor
298 while (list($processorName, $processorType) = each($processor)) {
299 $this->webtestAddPaymentProcessor($processorName, $processorType);
300 }
e9479dcf 301
2560550d
AW
302 // go to the New Contribution Page page
303 $this->openCiviPage('admin/contribute', 'action=add&reset=1');
304
305 // fill in Title and Settings
306 $this->type('title', $pageTitle);
307
308 // to select financial type
309 $this->select('financial_type_id', "label=Donation");
310
311 $this->click('is_organization');
d340a0e8 312 $this->select("xpath=//*[@class='crm-contribution-onbehalf_profile_id']//span[@class='crm-profile-selector-select']//select", 'label=On Behalf Of Organization');
2560550d
AW
313 $this->type('for_organization', "On behalf $hash");
314 // make onBehalf optional
315 $this->click('CIVICRM_QFID_1_2');
e9479dcf 316
2560550d
AW
317 $this->fillRichTextField('intro_text', 'This is introductory message for ' . $pageTitle, 'CKEditor');
318 $this->fillRichTextField('footer_text', 'This is footer message for ' . $pageTitle, 'CKEditor');
319
320 $this->type('goal_amount', 10 * $rand);
321
322 // Submit form
323 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
324
325 // Get contribution page id
326 $pageId = $this->urlArg('id');
327
328 // fill in Processor, Amounts
329 if (!empty($processor)) {
330 reset($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);
336 }
337 }
338
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);
77f1e6b1 346 $this->click('CIVICRM_QFID_1_4');
2560550d
AW
347 $this->click('_qf_Amount_submit_savenext-bottom');
348 $this->waitForPageToLoad($this->getTimeoutMsec());
e9479dcf 349
2560550d
AW
350 // click through to the membership view screen
351 $this->click("css=li#tab_thankyou a");
352 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
353
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");
365
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);
371
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;
377 }
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.";
e9479dcf 382 // check if clicking Save & Next button
2560550d
AW
383 // Premium is saved rather than required validation error
384 // for No Thank-you Label textfield
385 $this->assertTrue($this->isTextPresent($premiumText));
386
387 $this->openCiviPage("admin/contribute", "reset=1");
388
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']");
77f1e6b1 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']");
2560550d
AW
398 $this->waitForPageToLoad($this->getTimeoutMsec());
399 $this->waitForElementPresent('premiums_active');
400 $this->waitForElementPresent('_qf_Premium_cancel-bottom');
401
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");
e9479dcf 409
2560550d
AW
410 // let No Thank-you Label text be blank
411 // so that validation error appears
e9479dcf 412 // $this->type('premiums_nothankyou_label', );
2560550d
AW
413 $this->select('premiums_nothankyou_position', 'value=2');
414
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
77f1e6b1 422 $this->waitForElementPresent("xpath=//*[@id='premiumSettings']/div/div[2]/table/tbody/tr[6]/td[2]/span[1]");
2560550d 423 $this->assertTrue($this->isTextPresent($premiumRequiredText));
e9479dcf 424
2560550d 425 // fill in value for Premiums No Thank-you Label textfield
e9479dcf 426 $this->type('premiums_nothankyou_label', 'Premiums No Thank-you Label');
2560550d 427 $this->waitForElementPresent('_qf_Premium_upload_done-bottom');
e9479dcf 428
2560550d
AW
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.
e9479dcf 435 $this->assertTrue($this->isTextPresent($premiumSavedText));
2560550d 436 }
6a488035
TO
437}
438