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_Member_OnlineMembershipCreateTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testOnlineMembershipCreate() {
35 //check for online contribution and profile listings permissions
36 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
37 $this->changePermissions($permissions);
39 // Log in as normal user
40 $this->webtestLogin();
42 // a random 7-char string and an even number to make this pass unique
43 $hash = substr(sha1(rand()), 0, 7);
44 $rand = 2 * rand(2, 50);
46 // We need a payment processor
47 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
49 // create contribution page with randomized title and default params
50 $amountSection = TRUE;
52 $allowOtherAmmount = FALSE;
57 $memPriceSetId = NULL;
60 $profilePostId = NULL;
64 $isSeparatePayment = TRUE;
65 $contributionTitle = "Title $hash";
66 $pageId = $this->webtestAddContributionPage($hash,
69 array($processorName => 'Dummy'),
90 // create two new membership types
91 $memTypeParams1 = $this->webtestAddMembershipType();
92 $memTypeTitle1 = $memTypeParams1['membership_type'];
93 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
94 $memTypeId1 = $memTypeId1[1];
96 $memTypeParams2 = $this->webtestAddMembershipType();
97 $memTypeTitle2 = $memTypeParams2['membership_type'];
98 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
99 $memTypeId2 = $memTypeId2[1];
101 // edit contribution page memberships tab to add two new membership types
102 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
103 $this->click("membership_type_$memTypeId1");
104 $this->click("membership_type_$memTypeId2");
105 $this->clickLink('_qf_MembershipBlock_next', '_qf_MembershipBlock_next-bottom');
106 $text = "'MembershipBlock' information has been saved.";
107 $this->waitForText('crm-notification-container', $text);
110 $this->webtestLogout();
112 // signup for membership 1
113 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
114 $lastName = 'An' . substr(sha1(rand()), 0, 7);
116 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $firstName, $lastName, $payLater, $hash);
118 // Log in using webtestLogin() method
119 $this->webtestLogin();
122 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
124 $this->type("sort_name", "$firstName $lastName");
125 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
126 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
127 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
129 //View Membership Record
131 'Member' => $firstName . ' ' . $lastName,
132 'Membership Type' => $memTypeTitle1,
133 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
136 $verifyData['Status'] = 'Pending';
140 $verifyData['Status'] = 'New';
142 $this->webtestVerifyTabularData($verifyData);
144 // Click View action link on associated contribution record
145 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
146 $this->click("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
147 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
148 //View Contribution Record
150 'From' => $firstName . ' ' . $lastName,
151 'Total Amount' => '$ 100.00',
154 $verifyData['Contribution Status'] = 'Pending : Pay Later';
157 $verifyData['Contribution Status'] = 'Completed';
159 $this->webtestVerifyTabularData($verifyData);
161 // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different)
163 $this->webtestLogout();
165 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash);
167 // Log in using webtestLogin() method
168 $this->webtestLogin();
171 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
173 $this->type("sort_name", "$firstName $lastName");
174 $this->click("_qf_Search_refresh");
176 $this->waitForPageToLoad($this->getTimeoutMsec());
177 $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results');
180 function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE) {
181 //Open Live Contribution Page
182 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
183 // Select membership type 1
184 $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label");
185 if ($memTypeId != 'No thank you') {
186 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'$memTypeId')]");
190 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
194 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
197 $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
200 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
202 $this->type("email-5", $firstName . "@example.com");
204 $this->type("first_name", $firstName);
205 $this->type("last_name", $lastName);
207 $streetAddress = "100 Main Street";
208 $this->type("street_address-1", $streetAddress);
209 $this->type("city-1", "San Francisco");
210 $this->type("postal_code-1", "94117");
211 $this->select("country-1", "value=1228");
212 $this->select("state_province-1", "value=1001");
215 $this->select("credit_card_type", "value=Visa");
216 $this->type("credit_card_number", "4111111111111111");
217 $this->type("cvv2", "000");
218 $this->select("credit_card_exp_date[M]", "value=1");
219 $this->select("credit_card_exp_date[Y]", "value=2020");
222 $this->type("billing_first_name", $firstName . "billing");
223 $this->type("billing_last_name", $lastName . "billing");
224 $this->type("billing_street_address-5", "15 Main St.");
225 $this->type(" billing_city-5", "San Jose");
226 $this->select("billing_country_id-5", "value=1228");
227 $this->select("billing_state_province_id-5", "value=1004");
228 $this->type("billing_postal_code-5", "94129");
230 $this->click("_qf_Main_upload-bottom");
231 $this->waitForElementPresent("_qf_Confirm_next-bottom");
233 $this->click("_qf_Confirm_next-bottom");
234 $this->waitForPageToLoad($this->getTimeoutMsec());
237 function testOnlineMembershipCreateWithContribution() {
238 //login with admin credentials & make sure we do have required permissions.
239 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
240 $this->changePermissions($permissions);
242 $hash = substr(sha1(rand()), 0, 7);
243 $rand = 2 * rand(2, 50);
244 // We need a payment processor
245 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
246 $amountSection = TRUE;
248 $allowOtherAmmount = TRUE;
253 $memPriceSetId = NULL;
256 $profilePostId = NULL;
260 $isSeparatePayment = FALSE;
261 $membershipsRequired = FALSE;
262 $fixedAmount = FALSE;
263 $contributionTitle = "Title $hash";
264 $pageId = $this->webtestAddContributionPage($hash,
267 array($processorName => 'Dummy'),
291 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
292 $lastName = 'An' . substr(sha1(rand()), 0, 7);
295 $this->webtestLogout();
297 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
299 // Log in using webtestLogin() method
300 $this->webtestLogin();
303 $this->openCiviPage("contribute/search","reset=1", "contribution_date_low");
305 $this->type("sort_name", "$firstName $lastName");
306 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
307 $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom");
309 //View Contribution Record and verify data
311 'From' => "{$firstName} {$lastName}",
312 'Financial Type' => 'Donation',
313 'Total Amount' => '50.00',
314 'Contribution Status' => 'Completed',
315 'Received Into' => 'Deposit Bank Account',
316 'Source' => "Online Contribution: $contributionTitle",
317 'Online Contribution Page' => $contributionTitle,
319 $this->webtestVerifyTabularData($expected);