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