Commit | Line | Data |
---|---|---|
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 |
27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
28 | class 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 | ||
76e86fd8 | 118 | |
6a488035 TO |
119 | $this->click("_qf_MembershipType_upload-bottom"); |
120 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
121 | ||
76e86fd8 CW |
122 | $this->openCiviPage('admin/member/membershipType/add', 'action=update&id=2&reset=1'); |
123 | ||
6a488035 TO |
124 | $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')]"); |
125 | $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')]"); | |
126 | ||
127 | $this->type("duration_interval", "1"); | |
128 | $this->select("duration_unit", "label=year"); | |
129 | ||
6a488035 TO |
130 | |
131 | $this->click("_qf_MembershipType_upload-bottom"); | |
132 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
133 | ||
134 | // create contribution page with randomized title and default params | |
42daf119 CW |
135 | $amountSection = FALSE; |
136 | $payLater = TRUE; | |
137 | $onBehalf = FALSE; | |
138 | $pledges = FALSE; | |
139 | $recurring = TRUE; | |
6a488035 TO |
140 | $membershipTypes = array(array('id' => 1, 'auto_renew' => 1), |
141 | array('id' => 2, 'auto_renew' => 1), | |
142 | ); | |
143 | $memPriceSetId = NULL; | |
42daf119 CW |
144 | $friend = TRUE; |
145 | $profilePreId = NULL; | |
6a488035 | 146 | $profilePostId = NULL; |
42daf119 CW |
147 | $premiums = TRUE; |
148 | $widget = TRUE; | |
149 | $pcp = TRUE; | |
6a488035 TO |
150 | |
151 | $contributionTitle = "Title $hash"; | |
152 | $pageId = $this->webtestAddContributionPage($hash, | |
153 | $rand, | |
154 | $contributionTitle, | |
155 | array($processorName => 'Google_Checkout'), | |
156 | $amountSection, | |
157 | $payLater, | |
158 | $onBehalf, | |
159 | $pledges, | |
160 | $recurring, | |
161 | $membershipTypes, | |
162 | $memPriceSetId, | |
163 | $friend, | |
164 | $profilePreId, | |
165 | $profilePostId, | |
166 | $premiums, | |
167 | $widget, | |
168 | $pcp, | |
169 | FALSE | |
170 | ); | |
171 | ||
6a488035 | 172 | //make sure we do have required permissions. |
77a2a633 | 173 | $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms"); |
6a488035 TO |
174 | $this->changePermissions($permissions); |
175 | ||
176 | // now logout and do membership test that way | |
42daf119 | 177 | $this->webtestLogout(); |
6a488035 TO |
178 | } |
179 | ||
180 | return $pageId; | |
181 | } | |
182 | } | |
183 |