Merge pull request #2823 from monishdeb/CRM-13833
[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
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Contribute_ContributionPageAddTest extends CiviSeleniumTestCase {
29 function testContributionPageAdd() {
30 // open browser, login
6a488035
TO
31 $this->webtestLogin();
32
33 // a random 7-char string and an even number to make this pass unique
42daf119
CW
34 $hash = substr(sha1(rand()), 0, 7);
35 $rand = 2 * rand(2, 50);
6a488035
TO
36 $pageTitle = 'Donate Online ' . $hash;
37 // create contribution page with randomized title and default params
38 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array("Webtest Dummy" . substr(sha1(rand()), 0, 7) => 'Dummy'), TRUE, TRUE, 'required');
39
071a6d2e 40 $this->openCiviPage("admin/contribute", "reset=1");
6a488035
TO
41
42 // search for the new contrib page and go to its test version
43 $this->type('title', $pageTitle);
44 $this->click('_qf_SearchContribution_refresh');
45 $this->waitForPageToLoad($this->getTimeoutMsec());
46
47 // select testdrive mode
48 $this->isTextPresent($pageTitle);
b45c587e 49 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
071a6d2e 50
6a488035
TO
51 // verify whatever’s possible to verify
52 // FIXME: ideally should be expanded
53 $texts = array(
54 "Title - New Membership $hash",
55 "This is introductory message for $pageTitle",
56 '$ 50.00 Student',
57 "$ $rand.00 Label $hash",
58 "Pay later label $hash",
05f3c31c
DG
59 'Organization Details',
60 'Other Amount',
61 'I pledge to contribute this amount every',
62 "Honoree Section Title $hash",
63 "Honoree Introductory Message $hash",
64 'In Honor of',
65 'Name and Address',
66 'Summary Overlay',
67 );
68 foreach ($texts as $text) {
69 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
70 }
71 }
72
73 // CRM-12510 Test copy contribution page
74 function testContributionPageCopy() {
75 // open browser, login
76 $this->webtestLogin();
77
78 // a random 7-char string and an even number to make this pass unique
79 $hash = substr(sha1(rand()), 0, 7);
80 $rand = 2 * rand(2, 50);
81 $pageTitle = 'Donate Online ' . $hash;
82 // create contribution page with randomized title and default params
83 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array("Webtest Dummy" . substr(sha1(rand()), 0, 7) => 'Dummy'), TRUE, TRUE, 'required');
84
85 $this->openCiviPage("admin/contribute", "reset=1");
86
87 // search for the new contrib page and go to its test version
88 $this->type('title', $pageTitle);
89 $this->click('_qf_SearchContribution_refresh');
90 $this->waitForPageToLoad($this->getTimeoutMsec());
91
92 $this->isTextPresent($pageTitle);
93
94 // Call URL to make a copy of the page
95 $this->openCiviPage("admin/contribute", "action=copy&gid=$pageId");
96
97 // search for the new copy page and go to its test version
98 $this->type('title', 'Copy of ' . $pageTitle);
99 $this->click('_qf_SearchContribution_refresh');
100 $this->waitForPageToLoad($this->getTimeoutMsec());
101
102 $this->isTextPresent('Copy of ' . $pageTitle);
103 // get page id of the copy
104 // $copyPageId = $this->getText("xpath=//div[@id='configure_contribution_page']/tr[@id='row_4']/td[2]");
105 $copyPageId = $this->getText("xpath=//div[@id='option11_wrapper']/table[@id='option11']/tbody/tr[1]/td[2]");
106 // select testdrive mode
107 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$copyPageId", '_qf_Main_upload-bottom');
108
109 // verify whatever’s possible to verify
110 // FIXME: ideally should be expanded
111 $texts = array(
112 "Title - New Membership $hash",
113 "This is introductory message for $pageTitle",
114 '$ 50.00 Student',
115 "$ $rand.00 Label $hash",
116 "Pay later label $hash",
6a488035
TO
117 'Organization Details',
118 'Other Amount',
119 'I pledge to contribute this amount every',
120 "Honoree Section Title $hash",
121 "Honoree Introductory Message $hash",
122 'In Honor of',
123 'Name and Address',
124 'Summary Overlay',
125 );
126 foreach ($texts as $text) {
127 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
128 }
129 }
130
b45c587e
CW
131 /**
132 * check CRM-7943
133 */
6a488035
TO
134 function testContributionPageSeparatePayment() {
135 // open browser, login
6a488035
TO
136 $this->webtestLogin();
137
138 // a random 7-char string and an even number to make this pass unique
42daf119
CW
139 $hash = substr(sha1(rand()), 0, 7);
140 $rand = 2 * rand(2, 50);
6a488035
TO
141 $pageTitle = 'Donate Online ' . $hash;
142
143 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
144 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array("Webtest Dummy" . substr(sha1(rand()), 0, 7) => 'Dummy'),
145 TRUE, TRUE, 'required', TRUE, FALSE, TRUE, NULL, TRUE,
146 1, 7, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE
147 );
148
071a6d2e 149 $this->openCiviPage("admin/contribute", "reset=1");
6a488035
TO
150
151 // search for the new contrib page and go to its test version
152 $this->type('title', $pageTitle);
153 $this->click('_qf_SearchContribution_refresh');
154 $this->waitForPageToLoad($this->getTimeoutMsec());
155
156 // select testdrive mode
157 $this->isTextPresent($pageTitle);
b45c587e 158 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
6a488035 159
6a488035
TO
160 $texts = array(
161 "Title - New Membership $hash",
162 "This is introductory message for $pageTitle",
163 "$ $rand.00 Label $hash",
164 "Pay later label $hash",
165 'Organization Details',
166 'Other Amount',
167 'I pledge to contribute this amount every',
168 "Honoree Section Title $hash",
169 "Honoree Introductory Message $hash",
170 'In Honor of',
171 'Name and Address',
172 'Summary Overlay',
173 );
174 foreach ($texts as $text) {
175 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
176 }
177 }
178
b45c587e
CW
179 /**
180 * check CRM-7949
181 */
6a488035
TO
182 function testContributionPageSeparatePaymentPayLater() {
183 // open browser, login
6a488035
TO
184 $this->webtestLogin();
185
186 // a random 7-char string and an even number to make this pass unique
42daf119
CW
187 $hash = substr(sha1(rand()), 0, 7);
188 $rand = 2 * rand(2, 50);
6a488035
TO
189 $pageTitle = 'Donate Online ' . $hash;
190
191 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
192 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, NULL,
193 TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, NULL, FALSE,
194 1, 0, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE
195 );
196
071a6d2e 197 $this->openCiviPage("admin/contribute", "reset=1");
6a488035
TO
198
199 // search for the new contrib page and go to its test version
200 $this->type('title', $pageTitle);
201 $this->click('_qf_SearchContribution_refresh');
202 $this->waitForPageToLoad($this->getTimeoutMsec());
203
6a488035 204 //logout
42daf119 205 $this->webtestLogout();
6a488035
TO
206
207 //Open Live Contribution Page
b45c587e 208 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
6a488035
TO
209
210 $firstName = 'Ya' . substr(sha1(rand()), 0, 4);
211 $lastName = 'Cha' . substr(sha1(rand()), 0, 7);
212
213 $this->type('email-5', $firstName . '@example.com');
214 $this->type('first_name', $firstName);
215 $this->type('last_name', $lastName);
b45c587e 216
225a8648 217 $this->clickLink('_qf_Main_upload-bottom', '_qf_Confirm_next-bottom');
6a488035
TO
218
219 $this->click('_qf_Confirm_next-bottom');
220 $this->waitForPageToLoad($this->getTimeoutMsec());
221
222 //login to check contribution
6a488035
TO
223 $this->webtestLogin();
224
225 //Find Contribution
42daf119 226 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
6a488035
TO
227
228 $this->type('sort_name', "$firstName $lastName");
b68dea89 229 $this->select('financial_type_id',"label=Member Dues");
225a8648
CW
230 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
231 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom');
6a488035 232 $expected = array(
42daf119
CW
233 'From' => "{$firstName} {$lastName}",
234 'Financial Type' => 'Member Dues',
b68dea89
DG
235 'Total Amount' => '$ 50.00',
236 'Contribution Status' => 'Pending : Pay Later',
6a488035 237 );
b68dea89
DG
238 $this->webtestVerifyTabularData($expected);
239 $this->click('_qf_ContributionView_cancel-bottom');
240
241 //View Contribution for separate contribution
242 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
243 // Open search criteria again
1a599e05 244 $this->click("xpath=id('Search')/div[2]/div/div[1]");
b68dea89 245 $this->waitForElementPresent("financial_type_id");
1a599e05 246 $this->type("sort_name", $firstName);
b68dea89 247 $this->select('financial_type_id',"label=Donation");
225a8648 248 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
b68dea89 249
225a8648 250 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom');
b68dea89 251 $expected = array(
42daf119
CW
252 'From' => "{$firstName} {$lastName}",
253 'Financial Type' => 'Donation',
b68dea89
DG
254 'Contribution Status' => 'Pending : Pay Later',
255 );
256 $this->webtestVerifyTabularData($expected);
6a488035
TO
257 $this->click('_qf_ContributionView_cancel-bottom');
258
6a488035 259 //Find Member
42daf119 260 $this->openCiviPage("member/search", "reset=1", 'member_source');
6a488035 261 $this->type('sort_name', "$firstName $lastName");
225a8648
CW
262 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
263 $this->clickLink("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_MembershipView_cancel-bottom');
6a488035
TO
264
265 //View Membership Record
266 $expected = array(
b68dea89
DG
267 'Member' => "{$firstName} {$lastName}",
268 'Membership Type' => 'Student',
269 'Status' => 'Pending',
6a488035 270 );
b68dea89 271 $this->webtestVerifyTabularData($expected);
6a488035
TO
272 $this->click('_qf_MembershipView_cancel-bottom');
273 }
2560550d
AW
274
275 /**
276 * CRM-12994
277 */
278 function testContributionPageAddPremiumRequiredField() {
279 // open browser, login
280 $this->webtestLogin();
281
282 // a random 7-char string and an even number to make this pass unique
283 $hash = substr(sha1(rand()), 0, 7);
284 $rand = 2 * rand(2, 50);
285 $pageTitle = 'Donate Online ' . $hash;
286 $processor = array("Webtest Dummy" . substr(sha1(rand()), 0, 7) => 'Dummy');
287
288 // Create a new payment processor
289 while (list($processorName, $processorType) = each($processor)) {
290 $this->webtestAddPaymentProcessor($processorName, $processorType);
291 }
292
293 // go to the New Contribution Page page
294 $this->openCiviPage('admin/contribute', 'action=add&reset=1');
295
296 // fill in Title and Settings
297 $this->type('title', $pageTitle);
298
299 // to select financial type
300 $this->select('financial_type_id', "label=Donation");
301
302 $this->click('is_organization');
303 $this->select('onbehalf_profile_id', 'label=On Behalf Of Organization');
304 $this->type('for_organization', "On behalf $hash");
305 // make onBehalf optional
306 $this->click('CIVICRM_QFID_1_2');
307
308 $this->fillRichTextField('intro_text', 'This is introductory message for ' . $pageTitle, 'CKEditor');
309 $this->fillRichTextField('footer_text', 'This is footer message for ' . $pageTitle, 'CKEditor');
310
311 $this->type('goal_amount', 10 * $rand);
312
313 // Submit form
314 $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom");
315
316 // Get contribution page id
317 $pageId = $this->urlArg('id');
318
319 // fill in Processor, Amounts
320 if (!empty($processor)) {
321 reset($processor);
322 while (list($processorName) = each($processor)) {
323 // select newly created processor
324 $xpath = "xpath=//label[text() = '{$processorName}']/preceding-sibling::input[1]";
325 $this->assertTrue($this->isTextPresent($processorName));
326 $this->check($xpath);
327 }
328 }
329
330 // fill in labels & values in Fixed Contribution Options
331 $this->type('label_1', 'Fixed Amount 1');
332 $this->type('value_1', 1);
333 $this->type('label_2', 'Fixed Amount 2');
334 $this->type('value_2', 2);
335 $this->type('label_3', 'Fixed Amount 3');
336 $this->type('value_3', 3);
337 $this->click('CIVICRM_QFID_1_2');
338 $this->click('_qf_Amount_submit_savenext-bottom');
339 $this->waitForPageToLoad($this->getTimeoutMsec());
340
341 // click through to the membership view screen
342 $this->click("css=li#tab_thankyou a");
343 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
344
345 // fill in Receipt details
346 $this->type('thankyou_title', "Thank-you Page Title $hash");
347 $this->fillRichTextField('thankyou_text', 'This is thankyou message for ' . $pageTitle, 'CKEditor');
348 $this->fillRichTextField('thankyou_footer', 'This is thankyou footer message for ' . $pageTitle, 'CKEditor');
349 $this->click('is_email_receipt');
350 $this->waitForElementPresent('bcc_receipt');
351 $this->type('receipt_from_name', "Receipt From Name $hash");
352 $this->type('receipt_from_email', "$hash@example.org");
353 $this->type('receipt_text', "Receipt Message $hash");
354 $this->type('cc_receipt', "$hash@example.net");
355 $this->type('bcc_receipt', "$hash@example.com");
356
357 $this->click('_qf_ThankYou_next');
358 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
359 $this->waitForPageToLoad($this->getTimeoutMsec());
360 $receiptText = "'ThankYou' information has been saved.";
361 $this->assertTrue($this->isTextPresent($receiptText), 'Missing text: ' . $receiptText);
362
363 $this->click('link=Premiums');
364 $this->waitForElementPresent('_qf_Premium_submit_savenext-bottom');
365 $assertPremiumsCheck = FALSE;
366 if (!$this->isChecked('premiums_active')) {
367 $assertPremiumsCheck = TRUE;
368 }
369 $this->assertTrue($assertPremiumsCheck, 'Premiums Section is not unchecked by default.');
370 $this->click('_qf_Premium_submit_savenext-bottom');
371 $this->waitForPageToLoad($this->getTimeoutMsec());
372 $premiumText = "'Premium' information has been saved.";
373 // check if clicking Save & Next button
374 // Premium is saved rather than required validation error
375 // for No Thank-you Label textfield
376 $this->assertTrue($this->isTextPresent($premiumText));
377
378 $this->openCiviPage("admin/contribute", "reset=1");
379
380 // search for the new contrib page and go to its test version
381 $this->type('title', $pageTitle);
382 $this->click('_qf_SearchContribution_refresh');
383 $this->waitForPageToLoad($this->getTimeoutMsec());
384 $this->isElementPresent("xpath=//table[@id='option11_wrapper']/tbody/tr/td/strong[text()='$pageTitle']");
91c0f7ec
RN
385 $this->waitForElementPresent("xpath=//table[@id='option11']/tbody/tr/td[5]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
386 $this->click("xpath=//table[@id='option11']/tbody/tr/td[5]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']");
387 $this->waitForElementPresent("xpath=//table[@id='option11']/tbody/tr/td[5]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']/ul[@class='panel']/li[8]/a[@title='Premiums']");
388 $this->click("xpath=//table[@id='option11']/tbody/tr/td[5]/div[@class='crm-contribution-page-configure-actions']/span[text()='Configure']/ul[@class='panel']/li[8]/a[@title='Premiums']");
2560550d
AW
389 $this->waitForPageToLoad($this->getTimeoutMsec());
390 $this->waitForElementPresent('premiums_active');
391 $this->waitForElementPresent('_qf_Premium_cancel-bottom');
392
393 // click on Premiums Section Enabled? checkbox
394 $this->click('premiums_active');
395 $this->waitForElementPresent("xpath=//div[@id='premiumSettings']");
396 $this->waitForElementPresent('premiums_nothankyou_position');
397 $this->type('premiums_intro_title', 'Premiums Intro Title');
398 $this->type('premiums_intro_text', 'Premiums Into Text');
399 $this->type('premiums_contact_email', "$hash@example.net");
400
401 // let No Thank-you Label text be blank
402 // so that validation error appears
403 // $this->type('premiums_nothankyou_label', );
404 $this->select('premiums_nothankyou_position', 'value=2');
405
406 // click on save & next button
407 $this->click('_qf_Premium_submit_savenext-bottom');
408 $this->waitForPageToLoad($this->getTimeoutMsec());
409 $premiumRequiredText = "No Thank-you Label is a required field.";
410 // check if clicking Save & Next button
411 // required validation error appears
412 // for No Thank-you Label textfield
413 $this->waitForElementPresent("xpath=//ul[@id='errorList']");
414 $this->assertTrue($this->isTextPresent($premiumRequiredText));
415
416 // fill in value for Premiums No Thank-you Label textfield
417 $this->type('premiums_nothankyou_label', 'Premiums No Thank-you Label');
418 $this->waitForElementPresent('_qf_Premium_upload_done-bottom');
419
420 // click save & done button
421 $this->click('_qf_Premium_upload_done-bottom');
422 $this->waitForPageToLoad($this->getTimeoutMsec());
423 $premiumSavedText = "'Premium' information has been saved.";
424 // check if clicking Save & Done button
425 // contribution page is saved.
426 $this->assertTrue($this->isTextPresent($premiumSavedText));
427 }
6a488035
TO
428}
429