Fixed some contribution pages
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / ContributionPageAddTest.php
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
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contribute_ContributionPageAddTest extends CiviSeleniumTestCase {
30 function testContributionPageAdd() {
31 // open browser, login
32 $this->webtestLogin();
33
34 // a random 7-char string and an even number to make this pass unique
35 $hash = substr(sha1(rand()), 0, 7);
36 $rand = 2 * rand(2, 50);
37 $pageTitle = 'Donate Online ' . $hash;
38 // create contribution page with randomized title and default params
39 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array("Webtest Dummy" . substr(sha1(rand()), 0, 7) => 'Dummy'), TRUE, TRUE, 'required');
40
41 $this->openCiviPage("admin/contribute", "reset=1");
42
43 // search for the new contrib page and go to its test version
44 $this->type('title', $pageTitle);
45 $this->click('_qf_SearchContribution_refresh');
46 $this->waitForPageToLoad($this->getTimeoutMsec());
47
48 // select testdrive mode
49 $this->isTextPresent($pageTitle);
50 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
51
52 // verify whatever’s possible to verify
53 // FIXME: ideally should be expanded
54 $texts = array(
55 "Title - New Membership $hash",
56 "This is introductory message for $pageTitle",
57 '$ 50.00 Student',
58 "$ $rand.00 Label $hash",
59 "Pay later label $hash",
60 'Organization Details',
61 'Other Amount',
62 'I pledge to contribute this amount every',
63 "Honoree Section Title $hash",
64 "Honoree Introductory Message $hash",
65 'In Honor of',
66 'Name and Address',
67 'Summary Overlay',
68 );
69 foreach ($texts as $text) {
70 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
71 }
72 }
73
74 /**
75 * check CRM-7943
76 */
77 function testContributionPageSeparatePayment() {
78 // open browser, login
79 $this->webtestLogin();
80
81 // a random 7-char string and an even number to make this pass unique
82 $hash = substr(sha1(rand()), 0, 7);
83 $rand = 2 * rand(2, 50);
84 $pageTitle = 'Donate Online ' . $hash;
85
86 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
87 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array("Webtest Dummy" . substr(sha1(rand()), 0, 7) => 'Dummy'),
88 TRUE, TRUE, 'required', TRUE, FALSE, TRUE, NULL, TRUE,
89 1, 7, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE
90 );
91
92 $this->openCiviPage("admin/contribute", "reset=1");
93
94 // search for the new contrib page and go to its test version
95 $this->type('title', $pageTitle);
96 $this->click('_qf_SearchContribution_refresh');
97 $this->waitForPageToLoad($this->getTimeoutMsec());
98
99 // select testdrive mode
100 $this->isTextPresent($pageTitle);
101 $this->openCiviPage("contribute/transact", "reset=1&action=preview&id=$pageId", '_qf_Main_upload-bottom');
102
103 $texts = array(
104 "Title - New Membership $hash",
105 "This is introductory message for $pageTitle",
106 "$ $rand.00 Label $hash",
107 "Pay later label $hash",
108 'Organization Details',
109 'Other Amount',
110 'I pledge to contribute this amount every',
111 "Honoree Section Title $hash",
112 "Honoree Introductory Message $hash",
113 'In Honor of',
114 'Name and Address',
115 'Summary Overlay',
116 );
117 foreach ($texts as $text) {
118 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
119 }
120 }
121
122 /**
123 * check CRM-7949
124 */
125 function testContributionPageSeparatePaymentPayLater() {
126 // open browser, login
127 $this->webtestLogin();
128
129 // a random 7-char string and an even number to make this pass unique
130 $hash = substr(sha1(rand()), 0, 7);
131 $rand = 2 * rand(2, 50);
132 $pageTitle = 'Donate Online ' . $hash;
133
134 // create contribution page with randomized title, default params and separate payment for Membership and Contribution
135 $pageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, NULL,
136 TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, NULL, FALSE,
137 1, 0, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE
138 );
139
140 $this->openCiviPage("admin/contribute", "reset=1");
141
142 // search for the new contrib page and go to its test version
143 $this->type('title', $pageTitle);
144 $this->click('_qf_SearchContribution_refresh');
145 $this->waitForPageToLoad($this->getTimeoutMsec());
146
147 //logout
148 $this->webtestLogout();
149
150 //Open Live Contribution Page
151 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
152
153 $firstName = 'Ya' . substr(sha1(rand()), 0, 4);
154 $lastName = 'Cha' . substr(sha1(rand()), 0, 7);
155
156 $this->type('email-5', $firstName . '@example.com');
157 $this->type('first_name', $firstName);
158 $this->type('last_name', $lastName);
159
160 $this->click('_qf_Main_upload-bottom');
161 $this->waitForPageToLoad($this->getTimeoutMsec());
162 $this->waitForElementPresent('_qf_Confirm_next-bottom');
163
164 $this->click('_qf_Confirm_next-bottom');
165 $this->waitForPageToLoad($this->getTimeoutMsec());
166
167 //login to check contribution
168 $this->webtestLogin();
169
170 //Find Contribution
171 $this->openCiviPage("contribute/search", "reset=1", 'contribution_date_low');
172
173 $this->type('sort_name', "$firstName $lastName");
174 $this->select('financial_type_id',"label=Member Dues");
175 $this->click('_qf_Search_refresh');
176
177 $this->waitForPageToLoad($this->getTimeoutMsec());
178
179 //View Contribution for membership fee
180 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
181 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
182 $this->waitForPageToLoad($this->getTimeoutMsec());
183 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
184 $expected = array(
185 'From' => "{$firstName} {$lastName}",
186 'Financial Type' => 'Member Dues',
187 'Total Amount' => '$ 50.00',
188 'Contribution Status' => 'Pending : Pay Later',
189 );
190 $this->webtestVerifyTabularData($expected);
191 $this->click('_qf_ContributionView_cancel-bottom');
192
193 //View Contribution for separate contribution
194 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
195 // Open search criteria again
196 $this->click("xpath=id('Search')/x:div[2]/x:div/x:div[1]");
197 $this->waitForElementPresent("financial_type_id");
198 $this->select('financial_type_id',"label=Donation");
199 $this->click('_qf_Search_refresh');
200
201 $this->waitForPageToLoad($this->getTimeoutMsec());
202 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
203
204 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
205 $this->waitForPageToLoad($this->getTimeoutMsec());
206 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
207 $expected = array(
208 'From' => "{$firstName} {$lastName}",
209 'Financial Type' => 'Donation',
210 'Contribution Status' => 'Pending : Pay Later',
211 );
212 $this->webtestVerifyTabularData($expected);
213 $this->click('_qf_ContributionView_cancel-bottom');
214
215
216 //Find Member
217 $this->openCiviPage("member/search", "reset=1", 'member_source');
218 $this->type('sort_name', "$firstName $lastName");
219 $this->click('_qf_Search_refresh');
220 $this->waitForPageToLoad($this->getTimeoutMsec());
221
222 //visit the Member View link
223 $this->waitForElementPresent("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
224 $this->click("xpath=//div[@id='memberSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
225 $this->waitForPageToLoad($this->getTimeoutMsec());
226 $this->waitForElementPresent('_qf_MembershipView_cancel-bottom');
227
228 //View Membership Record
229 $expected = array(
230 'Member' => "{$firstName} {$lastName}",
231 'Membership Type' => 'Student',
232 'Status' => 'Pending',
233 );
234 $this->webtestVerifyTabularData($expected);
235 $this->click('_qf_MembershipView_cancel-bottom');
236 }
237 }
238