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