3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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']");
110 $this->select("honor[prefix_id]", "label=Ms.");
111 $this->type("honor[first_name]", $honorFirstName);
112 $this->type("honor[last_name]", $honorLastName);
113 $this->type("honor[email-1]", $honorEmail);
116 $this->select("credit_card_type", "value=Visa");
117 $this->type("credit_card_number", "4111111111111111");
118 $this->type("cvv2", "000");
119 $this->select("credit_card_exp_date[M]", "value=1");
120 $this->select("credit_card_exp_date[Y]", "value=2020");
123 $this->type("billing_first_name", $firstName . "billing");
124 $this->type("billing_last_name", $lastName . "billing");
125 $this->type("billing_street_address-5", "15 Main St.");
126 $this->type(" billing_city-5", "San Jose");
127 $this->select("billing_country_id-5", "value=1228");
128 $this->select("billing_state_province_id-5", "value=1004");
129 $this->type("billing_postal_code-5", "94129");
130 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
132 $this->click("_qf_Confirm_next-bottom");
133 $this->waitForPageToLoad($this->getTimeoutMsec());
135 //login to check contribution
137 // Log in using webtestLogin() method
138 $this->webtestLogin();
141 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
143 $this->type("sort_name", "$firstName $lastName");
144 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
145 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
147 //View Contribution Record and verify data
149 'From' => "{$firstName} {$lastName}",
150 'Financial Type' => 'Donation',
151 'Total Amount' => '100.00',
152 'Contribution Status' => 'Completed',
154 $this->webtestVerifyTabularData($expected);
156 //View Soft Credit record of type 'Honor of'
157 $this->waitForTextPresent($honorDisplayName);
158 $this->waitForTextPresent('100.00 (In Honor of)');
160 // Check for Honoree contact created
161 $this->click("css=input#sort_name_navigation");
162 $this->type("css=input#sort_name_navigation", $honorSortName);
163 $this->typeKeys("css=input#sort_name_navigation", $honorSortName);
165 // wait for result list
166 $this->waitForElementPresent("css=div.ac_results-inner li");
168 // visit contact summary page
169 $this->click("css=div.ac_results-inner li");
170 $this->waitForPageToLoad($this->getTimeoutMsec());
172 // Is contact present?
173 $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found.");
177 function testOnlineContributionWithZeroAmount () {
178 $this->webtestLogin();
180 // We need a payment processor
181 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
182 $processorType = 'Dummy';
183 $pageTitle = substr(sha1(rand()), 0, 7);
184 $rand = 2 * rand(10, 50);
185 $hash = substr(sha1(rand()), 0, 7);
186 $amountSection = TRUE;
191 $memberships = FALSE;
193 $profilePreId = NULL;
194 $profilePostId = NULL;
198 $memPriceSetId = NULL;
200 // create a new online contribution page
201 // create contribution page with randomized title and default params
202 $pageId = $this->webtestAddContributionPage($hash,
205 array($processorName => $processorType),
221 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
222 $this->type('label_1', "Label $hash");
223 $this->type('value_1', 0);
224 $this->clickLink('_qf_Amount_upload_done-top');
226 //Contribution using Contribution Options
227 $this->_doContributionAndVerifyData($pageId);
230 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
231 $this->type('title', "Test Priceset $rand");
232 $this->check('extends_2');
233 $this->select("financial_type_id", "label=Donation");
234 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
235 $sid = $this->urlArg('sid');
237 $this->type('label', "Testfield");
238 $this->select('html_type', "value=Radio");
239 $this->type('option_label_1', 'test Label');
240 $this->type('option_amount_1', 0.00);
241 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
242 $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom');
243 $this->select('price_set_id', "value=$sid");
244 $this->clickLink('_qf_Amount_upload_done-bottom');
246 //Contribution using priceset
247 $this->_doContributionAndVerifyData($pageId, TRUE);
250 function _doContributionAndVerifyData($pageId, $priceSet = FALSE) {
252 $this->webtestLogout();
253 $amountLabel = 'Total Amount';
254 $amountValue = '0.00';
255 //Open Live Contribution Page
256 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
258 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
259 $lastName = 'An' . substr(sha1(rand()), 0, 7);
261 $this->type("email-5", $firstName . "@example.com");
264 $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input");
265 $amountLabel = 'Contribution Amount';
266 $amountValue = 'Contribution Total: $ 0.00';
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");
277 $this->type("billing_first_name", $firstName);
278 $this->type("billing_last_name", $lastName);
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");
284 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
286 $this->clickLink("_qf_Confirm_next-bottom", NULL);
289 //login to check contribution
291 // Log in using webtestLogin() method
292 $this->webtestLogin();
295 $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low");
297 $this->type("sort_name", "$firstName $lastName");
298 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
299 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
301 //View Contribution Record and verify data
303 'From' => "{$firstName} {$lastName}",
304 'Financial Type' => 'Donation',
305 $amountLabel => $amountValue,
306 'Contribution Status' => 'Completed'
308 $this->webtestVerifyTabularData($expected);