Merge pull request #1134 from deepak-srivastava/toggle
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / ContributionPageAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
244 $this->click("xpath=id('Search')/x:div[2]/x:div/x:div[1]");
245 $this->waitForElementPresent("financial_type_id");
246 $this->select('financial_type_id',"label=Donation");
225a8648 247 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
b68dea89 248
225a8648 249 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_ContributionView_cancel-bottom');
b68dea89 250 $expected = array(
42daf119
CW
251 'From' => "{$firstName} {$lastName}",
252 'Financial Type' => 'Donation',
b68dea89
DG
253 'Contribution Status' => 'Pending : Pay Later',
254 );
255 $this->webtestVerifyTabularData($expected);
6a488035
TO
256 $this->click('_qf_ContributionView_cancel-bottom');
257
6a488035 258 //Find Member
42daf119 259 $this->openCiviPage("member/search", "reset=1", 'member_source');
6a488035 260 $this->type('sort_name', "$firstName $lastName");
225a8648
CW
261 $this->clickLink('_qf_Search_refresh', "xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
262 $this->clickLink("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", '_qf_MembershipView_cancel-bottom');
6a488035
TO
263
264 //View Membership Record
265 $expected = array(
b68dea89
DG
266 'Member' => "{$firstName} {$lastName}",
267 'Membership Type' => 'Student',
268 'Status' => 'Pending',
6a488035 269 );
b68dea89 270 $this->webtestVerifyTabularData($expected);
6a488035
TO
271 $this->click('_qf_MembershipView_cancel-bottom');
272 }
273}
274