Merge pull request #84 from pradpnayak/CRM-12018
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineAutoRenewMembershipGCTest.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_OnlineAutoRenewMembershipGCTest 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->open($this->sboxPath . "civicrm/contribute/transact?reset=1&action=preview&id={$pageId}");
41 $this->waitForPageToLoad("3000");
42 $this->waitForElementPresent("_qf_Main_upload-bottom");
43
44 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]");
45 $this->click("auto_renew");
46
47 $firstName = 'John';
48 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
49 $this->type('email-5', "{$lastName}@example.com");
50
51 $this->click("_qf_Main_upload-bottom");
52 $this->waitForPageToLoad($this->getTimeoutMsec());
53 $this->waitForElementPresent("_qf_Confirm_next_checkout");
54
55 $text = 'I want this membership to be renewed automatically every 1 year(s).';
56 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
57
58 $this->click("_qf_Confirm_next_checkout");
59 sleep(5);
60
61 // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case)
62 // has changed a bit. No point in adding test for external page as we 'll test with fake transactions.
63 }
64
65 function testOnlineAutoRenewMembershipAuthenticated() {
66 //configure membership signup page.
67 $pageId = $this->_configureMembershipPage();
68
69 $this->open($this->sboxPath);
70 $this->webtestLogin();
71 $this->waitForPageToLoad($this->getTimeoutMsec());
72
73 //now do the test membership signup.
74 $this->open($this->sboxPath . "civicrm/contribute/transact?reset=1&action=preview&id={$pageId}");
75 $this->waitForPageToLoad("3000");
76 $this->waitForElementPresent("_qf_Main_upload-bottom");
77
78 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]");
79
80 $this->click("auto_renew");
81
82 $firstName = 'John';
83 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
84 $this->type('email-5', "{$lastName}@example.com");
85
86 $this->click("_qf_Main_upload-bottom");
87 $this->waitForPageToLoad($this->getTimeoutMsec());
88 $this->waitForElementPresent("_qf_Confirm_next_checkout");
89
90 $text = 'I want this membership to be renewed automatically every 1 year(s).';
91 $this->assertTrue($this->isTextPresent($text), 'Missing text: ' . $text);
92
93 $this->click("_qf_Confirm_next_checkout");
94 sleep(5);
95
96 // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case)
97 // has changed a bit. No point in adding test for external page as we 'll test with fake transactions.
98 }
99
100 function _configureMembershipPage() {
101 static $pageId = NULL;
102
103 if (!$pageId) {
104 $this->open($this->sboxPath);
105 $this->webtestLogin();
106
107 //add payment processor.
108 $hash = substr(sha1(rand()), 0, 7);
109 $rand = 2 * rand(2, 50);
110 $processorName = "Webtest Auto Renew Google Checkout" . $hash;
111 $this->webtestAddPaymentProcessor($processorName, 'Google_Checkout');
112
113 // -- start updating membership types
114 $this->open($this->sboxPath . "civicrm/admin/member/membershipType/add?action=update&id=1&reset=1");
115 $this->waitForPageToLoad($this->getTimeoutMsec());
116
117 $this->waitForElementPresent("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')]");
118 $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')]");
119
120 $this->type("duration_interval", "1");
121 $this->select("duration_unit", "label=year");
122
123 //wait for the auto-complete member_of_contact to populate
124 sleep(3);
125
126 $this->click("_qf_MembershipType_upload-bottom");
127 $this->waitForPageToLoad($this->getTimeoutMsec());
128
129 $this->open($this->sboxPath . "civicrm/admin/member/membershipType/add?action=update&id=2&reset=1");
130 $this->waitForPageToLoad($this->getTimeoutMsec());
131
132 $this->waitForElementPresent("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')]");
133 $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')]");
134
135 $this->type("duration_interval", "1");
136 $this->select("duration_unit", "label=year");
137
138 //wait for the auto-complete member_of_contact to populate
139 sleep(3);
140
141 $this->click("_qf_MembershipType_upload-bottom");
142 $this->waitForPageToLoad($this->getTimeoutMsec());
143
144 // create contribution page with randomized title and default params
145 $amountSection = FALSE;
146 $payLater = TRUE;
147 $onBehalf = FALSE;
148 $pledges = FALSE;
149 $recurring = TRUE;
150 $membershipTypes = array(array('id' => 1, 'auto_renew' => 1),
151 array('id' => 2, 'auto_renew' => 1),
152 );
153 $memPriceSetId = NULL;
154 $friend = TRUE;
155 $profilePreId = NULL;
156 $profilePostId = NULL;
157 $premiums = TRUE;
158 $widget = TRUE;
159 $pcp = TRUE;
160
161 $contributionTitle = "Title $hash";
162 $pageId = $this->webtestAddContributionPage($hash,
163 $rand,
164 $contributionTitle,
165 array($processorName => 'Google_Checkout'),
166 $amountSection,
167 $payLater,
168 $onBehalf,
169 $pledges,
170 $recurring,
171 $membershipTypes,
172 $memPriceSetId,
173 $friend,
174 $profilePreId,
175 $profilePostId,
176 $premiums,
177 $widget,
178 $pcp,
179 FALSE
180 );
181
182 // now logout and login with admin credentials
183 $this->open($this->sboxPath . "civicrm/logout?reset=1");
184 $this->waitForPageToLoad($this->getTimeoutMsec());
185
186 //make sure we do have required permissions.
187 $permissions = array("edit-1-make-online-contributions");
188 $this->changePermissions($permissions);
189
190 // now logout and do membership test that way
191 $this->open($this->sboxPath . "civicrm/logout?reset=1");
192 $this->waitForPageToLoad($this->getTimeoutMsec());
193 }
194
195 return $pageId;
196 }
197}
198