Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-04-00-48-43
[civicrm-core.git] / tests / phpunit / WebTest / Member / OnlineAutoRenewMembershipGCTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Member_OnlineAutoRenewMembershipGCTest 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.
f2ff7d84 39 $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom");
6a488035
TO
40
41 $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]");
42 $this->click("auto_renew");
43
44 $firstName = 'John';
45 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
46 $this->type('email-5', "{$lastName}@example.com");
47
225a8648 48 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next_checkout");
6a488035
TO
49
50 $text = 'I want this membership to be renewed automatically every 1 year(s).';
f2ff7d84 51 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
52
53 $this->click("_qf_Confirm_next_checkout");
efb29358
CW
54 // Because it tends to cause problems, all uses of sleep() must be justified in comments
55 // Sleep should never be used for wait for anything to load from the server
56 // Justification for this instance: FIXME
6a488035
TO
57 sleep(5);
58
76e86fd8
CW
59 // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case)
60
6a488035
TO
61 // has changed a bit. No point in adding test for external page as we 'll test with fake transactions.
62 }
63
64 function testOnlineAutoRenewMembershipAuthenticated() {
65 //configure membership signup page.
66 $pageId = $this->_configureMembershipPage();
67
6a488035
TO
68 $this->webtestLogin();
69 $this->waitForPageToLoad($this->getTimeoutMsec());
70
71 //now do the test membership signup.
f2ff7d84 72 $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom");
6a488035
TO
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 $firstName = 'John';
78 $lastName = 'Smith_' . substr(sha1(rand()), 0, 7);
79 $this->type('email-5', "{$lastName}@example.com");
80
225a8648 81 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next_checkout");
6a488035
TO
82
83 $text = 'I want this membership to be renewed automatically every 1 year(s).';
f2ff7d84 84 $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text);
6a488035
TO
85
86 $this->click("_qf_Confirm_next_checkout");
efb29358
CW
87 // Because it tends to cause problems, all uses of sleep() must be justified in comments
88 // Sleep should never be used for wait for anything to load from the server
89 // Justification for this instance: FIXME
6a488035
TO
90 sleep(5);
91
76e86fd8
CW
92 // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case)
93
6a488035
TO
94 // has changed a bit. No point in adding test for external page as we 'll test with fake transactions.
95 }
96
97 function _configureMembershipPage() {
98 static $pageId = NULL;
99
100 if (!$pageId) {
6a488035
TO
101 $this->webtestLogin();
102
103 //add payment processor.
42daf119
CW
104 $hash = substr(sha1(rand()), 0, 7);
105 $rand = 2 * rand(2, 50);
6a488035
TO
106 $processorName = "Webtest Auto Renew Google Checkout" . $hash;
107 $this->webtestAddPaymentProcessor($processorName, 'Google_Checkout');
108
109 // -- start updating membership types
76e86fd8
CW
110 $this->openCiviPage('admin/member/membershipType/add', 'action=update&id=1&reset=1');
111
6a488035
TO
112 $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')]");
113 $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')]");
76e86fd8 114
6a488035
TO
115 $this->type("duration_interval", "1");
116 $this->select("duration_unit", "label=year");
117
118 //wait for the auto-complete member_of_contact to populate
efb29358 119 $this->waitForValue('member_of_contact', '::');
76e86fd8 120
6a488035
TO
121 $this->click("_qf_MembershipType_upload-bottom");
122 $this->waitForPageToLoad($this->getTimeoutMsec());
123
76e86fd8
CW
124 $this->openCiviPage('admin/member/membershipType/add', 'action=update&id=2&reset=1');
125
6a488035
TO
126 $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')]");
127 $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')]");
128
129 $this->type("duration_interval", "1");
130 $this->select("duration_unit", "label=year");
131
132 //wait for the auto-complete member_of_contact to populate
efb29358 133 $this->waitForValue('member_of_contact', '::');
6a488035
TO
134
135 $this->click("_qf_MembershipType_upload-bottom");
136 $this->waitForPageToLoad($this->getTimeoutMsec());
137
138 // create contribution page with randomized title and default params
42daf119
CW
139 $amountSection = FALSE;
140 $payLater = TRUE;
141 $onBehalf = FALSE;
142 $pledges = FALSE;
143 $recurring = TRUE;
6a488035
TO
144 $membershipTypes = array(array('id' => 1, 'auto_renew' => 1),
145 array('id' => 2, 'auto_renew' => 1),
146 );
147 $memPriceSetId = NULL;
42daf119
CW
148 $friend = TRUE;
149 $profilePreId = NULL;
6a488035 150 $profilePostId = NULL;
42daf119
CW
151 $premiums = TRUE;
152 $widget = TRUE;
153 $pcp = TRUE;
6a488035
TO
154
155 $contributionTitle = "Title $hash";
156 $pageId = $this->webtestAddContributionPage($hash,
157 $rand,
158 $contributionTitle,
159 array($processorName => 'Google_Checkout'),
160 $amountSection,
161 $payLater,
162 $onBehalf,
163 $pledges,
164 $recurring,
165 $membershipTypes,
166 $memPriceSetId,
167 $friend,
168 $profilePreId,
169 $profilePostId,
170 $premiums,
171 $widget,
172 $pcp,
173 FALSE
174 );
175
6a488035
TO
176 //make sure we do have required permissions.
177 $permissions = array("edit-1-make-online-contributions");
178 $this->changePermissions($permissions);
179
180 // now logout and do membership test that way
42daf119 181 $this->webtestLogout();
6a488035
TO
182 }
183
184 return $pageId;
185 }
186}
187