Commit | Line | Data |
---|---|---|
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 |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class 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 | ||
4cbe18b8 EM |
116 | /** |
117 | * @param $campaignTitle | |
118 | * @param $id | |
119 | */ | |
6a488035 TO |
120 | function onlineContributionAddTest($campaignTitle, $id) { |
121 | // We need a payment processor | |
122 | $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7); | |
123 | $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName); | |
124 | ||
9042f10e | 125 | $this->openCiviPage("admin/contribute/add", "reset=1&action=add"); |
6a488035 TO |
126 | |
127 | $contributionTitle = substr(sha1(rand()), 0, 7); | |
128 | $rand = 2 * rand(2, 50); | |
129 | ||
130 | // fill in step 1 (Title and Settings) | |
131 | $contributionPageTitle = "Title $contributionTitle"; | |
132 | $this->type('title', $contributionPageTitle); | |
133 | $this->select( 'financial_type_id', 'value=1' ); | |
134 | ||
135 | // select campaign | |
136 | $this->click("campaign_id"); | |
137 | $this->select("campaign_id", "value=$id"); | |
138 | ||
139 | $this->fillRichTextField('intro_text', 'This is Test Introductory Message', 'CKEditor'); | |
140 | $this->fillRichTextField('footer_text', 'This is Test Footer Message', 'CKEditor'); | |
141 | ||
b45c587e CW |
142 | // Submit form |
143 | $this->clickLink('_qf_Settings_next', "_qf_Amount_next-bottom"); | |
144 | ||
145 | // Get contribution page id | |
146 | $pageId = $this->urlArg('id'); | |
6a488035 TO |
147 | |
148 | //this contribution page for online contribution | |
149 | $this->check("payment_processor[{$paymentProcessorId}]"); | |
9042f10e | 150 | $this->assertElementContainsText('crm-container', "Contribution Amounts section enabled"); |
6a488035 TO |
151 | $this->type("label_1", "amount 1"); |
152 | $this->type("value_1", "100"); | |
153 | $this->type("label_2", "amount 2"); | |
154 | $this->type("value_2", "200"); | |
701f18c0 | 155 | $this->click("xpath=//*[@id='map-field-table']//tr[2]//input[1][@name='default']"); |
6a488035 TO |
156 | |
157 | $this->click("_qf_Amount_next-bottom"); | |
158 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
159 | ||
160 | // go to step 4 | |
161 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Receipt']"); | |
162 | $this->waitForElementPresent('_qf_ThankYou_next-bottom'); | |
163 | ||
164 | // fill in step 4 (Thanks and Receipt) | |
165 | $this->type('thankyou_title', "Thank-you Page Title $contributionTitle"); | |
166 | $this->type('receipt_from_name', "Receipt From Name $contributionTitle"); | |
167 | $this->type('receipt_from_email', "$contributionTitle@example.org"); | |
168 | $this->type('receipt_text', "Receipt Message $contributionTitle"); | |
169 | $this->type('cc_receipt', "$contributionTitle@example.net"); | |
170 | $this->type('bcc_receipt', "$contributionTitle@example.com"); | |
171 | ||
172 | $this->click('_qf_ThankYou_next-bottom'); | |
173 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
174 | ||
175 | // go to step 5 | |
176 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Tell a Friend']"); | |
177 | $this->waitForElementPresent("_qf_Contribute_next-bottom"); | |
178 | ||
179 | // fill in step 5 (Tell a Friend) | |
180 | $this->click('tf_is_active'); | |
181 | $this->type('tf_title', "TaF Title $contributionTitle"); | |
182 | $this->type('intro', "TaF Introduction $contributionTitle"); | |
183 | $this->type('suggested_message', "TaF Suggested Message $contributionTitle"); | |
184 | $this->type('general_link', "TaF Info Page Link $contributionTitle"); | |
185 | $this->type('tf_thankyou_title', "TaF Thank-you Title $contributionTitle"); | |
186 | $this->type('tf_thankyou_text', "TaF Thank-you Message $contributionTitle"); | |
187 | ||
188 | $this->click('_qf_Contribute_next-bottom'); | |
189 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
190 | ||
191 | // go to step 6 | |
192 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Profiles']"); | |
193 | $this->waitForElementPresent("_qf_Custom_next-bottom"); | |
194 | ||
195 | // fill in step 6 (Include Profiles) | |
701f18c0 | 196 | $this->select('css=tr.crm-contribution-contributionpage-custom-form-block-custom_pre_id span.crm-profile-selector-select select', 'value=1'); |
6a488035 TO |
197 | |
198 | $this->click('_qf_Custom_next-bottom'); | |
199 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
200 | ||
201 | // go to step 7 | |
202 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Premiums']"); | |
203 | $this->waitForElementPresent("_qf_Premium_next-bottom"); | |
204 | ||
205 | // fill in step 7 (Premiums) | |
206 | $this->click('premiums_active'); | |
207 | $this->type('premiums_intro_title', "Prem Title $contributionTitle"); | |
208 | $this->type('premiums_intro_text', "Prem Introductory Message $contributionTitle"); | |
209 | $this->type('premiums_contact_email', "$contributionTitle@example.info"); | |
210 | $this->type('premiums_contact_phone', rand(100000000, 999999999)); | |
211 | $this->click('premiums_display_min_contribution'); | |
212 | $this->type('premiums_nothankyou_label', "No Thank you "); | |
213 | ||
214 | $this->click('_qf_Premium_next-bottom'); | |
215 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
216 | ||
217 | // go to step 8 | |
218 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Widgets']"); | |
219 | $this->waitForElementPresent("_qf_Widget_next-bottom"); | |
220 | ||
221 | // fill in step 8 (Widget Settings) | |
222 | $this->click('is_active'); | |
223 | $this->type('url_logo', "URL to Logo Image $contributionTitle"); | |
224 | $this->type('button_title', "Button Title $contributionTitle"); | |
225 | $this->type('about', "About $contributionTitle"); | |
226 | ||
227 | $this->click('_qf_Widget_next-bottom'); | |
228 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
229 | ||
230 | // go to step 9 | |
231 | $this->click("//div[@id='mainTabContainer']/ul//li/a[text()='Personal Campaigns']"); | |
232 | $this->waitForElementPresent("_qf_Contribute_next-bottom"); | |
233 | ||
234 | // fill in step 9 (Enable Personal Campaign Pages) | |
235 | $this->click('pcp_active'); | |
236 | $this->click('is_approval_needed'); | |
237 | $this->type('notify_email', "$contributionTitle@example.name"); | |
238 | $this->select('supporter_profile_id', 'value=2'); | |
239 | $this->type('tellfriend_limit', 7); | |
240 | $this->type('link_text', "'Create Personal Campaign Page' link text $contributionTitle"); | |
241 | ||
242 | // submit new contribution page | |
243 | $this->click('_qf_Contribute_next-bottom'); | |
244 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
245 | ||
b45c587e CW |
246 | // Make sure our page shows up in search results |
247 | $this->openCiviPage("admin/contribute", "reset=1", "_qf_SearchContribution_refresh"); | |
248 | $this->type('title', $contributionPageTitle); | |
249 | $this->click("_qf_SearchContribution_refresh"); | |
250 | $this->waitForPageToLoad(2 * $this->getTimeoutMsec()); | |
251 | $url = $this->assertElementContainsText("//div[@id='configure_contribution_page']//table/tbody", $contributionPageTitle); | |
6a488035 TO |
252 | |
253 | //logout | |
42daf119 | 254 | $this->webtestLogout(); |
6a488035 TO |
255 | |
256 | //Open Live Contribution Page | |
b45c587e CW |
257 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom'); |
258 | ||
6a488035 TO |
259 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); |
260 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
6a488035 TO |
261 | $this->type("first_name", $firstName); |
262 | $this->type("last_name", $lastName); | |
263 | ||
b45c587e CW |
264 | $this->type("email-5", $firstName . "@example.com"); |
265 | ||
6a488035 TO |
266 | $streetAddress = "100 Main Street"; |
267 | $this->type("street_address-1", $streetAddress); | |
268 | $this->type("city-1", "San Francisco"); | |
269 | $this->type("postal_code-1", "94117"); | |
270 | $this->select("country-1", "value=1228"); | |
271 | $this->select("state_province-1", "value=1001"); | |
272 | ||
273 | //Credit Card Info | |
274 | $this->select("credit_card_type", "value=Visa"); | |
275 | $this->type("credit_card_number", "4111111111111111"); | |
276 | $this->type("cvv2", "000"); | |
277 | $this->select("credit_card_exp_date[M]", "value=1"); | |
278 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
279 | ||
280 | //Billing Info | |
281 | $this->type("billing_first_name", $firstName . "billing"); | |
282 | $this->type("billing_last_name", $lastName . "billing"); | |
283 | $this->type("billing_street_address-5", "15 Main St."); | |
284 | $this->type(" billing_city-5", "San Jose"); | |
285 | $this->select("billing_country_id-5", "value=1228"); | |
286 | $this->select("billing_state_province_id-5", "value=1004"); | |
287 | $this->type("billing_postal_code-5", "94129"); | |
225a8648 | 288 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 | 289 | |
b45c587e | 290 | $this->clickLink("_qf_Confirm_next-bottom", NULL); |
6a488035 TO |
291 | |
292 | //login to check contribution | |
6a488035 TO |
293 | $this->webtestLogin(); |
294 | ||
295 | //Find Contribution | |
9042f10e | 296 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
6a488035 TO |
297 | |
298 | $this->type("sort_name", "$firstName $lastName"); | |
b45c587e | 299 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
701f18c0 | 300 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
6a488035 TO |
301 | |
302 | //View Contribution Record | |
303 | $this->verifyText("xpath=id('ContributionView')/div[2]/table[1]/tbody/tr[10]/td[2]", preg_quote($campaignTitle)); | |
304 | } | |
305 | ||
b9715b8a | 306 | } |