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