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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Member_OnlineAutoRenewMembershipGCTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Member_OnlineAutoRenewMembershipGCTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testOnlineAutoRenewMembershipAnonymous() { | |
39 | //configure membership signup page. | |
40 | $pageId = $this->_configureMembershipPage(); | |
41 | ||
42 | //now do the test membership signup. | |
f2ff7d84 | 43 | $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom"); |
6a488035 TO |
44 | |
45 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]"); | |
46 | $this->click("auto_renew"); | |
47 | ||
48 | $firstName = 'John'; | |
49 | $lastName = 'Smith_' . substr(sha1(rand()), 0, 7); | |
50 | $this->type('email-5', "{$lastName}@example.com"); | |
51 | ||
225a8648 | 52 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next_checkout"); |
6a488035 TO |
53 | |
54 | $text = 'I want this membership to be renewed automatically every 1 year(s).'; | |
f2ff7d84 | 55 | $this->assertElementContainsText('css=div.display-block', $text, 'Missing text: ' . $text); |
6a488035 TO |
56 | |
57 | $this->click("_qf_Confirm_next_checkout"); | |
efb29358 CW |
58 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
59 | // Sleep should never be used for wait for anything to load from the server | |
60 | // Justification for this instance: FIXME | |
6a488035 TO |
61 | sleep(5); |
62 | ||
76e86fd8 CW |
63 | // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case) |
64 | ||
6a488035 TO |
65 | // has changed a bit. No point in adding test for external page as we 'll test with fake transactions. |
66 | } | |
67 | ||
68 | function testOnlineAutoRenewMembershipAuthenticated() { | |
69 | //configure membership signup page. | |
70 | $pageId = $this->_configureMembershipPage(); | |
71 | ||
6a488035 TO |
72 | $this->webtestLogin(); |
73 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
74 | ||
75 | //now do the test membership signup. | |
f2ff7d84 | 76 | $this->openCiviPage('contribute/transact', "reset=1&action=preview&id={$pageId}", "_qf_Main_upload-bottom"); |
6a488035 TO |
77 | $this->click("xpath=//div[@class='crm-section membership_amount-section']/div[2]//span/label/span[2][contains(text(),'Student')]"); |
78 | ||
79 | $this->click("auto_renew"); | |
80 | ||
81 | $firstName = 'John'; | |
82 | $lastName = 'Smith_' . substr(sha1(rand()), 0, 7); | |
83 | $this->type('email-5', "{$lastName}@example.com"); | |
84 | ||
225a8648 | 85 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next_checkout"); |
6a488035 TO |
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 | ||
76e86fd8 CW |
96 | // FIXME: By this time pending records has already been created. Formatting for external page (google checkout in this case) |
97 | ||
6a488035 TO |
98 | // has changed a bit. No point in adding test for external page as we 'll test with fake transactions. |
99 | } | |
100 | ||
4cbe18b8 EM |
101 | /** |
102 | * @return null | |
103 | */ | |
6a488035 TO |
104 | function _configureMembershipPage() { |
105 | static $pageId = NULL; | |
106 | ||
107 | if (!$pageId) { | |
6a488035 TO |
108 | $this->webtestLogin(); |
109 | ||
110 | //add payment processor. | |
42daf119 CW |
111 | $hash = substr(sha1(rand()), 0, 7); |
112 | $rand = 2 * rand(2, 50); | |
6a488035 TO |
113 | $processorName = "Webtest Auto Renew Google Checkout" . $hash; |
114 | $this->webtestAddPaymentProcessor($processorName, 'Google_Checkout'); | |
115 | ||
116 | // -- start updating membership types | |
76e86fd8 CW |
117 | $this->openCiviPage('admin/member/membershipType/add', 'action=update&id=1&reset=1'); |
118 | ||
6a488035 TO |
119 | $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')]"); |
120 | $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 | 121 | |
6a488035 TO |
122 | $this->type("duration_interval", "1"); |
123 | $this->select("duration_unit", "label=year"); | |
124 | ||
76e86fd8 | 125 | |
6a488035 TO |
126 | $this->click("_qf_MembershipType_upload-bottom"); |
127 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
128 | ||
76e86fd8 CW |
129 | $this->openCiviPage('admin/member/membershipType/add', 'action=update&id=2&reset=1'); |
130 | ||
6a488035 TO |
131 | $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')]"); |
132 | $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')]"); | |
133 | ||
134 | $this->type("duration_interval", "1"); | |
135 | $this->select("duration_unit", "label=year"); | |
136 | ||
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 | 179 | //make sure we do have required permissions. |
77a2a633 | 180 | $permissions = array("edit-1-make-online-contributions", "edit-1-profile-listings-and-forms"); |
6a488035 TO |
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 |