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