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