3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contribute_OnlineContributionTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testOnlineContributionAdd() {
35 $this->webtestLogin();
37 // We need a payment processor
38 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
39 $processorType = 'Dummy';
40 $pageTitle = substr(sha1(rand()), 0, 7);
41 $rand = 2 * rand(10, 50);
42 $hash = substr(sha1(rand()), 0, 7);
43 $amountSection = TRUE;
51 $profilePostId = NULL;
55 $memPriceSetId = NULL;
57 // create a new online contribution page
58 // create contribution page with randomized title and default params
59 $pageId = $this->webtestAddContributionPage($hash,
62 array($processorName => $processorType),
79 $this->webtestLogout();
81 //Open Live Contribution Page
82 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
84 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
85 $lastName = 'An' . substr(sha1(rand()), 0, 7);
86 $honorFirstName = 'In' . substr(sha1(rand()), 0, 4);
87 $honorLastName = 'Hon' . substr(sha1(rand()), 0, 7);
88 $honorEmail = $honorFirstName . "@example.com";
89 $honorSortName = $honorLastName . ', ' . $honorFirstName;
90 $honorDisplayName = 'Ms. ' . $honorFirstName . ' ' . $honorLastName;
92 $this->type("email-5", $firstName . "@example.com");
94 $this->type("first_name", $firstName);
95 $this->type("last_name", $lastName);
97 $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input");
98 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100);
100 $streetAddress = "100 Main Street";
101 $this->type("street_address-1", $streetAddress);
102 $this->type("city-1", "San Francisco");
103 $this->type("postal_code-1", "94117");
104 $this->select("country-1", "value=1228");
105 $this->select("state_province-1", "value=1001");
108 $this->click("xpath=id('Main')/div[2]/fieldset/div[2]/div/label[text()='In Honor of']");
109 $this->waitForElementPresent("honor_email");
111 $this->select("honor_prefix_id", "label=Ms.");
112 $this->type("honor_first_name", $honorFirstName);
113 $this->type("honor_last_name", $honorLastName);
114 $this->type("honor_email", $honorEmail);
117 $this->select("credit_card_type", "value=Visa");
118 $this->type("credit_card_number", "4111111111111111");
119 $this->type("cvv2", "000");
120 $this->select("credit_card_exp_date[M]", "value=1");
121 $this->select("credit_card_exp_date[Y]", "value=2020");
124 $this->type("billing_first_name", $firstName . "billing");
125 $this->type("billing_last_name", $lastName . "billing");
126 $this->type("billing_street_address-5", "15 Main St.");
127 $this->type(" billing_city-5", "San Jose");
128 $this->select("billing_country_id-5", "value=1228");
129 $this->select("billing_state_province_id-5", "value=1004");
130 $this->type("billing_postal_code-5", "94129");
131 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
133 $this->click("_qf_Confirm_next-bottom");
134 $this->waitForPageToLoad($this->getTimeoutMsec());
136 //login to check contribution
138 // Log in using webtestLogin() method
139 $this->webtestLogin();
142 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
144 $this->type("sort_name", "$firstName $lastName");
145 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
146 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
148 //View Contribution Record and verify data
150 'From' => "{$firstName} {$lastName}",
151 'Financial Type' => 'Donation',
152 'Total Amount' => '100.00',
153 'Contribution Status' => 'Completed',
154 'In Honor of' => $honorDisplayName
156 $this->webtestVerifyTabularData($expected);
158 // Check for Honoree contact created
159 $this->click("css=input#sort_name_navigation");
160 $this->type("css=input#sort_name_navigation", $honorSortName);
161 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
163 // wait for result list
164 $this->waitForElementPresent("css=div.ac_results-inner li");
166 // visit contact summary page
167 $this->click("css=div.ac_results-inner li");
168 $this->waitForPageToLoad($this->getTimeoutMsec());
170 // Is contact present?
171 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
175 function testOnlineContributionWithZeroAmount () {
176 $this->webtestLogin();
178 // We need a payment processor
179 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
180 $processorType = 'Dummy';
181 $pageTitle = substr(sha1(rand()), 0, 7);
182 $rand = 2 * rand(10, 50);
183 $hash = substr(sha1(rand()), 0, 7);
184 $amountSection = TRUE;
189 $memberships = FALSE;
191 $profilePreId = NULL;
192 $profilePostId = NULL;
196 $memPriceSetId = NULL;
198 // create a new online contribution page
199 // create contribution page with randomized title and default params
200 $pageId = $this->webtestAddContributionPage($hash,
203 array($processorName => $processorType),
219 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
220 $this->type('label_1', "Label $hash");
221 $this->type('value_1', 0);
222 $this->clickLink('_qf_Amount_upload_done-top');
224 //Contribution using Contribution Options
225 $this->_doContributionAndVerifyData($pageId);
228 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
229 $this->type('title', "Test Priceset $rand");
230 $this->check('extends_2');
231 $this->select("financial_type_id", "label=Donation");
232 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
233 $sid = $this->urlArg('sid');
235 $this->type('label', "Testfield");
236 $this->select('html_type', "value=Radio");
237 $this->type('option_label_1', 'test Label');
238 $this->type('option_amount_1', 0.00);
239 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
240 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
241 $this->select('price_set_id', "value=$sid");
242 $this->clickLink('_qf_Amount_upload_done-bottom');
244 //Contribution using priceset
245 $this->_doContributionAndVerifyData($pageId, TRUE);
248 function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
250 $this->webtestLogout();
251 $amountLabel = 'Total Amount';
252 $amountValue = '0.00';
253 //Open Live Contribution Page
254 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
256 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
257 $lastName = 'An' . substr(sha1(rand()), 0, 7);
259 $this->type("email-5", $firstName . "@example.com");
262 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
263 $amountLabel = 'Contribution Amount';
264 $amountValue = 'Contribution Total: $ 0.00';
268 $this->select("credit_card_type", "value=Visa");
269 $this->type("credit_card_number", "4111111111111111");
270 $this->type("cvv2", "000");
271 $this->select("credit_card_exp_date[M]", "value=1");
272 $this->select("credit_card_exp_date[Y]", "value=2020");
275 $this->type("billing_first_name", $firstName);
276 $this->type("billing_last_name", $lastName);
277 $this->type("billing_street_address-5", "15 Main St.");
278 $this->type(" billing_city-5", "San Jose");
279 $this->select("billing_country_id-5", "value=1228");
280 $this->select("billing_state_province_id-5", "value=1004");
281 $this->type("billing_postal_code-5", "94129");
282 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
284 $this->clickLink("_qf_Confirm_next-bottom", NULL);
287 //login to check contribution
289 // Log in using webtestLogin() method
290 $this->webtestLogin();
293 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
295 $this->type("sort_name", "$firstName $lastName");
296 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
297 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
299 //View Contribution Record and verify data
301 'From' => "{$firstName} {$lastName}",
302 'Financial Type' => 'Donation',
303 $amountLabel => $amountValue,
304 'Contribution Status' => 'Completed'
306 $this->webtestVerifyTabularData($expected);