Fixed some contribution pages
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineAutoRenewMembershipTest.php
CommitLineData
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
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Member_OnlineAutoRenewMembershipTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testOnlineAutoRenewMembershipAnonymous() {
36 //configure membership signup page.
37 $pageId = $this->_configureMembershipPage();
38
39 //now do the test membership signup.
f2ff7d84
PJ
40 $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom");
41
6a488035
TO
42 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]");
43
44 $this->click("auto_renew");
45
46 $this->webtestAddCreditCardDetails();
47
48 list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails();
49
50 $this->type('email-5', "{$lastName}@example.com");
51
52 $this->click("_qf_Main_upload-bottom");
53 $this->waitForPageToLoad($this->getTimeoutMsec());
54 $this->waitForElementPresent("_qf_Confirm_next-bottom");
55
56 $text = 'I want this membership to be renewed automatically every 1 year(s).';
f2ff7d84 57 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
58
59 $this->click("_qf_Confirm_next-bottom");
60 $this->waitForPageToLoad($this->getTimeoutMsec());
61
62 $text = 'This membership will be renewed automatically every 1 year(s).';
f2ff7d84 63 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
64 }
65
66 function testOnlineAutoRenewMembershipAuthenticated() {
67 //configure membership signup page.
68 $pageId = $this->_configureMembershipPage();
69
6a488035
TO
70 $this->webtestLogin();
71 $this->waitForPageToLoad($this->getTimeoutMsec());
72
73 //now do the test membership signup.
f2ff7d84
PJ
74 $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom");
75
6a488035
TO
76 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]");
77
78 $this->click("auto_renew");
79
80 $this->webtestAddCreditCardDetails();
81
82 list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails();
83
84 $this->type('email-5', "{$lastName}@example.com");
85
86 $this->click("_qf_Main_upload-bottom");
6a488035
TO
87 $this->waitForElementPresent("_qf_Confirm_next-bottom");
88
89 $text = 'I want this membership to be renewed automatically every 1 year(s).';
f2ff7d84 90 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
91
92 $this->click("_qf_Confirm_next-bottom");
93 $this->waitForPageToLoad($this->getTimeoutMsec());
94
95 $text = 'This membership will be renewed automatically every 1 year(s).';
f2ff7d84 96 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
97 }
98
99 function testOnlinePendingAutoRenewMembershipAnonymous() {
100 //configure membership signup page.
101 $pageId = $this->_configureMembershipPage();
102
103 //now do the test membership signup.
f2ff7d84
PJ
104 $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom");
105
6a488035
TO
106 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]");
107
108 $this->click("auto_renew");
109
110 $this->webtestAddCreditCardDetails();
111 list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails();
112 $this->type('email-5', "{$lastName}@example.com");
113
114 $this->click("_qf_Main_upload-bottom");
6a488035
TO
115 $this->waitForElementPresent("_qf_Confirm_next-bottom");
116
117 $text = 'I want this membership to be renewed automatically every 1 year(s).';
f2ff7d84 118 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
119
120 $this->click("_qf_Confirm_next-bottom");
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122
123 $text = 'This membership will be renewed automatically every 1 year(s).';
f2ff7d84 124 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
125 }
126
127 function _configureMembershipPage() {
128 static $pageId = NULL;
129
130 if (!$pageId) {
42daf119 131 $this->webtestLogin();
6a488035
TO
132
133 //add payment processor.
42daf119
CW
134 $hash = substr(sha1(rand()), 0, 7);
135 $rand = 2 * rand(2, 50);
6a488035
TO
136 $processorName = "Webtest Auto Renew AuthNet" . $hash;
137 $this->webtestAddPaymentProcessor($processorName, 'AuthNet');
138
139 // -- start updating membership types
f2ff7d84 140 $this->openCiviPage('admin/member/membershipType/add', "action=update&id=1&reset=1", "_qf_MembershipType_upload-bottom");
6a488035 141
6a488035
TO
142 $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]");
143
144 $this->type("duration_interval", "1");
145 $this->select("duration_unit", "label=year");
146
efb29358
CW
147 // wait for the auto-complete member_of_contact to populate
148 $this->waitForValue('member_of_contact', '::');
6a488035
TO
149
150 $this->click("_qf_MembershipType_upload-bottom");
151 $this->waitForPageToLoad($this->getTimeoutMsec());
152
f2ff7d84 153 $this->openCiviPage('admin/member/membershipType/add', "action=update&id=2&reset=1", "_qf_MembershipType_upload-bottom");
6a488035 154
6a488035
TO
155 $this->click("xpath=//div[@id='membership_type_form']//table/tbody/tr[6]/td/label[contains(text(), 'Auto-renew Option')]/../../td[2]/label[contains(text(), 'Give option, but not required')]");
156
157 $this->type("duration_interval", "1");
158 $this->select("duration_unit", "label=year");
159
160 //wait for the auto-complete member_of_contact to populate
efb29358 161 $this->waitForValue('member_of_contact', '::');
6a488035
TO
162
163 $this->click("_qf_MembershipType_upload-bottom");
164 $this->waitForPageToLoad($this->getTimeoutMsec());
165
6a488035 166 // create contribution page with randomized title and default params
42daf119
CW
167 $amountSection = FALSE;
168 $payLater = TRUE;
169 $onBehalf = FALSE;
170 $pledges = FALSE;
171 $recurring = TRUE;
6a488035
TO
172 $membershipTypes = array(array('id' => 1, 'auto_renew' => 1),
173 array('id' => 2, 'auto_renew' => 1),
174 );
175 $memPriceSetId = NULL;
42daf119
CW
176 $friend = TRUE;
177 $profilePreId = NULL;
6a488035 178 $profilePostId = NULL;
42daf119
CW
179 $premiums = TRUE;
180 $widget = TRUE;
181 $pcp = TRUE;
6a488035
TO
182
183 $contributionTitle = "Title $hash";
184 $pageId = $this->webtestAddContributionPage($hash,
185 $rand,
186 $contributionTitle,
187 array($processorName => 'AuthNet'),
188 $amountSection,
189 $payLater,
190 $onBehalf,
191 $pledges,
192 $recurring,
193 $membershipTypes,
194 $memPriceSetId,
195 $friend,
196 $profilePreId,
197 $profilePostId,
198 $premiums,
199 $widget,
200 $pcp,
201 FALSE
202 );
203
204 //make sure we do have required permissions.
205 $permissions = array("edit-1-make-online-contributions");
206 $this->changePermissions($permissions);
207
208 // now logout and do membership test that way
42daf119 209 $this->webtestLogout();
6a488035
TO
210 }
211
212 return $pageId;
213 }
214}
215