3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Member_OnlineMembershipCreateTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testOnlineMembershipCreate() {
36 //check for online contribution and profile listings permissions
37 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
38 $this->changePermissions($permissions);
40 // Log in as normal user
41 $this->webtestLogin();
43 // a random 7-char string and an even number to make this pass unique
44 $hash = substr(sha1(rand()), 0, 7);
45 $rand = 2 * rand(2, 50);
47 // We need a payment processor
48 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
50 // create contribution page with randomized title and default params
51 $amountSection = TRUE;
53 $allowOtherAmmount = FALSE;
58 $memPriceSetId = NULL;
61 $profilePostId = NULL;
65 $isSeparatePayment = TRUE;
66 $contributionTitle = "Title $hash";
67 $pageId = $this->webtestAddContributionPage($hash,
70 array($processorName => 'Dummy'),
92 // create two new membership types
93 $memTypeParams1 = $this->webtestAddMembershipType();
94 $memTypeTitle1 = $memTypeParams1['membership_type'];
95 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
96 $memTypeId1 = $memTypeId1[1];
98 $memTypeParams2 = $this->webtestAddMembershipType();
99 $memTypeTitle2 = $memTypeParams2['membership_type'];
100 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
101 $memTypeId2 = $memTypeId2[1];
103 // edit contribution page memberships tab to add two new membership types
104 $this->openCiviPage("admin/contribute/membership", "reset=1&action=update&id={$pageId}", '_qf_MembershipBlock_next-bottom');
105 $this->click("membership_type_$memTypeId1");
106 $this->click("membership_type_$memTypeId2");
107 $this->click('_qf_MembershipBlock_next');
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->waitForElementPresent('_qf_MembershipBlock_next-bottom');
110 $text = "'MembershipBlock' information has been saved.";
111 $this->assertElementContainsText('crm-notification-container', $text, 'Missing text: ' . $text);
114 $this->webtestLogout();
116 // signup for membership 1
117 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
118 $lastName = 'An' . substr(sha1(rand()), 0, 7);
120 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle1, $firstName, $lastName, $payLater, $hash);
122 // Log in using webtestLogin() method
123 $this->webtestLogin();
126 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
128 $this->type("sort_name", "$firstName $lastName");
129 $this->click("_qf_Search_refresh");
131 $this->waitForPageToLoad($this->getTimeoutMsec());
133 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
134 $this->click("xpath=//div[@id='memberSearch']/table/tbody/tr/td[11]/span/a[text()='View']");
135 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
137 //View Membership Record
139 'Member' => $firstName . ' ' . $lastName,
140 'Membership Type' => $memTypeTitle1,
141 'Source' => 'Online Contribution:' . ' ' . $contributionTitle,
144 $verifyData['Status'] = 'Pending';
147 $verifyData['Status'] = 'New';
149 $this->webtestVerifyTabularData($verifyData);
151 // Click View action link on associated contribution record
152 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
153 $this->click("xpath=//form[@id='MembershipView']/div[2]/div/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
154 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
155 //View Contribution Record
157 'From' => $firstName . ' ' . $lastName,
158 'Total Amount' => '$ 100.00',
161 $verifyData['Contribution Status'] = 'Pending : Pay Later';
164 $verifyData['Contribution Status'] = 'Completed';
166 $this->webtestVerifyTabularData($verifyData);
168 // CRM-8141 signup for membership 2 with same anonymous user info (should create 2 separate membership records because membership orgs are different)
170 $this->webtestLogout();
172 $this->_testOnlineMembershipSignup($pageId, $memTypeTitle2, $firstName, $lastName, $payLater, $hash);
174 // Log in using webtestLogin() method
175 $this->webtestLogin();
178 $this->openCiviPage("member/search", "reset=1", "member_end_date_high");
180 $this->type("sort_name", "$firstName $lastName");
181 $this->click("_qf_Search_refresh");
183 $this->waitForPageToLoad($this->getTimeoutMsec());
184 $this->assertElementContainsText('search-status', '2 Results', 'Missing text: ' . '2 Results');
187 function _testOnlineMembershipSignup($pageId, $memTypeId, $firstName, $lastName, $payLater, $hash, $otherAmount = FALSE) {
188 //Open Live Contribution Page
189 $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom");
190 // Select membership type 1
191 $this->waitForElementPresent("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label");
192 if ($memTypeId != 'No thank you') {
193 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'$memTypeId')]");
196 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label[contains(text(),'$memTypeId')]");
199 $this->click("xpath=//div[@class='crm-section contribution_amount-section']/div[2]//span/label[text()='No thank you']");
202 $this->type("xpath=//div[@class='content other_amount-content']/input", $otherAmount);
205 $this->click("xpath=//div[@class='crm-section payment_processor-section']/div[2]//label[text()='Pay later label {$hash}']");
207 $this->type("email-5", $firstName . "@example.com");
209 $this->type("first_name", $firstName);
210 $this->type("last_name", $lastName);
212 $streetAddress = "100 Main Street";
213 $this->type("street_address-1", $streetAddress);
214 $this->type("city-1", "San Francisco");
215 $this->type("postal_code-1", "94117");
216 $this->select("country-1", "value=1228");
217 $this->select("state_province-1", "value=1001");
220 $this->select("credit_card_type", "value=Visa");
221 $this->type("credit_card_number", "4111111111111111");
222 $this->type("cvv2", "000");
223 $this->select("credit_card_exp_date[M]", "value=1");
224 $this->select("credit_card_exp_date[Y]", "value=2020");
227 $this->type("billing_first_name", $firstName . "billing");
228 $this->type("billing_last_name", $lastName . "billing");
229 $this->type("billing_street_address-5", "15 Main St.");
230 $this->type(" billing_city-5", "San Jose");
231 $this->select("billing_country_id-5", "value=1228");
232 $this->select("billing_state_province_id-5", "value=1004");
233 $this->type("billing_postal_code-5", "94129");
235 $this->click("_qf_Main_upload-bottom");
236 $this->waitForElementPresent("_qf_Confirm_next-bottom");
238 $this->click("_qf_Confirm_next-bottom");
239 $this->waitForPageToLoad($this->getTimeoutMsec());
242 function testOnlineMembershipCreateWithContribution() {
243 //login with admin credentials & make sure we do have required permissions.
244 $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms");
245 $this->changePermissions($permissions);
247 $hash = substr(sha1(rand()), 0, 7);
248 $rand = 2 * rand(2, 50);
249 // We need a payment processor
250 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
251 $amountSection = TRUE;
253 $allowOtherAmmount = TRUE;
258 $memPriceSetId = NULL;
261 $profilePostId = NULL;
265 $isSeparatePayment = FALSE;
266 $membershipsRequired = FALSE;
267 $fixedAmount = FALSE;
268 $contributionTitle = "Title $hash";
269 $pageId = $this->webtestAddContributionPage($hash,
272 array($processorName => 'Dummy'),
296 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
297 $lastName = 'An' . substr(sha1(rand()), 0, 7);
300 $this->webtestLogout();
302 $this->_testOnlineMembershipSignup($pageId, 'No thank you', $firstName, $lastName, FALSE, $hash, 50);
304 // Log in using webtestLogin() method
305 $this->webtestLogin();
308 $this->openCiviPage("contribute/search","reset=1", "contribution_date_low");
310 $this->type("sort_name", "$firstName $lastName");
311 $this->click("_qf_Search_refresh");
312 $this->waitForPageToLoad($this->getTimeoutMsec());
314 $this->waitForElementPresent("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
315 $this->click("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']");
316 $this->waitForPageToLoad($this->getTimeoutMsec());
317 $this->waitForElementPresent("_qf_ContributionView_cancel-bottom");
319 //View Contribution Record and verify data
321 'From' => "{$firstName} {$lastName}",
322 'Financial Type' => 'Donation',
323 'Total Amount' => '50.00',
324 'Contribution Status' => 'Completed',
325 'Received Into' => 'Deposit Bank Account',
326 'Source' => "Online Contribution: $contributionTitle",
327 'Online Contribution Page' => $contributionTitle,
329 $this->webtestVerifyTabularData($expected);