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