Merge pull request #202 from pratik-joshi/CRM-12153-tag-merge-UI-break-fixes
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OnlineContributionTest.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
27
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Campaign_OnlineContributionTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testCreateCampaign() {
42daf119 36 $this->webtestLogin('admin');
6a488035
TO
37
38 // Create new group
39 $title = substr(sha1(rand()), 0, 7);
40 $groupName = $this->WebtestAddGroup();
41
42 // Adding contact
43 // We're using Quick Add block on the main page for this.
44 $firstName1 = substr(sha1(rand()), 0, 7);
45 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
46
47 // add contact to group
48 // visit group tab
49 $this->click("css=li#tab_group a");
50 $this->waitForElementPresent("group_id");
51
52 // add to group
53 $this->select("group_id", "label=$groupName");
54 $this->click("_qf_GroupContact_next");
55 $this->waitForPageToLoad($this->getTimeoutMsec());
56
57 $firstName2 = substr(sha1(rand()), 0, 7);
58 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
59
60 // add contact to group
61 // visit group tab
62 $this->click("css=li#tab_group a");
63 $this->waitForElementPresent("group_id");
64
65 // add to group
66 $this->select("group_id", "label=$groupName");
67 $this->click("_qf_GroupContact_next");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
69
70 // Enable CiviCampaign module if necessary
9042f10e 71 $this->enableComponents(array('CiviCampaign'));
6a488035 72
42daf119 73 // add the required permission
6a488035
TO
74 $permissions = array(
75 'edit-2-administer-civicampaign',
76 'edit-1-make-online-contributions',
77 'edit-1-profile-listings-and-forms',
78 );
79 $this->changePermissions($permissions);
80
42daf119
CW
81 // Log in as normal user
82 $this->webtestLogin();
9042f10e 83 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
6a488035 84
6a488035
TO
85 $campaignTitle = "Campaign $title";
86 $this->type("title", $campaignTitle);
87
88 // select the campaign type
89 $this->select("campaign_type_id", "value=2");
90
91 // fill in the description
92 $this->type("description", "This is a test campaign");
93
94 // include groups for the campaign
95 $this->addSelection("includeGroups-f", "label=$groupName");
96 $this->click("//option[@value=4]");
97 $this->click("add");
98
99 // fill the end date for campaign
100 $this->webtestFillDate("end_date", "+1 year");
101
102 // select campaign status
103 $this->select("status_id", "value=2");
104
105 // click save
106 $this->click("_qf_Campaign_upload-bottom");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
108
9042f10e 109 $this->assertElementContainsText('crm-notification-container', "Campaign Campaign $title has been saved.",
6a488035
TO
110 "Status message didn't show up after saving campaign!"
111 );
112
113 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
114 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
115
116 $this->onlineContributionAddTest($campaignTitle, $id);
117 }
118
119 function onlineContributionAddTest($campaignTitle, $id) {
120 // We need a payment processor
121 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
122 $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName);
123
9042f10e 124 $this->openCiviPage("admin/contribute/add", "reset=1&action=add");
6a488035
TO
125
126 $contributionTitle = substr(sha1(rand()), 0, 7);
127 $rand = 2 * rand(2, 50);
128
129 // fill in step 1 (Title and Settings)
130 $contributionPageTitle = "Title $contributionTitle";
131 $this->type('title', $contributionPageTitle);
132 $this->select( 'financial_type_id', 'value=1' );
133
134 // select campaign
135 $this->click("campaign_id");
136 $this->select("campaign_id", "value=$id");
137
138 $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor');
139 $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor');
140
141 // go to step 2
142 $this->click('_qf_Settings_next');
143 $this->waitForElementPresent("_qf_Amount_next-bottom");
144
145 //this contribution page for online contribution
146 $this->check("payment_processor[{$paymentProcessorId}]");
9042f10e 147 $this->assertElementContainsText('crm-container', "Contribution Amounts section enabled");
6a488035
TO
148 $this->type("label_1", "amount 1");
149 $this->type("value_1", "100");
150 $this->type("label_2", "amount 2");
151 $this->type("value_2", "200");
152 $this->click("CIVICRM_QFID_1_2");
153
154 $this->click("_qf_Amount_next-bottom");
155 $this->waitForPageToLoad($this->getTimeoutMsec());
156
157 // go to step 4
158 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Receipt']");
159 $this->waitForElementPresent('_qf_ThankYou_next-bottom');
160
161 // fill in step 4 (Thanks and Receipt)
162 $this->type('thankyou_title', "Thank-you Page Title $contributionTitle");
163 $this->type('receipt_from_name', "Receipt From Name $contributionTitle");
164 $this->type('receipt_from_email', "$contributionTitle@example.org");
165 $this->type('receipt_text', "Receipt Message $contributionTitle");
166 $this->type('cc_receipt', "$contributionTitle@example.net");
167 $this->type('bcc_receipt', "$contributionTitle@example.com");
168
169 $this->click('_qf_ThankYou_next-bottom');
170 $this->waitForPageToLoad($this->getTimeoutMsec());
171
172 // go to step 5
173 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Tell a Friend']");
174 $this->waitForElementPresent("_qf_Contribute_next-bottom");
175
176 // fill in step 5 (Tell a Friend)
177 $this->click('tf_is_active');
178 $this->type('tf_title', "TaF Title $contributionTitle");
179 $this->type('intro', "TaF Introduction $contributionTitle");
180 $this->type('suggested_message', "TaF Suggested Message $contributionTitle");
181 $this->type('general_link', "TaF Info Page Link $contributionTitle");
182 $this->type('tf_thankyou_title', "TaF Thank-you Title $contributionTitle");
183 $this->type('tf_thankyou_text', "TaF Thank-you Message $contributionTitle");
184
185 $this->click('_qf_Contribute_next-bottom');
186 $this->waitForPageToLoad($this->getTimeoutMsec());
187
188 // go to step 6
189 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Profiles']");
190 $this->waitForElementPresent("_qf_Custom_next-bottom");
191
192 // fill in step 6 (Include Profiles)
193 $this->select('custom_pre_id', 'value=1');
194
195 $this->click('_qf_Custom_next-bottom');
196 $this->waitForPageToLoad($this->getTimeoutMsec());
197
198 // go to step 7
199 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Premiums']");
200 $this->waitForElementPresent("_qf_Premium_next-bottom");
201
202 // fill in step 7 (Premiums)
203 $this->click('premiums_active');
204 $this->type('premiums_intro_title', "Prem Title $contributionTitle");
205 $this->type('premiums_intro_text', "Prem Introductory Message $contributionTitle");
206 $this->type('premiums_contact_email', "$contributionTitle@example.info");
207 $this->type('premiums_contact_phone', rand(100000000, 999999999));
208 $this->click('premiums_display_min_contribution');
209 $this->type('premiums_nothankyou_label', "No Thank you ");
210
211 $this->click('_qf_Premium_next-bottom');
212 $this->waitForPageToLoad($this->getTimeoutMsec());
213
214 // go to step 8
215 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Widgets']");
216 $this->waitForElementPresent("_qf_Widget_next-bottom");
217
218 // fill in step 8 (Widget Settings)
219 $this->click('is_active');
220 $this->type('url_logo', "URL to Logo Image $contributionTitle");
221 $this->type('button_title', "Button Title $contributionTitle");
222 $this->type('about', "About $contributionTitle");
223
224 $this->click('_qf_Widget_next-bottom');
225 $this->waitForPageToLoad($this->getTimeoutMsec());
226
227 // go to step 9
228 $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Personal Campaigns']");
229 $this->waitForElementPresent("_qf_Contribute_next-bottom");
230
231 // fill in step 9 (Enable Personal Campaign Pages)
232 $this->click('pcp_active');
233 $this->click('is_approval_needed');
234 $this->type('notify_email', "$contributionTitle@example.name");
235 $this->select('supporter_profile_id', 'value=2');
236 $this->type('tellfriend_limit', 7);
237 $this->type('link_text', "'Create Personal Campaign Page' link text $contributionTitle");
238
239 // submit new contribution page
240 $this->click('_qf_Contribute_next-bottom');
241 $this->waitForPageToLoad($this->getTimeoutMsec());
242
243 //get Url for Live Contribution Page
244 $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
245
246 //logout
42daf119 247 $this->webtestLogout();
6a488035
TO
248
249 //Open Live Contribution Page
554b655e 250 $this->openCiviPage($registerUrl['url'], $registerUrl['args'], NULL);
6a488035
TO
251 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
252 $lastName = 'An' . substr(sha1(rand()), 0, 7);
253
254 $this->type("email-5", $firstName . "@example.com");
255
256 $this->type("first_name", $firstName);
257 $this->type("last_name", $lastName);
258
259 $streetAddress = "100 Main Street";
260 $this->type("street_address-1", $streetAddress);
261 $this->type("city-1", "San Francisco");
262 $this->type("postal_code-1", "94117");
263 $this->select("country-1", "value=1228");
264 $this->select("state_province-1", "value=1001");
265
266 //Credit Card Info
267 $this->select("credit_card_type", "value=Visa");
268 $this->type("credit_card_number", "4111111111111111");
269 $this->type("cvv2", "000");
270 $this->select("credit_card_exp_date[M]", "value=1");
271 $this->select("credit_card_exp_date[Y]", "value=2020");
272
273 //Billing Info
274 $this->type("billing_first_name", $firstName . "billing");
275 $this->type("billing_last_name", $lastName . "billing");
276 $this->type("billing_street_address-5", "15 Main St.");
277 $this->type(" billing_city-5", "San Jose");
278 $this->select("billing_country_id-5", "value=1228");
279 $this->select("billing_state_province_id-5", "value=1004");
280 $this->type("billing_postal_code-5", "94129");
281 $this->click("_qf_Main_upload-bottom");
282
283 $this->waitForPageToLoad($this->getTimeoutMsec());
284 $this->waitForElementPresent("_qf_Confirm_next-bottom");
285
286 $this->click("_qf_Confirm_next-bottom");
287 $this->waitForPageToLoad($this->getTimeoutMsec());
288
289 //login to check contribution
6a488035
TO
290
291 // Log in using webtestLogin() method
292 $this->webtestLogin();
293
294 //Find Contribution
9042f10e 295 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
6a488035
TO
296
297 $this->type("sort_name", "$firstName $lastName");
298 $this->click("_qf_Search_refresh");
299
300 $this->waitForPageToLoad($this->getTimeoutMsec());
301
302 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
303 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
304 $this->waitForPageToLoad($this->getTimeoutMsec());
305 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
306
307 //View Contribution Record
308 $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[10]/td[2]", preg_quote($campaignTitle));
309 }
310
311 function _testVerifyRegisterPage($contributionPageTitle) {
9042f10e 312 $this->openCiviPage("admin/contribute", "reset=1", "_qf_SearchContribution_refresh");
6a488035
TO
313 $this->type('title', $contributionPageTitle);
314 $this->click("_qf_SearchContribution_refresh");
315 $this->waitForPageToLoad('50000');
42daf119
CW
316 $id = $this->getAttribute("//div[@id='configure_contribution_page']//table/tbody/tr/td/strong[text()='$contributionPageTitle']/../../td[5]/div/span/ul/li/a[text()='Title and Settings']@href");
317 $id = explode('id=', $id);
9042f10e 318 $registerUrl = array('url' => 'contribute/transact', 'args' => "reset=1&id=$id[1]");
6a488035
TO
319 return $registerUrl;
320 }
b9715b8a 321}