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_OnlineMembershipAddPricesetTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Member_OnlineMembershipAddPricesetTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testAddPriceSet() { | |
42daf119 | 39 | // add the required permission |
6a488035 TO |
40 | $permissions = array('edit-1-make-online-contributions'); |
41 | $this->changePermissions($permissions); | |
42 | ||
42daf119 CW |
43 | // Log in as normal user |
44 | $this->webtestLogin(); | |
45 | ||
46 | $title = substr(sha1(rand()), 0, 7); | |
47 | $setTitle = "Membership Fees - $title"; | |
48 | $usedFor = 'Membership'; | |
6a488035 | 49 | $contributionType = 'Donation'; |
42daf119 | 50 | $setHelp = 'Select your membership options.'; |
6a488035 TO |
51 | $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp); |
52 | ||
53 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
54 | // which is where we are after adding Price Set. | |
a471a3b6 | 55 | $sid = $this->urlArg('sid'); |
6a488035 TO |
56 | $this->assertType('numeric', $sid); |
57 | ||
58 | $fields = array( | |
59 | "National Membership $title" => 'Radio', | |
60 | "Local Chapter $title" => 'CheckBox', | |
61 | ); | |
62 | ||
63 | list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType); | |
64 | //var_dump($validateStrings); | |
65 | ||
66 | // load the Price Set Preview and check for expected values | |
67 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
68 | ||
69 | $contributionPageTitle = "Contribution Page $title"; | |
70 | $paymentProcessor = "Webtest Dummy $title"; | |
b45c587e | 71 | $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'), |
6a488035 TO |
72 | TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL |
73 | ); | |
74 | ||
75 | // Sign up for membership | |
6a488035 | 76 | $firstName = 'John_' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
77 | $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7); |
78 | $email = "{$firstName}.{$lastName}@example.com"; | |
6a488035 TO |
79 | |
80 | $contactParams = array( | |
81 | 'first_name' => $firstName, | |
82 | 'last_name' => $lastName, | |
83 | 'email-5' => $email, | |
84 | ); | |
b45c587e | 85 | $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2); |
6a488035 TO |
86 | |
87 | // Renew this membership | |
b45c587e | 88 | $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE); |
6a488035 TO |
89 | } |
90 | ||
91 | function testAddPriceSetWithMultipleTerms() { | |
42daf119 | 92 | // add the required permission |
6a488035 TO |
93 | $permissions = array('edit-1-make-online-contributions'); |
94 | $this->changePermissions($permissions); | |
95 | ||
42daf119 CW |
96 | // Log in as normal user |
97 | $this->webtestLogin(); | |
98 | ||
99 | $title = substr(sha1(rand()), 0, 7); | |
100 | $setTitle = "Membership Fees - $title"; | |
101 | $usedFor = 'Membership'; | |
6a488035 | 102 | $contributionType = 'Member Dues'; |
42daf119 | 103 | $setHelp = 'Select your membership options.'; |
6a488035 | 104 | $memTypeParams1 = $this->webtestAddMembershipType(); |
42daf119 | 105 | $memTypeTitle1 = $memTypeParams1['membership_type']; |
343688b7 | 106 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href")); |
42daf119 | 107 | $memTypeId1 = $memTypeId1[1]; |
6a488035 TO |
108 | $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp); |
109 | ||
110 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
111 | // which is where we are after adding Price Set. | |
a471a3b6 | 112 | $sid = $this->urlArg('sid'); |
6a488035 TO |
113 | $this->assertType('numeric', $sid); |
114 | ||
115 | $fields = array("National Membership $title", "Radio"); | |
8fe1f83e | 116 | $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}"); |
76e86fd8 | 117 | |
6a488035 TO |
118 | $validateStrings[] = $fields[0]; |
119 | $this->type('label', $fields[0]); | |
120 | $this->select('html_type', "value={$fields[1]}"); | |
121 | $options = array( | |
122 | 1 => array('label' => $memTypeTitle1."_1", | |
123 | 'membership_type_id' => $memTypeId1, | |
124 | 'amount' => 50.00, | |
125 | 'membership_num_terms' => 1, | |
126 | ), | |
127 | 2 => array( | |
128 | 'label' => $memTypeTitle1."_2", | |
129 | 'membership_type_id' => $memTypeId1, | |
130 | 'amount' => 90.00, | |
131 | 'membership_num_terms' => 2, | |
132 | ), | |
133 | 3 => array( | |
134 | 'label' => $memTypeTitle1."_3", | |
135 | 'membership_type_id' => $memTypeId1, | |
136 | 'amount' => 120.00, | |
137 | 'membership_num_terms' => 3, | |
138 | ), | |
76e86fd8 | 139 | |
6a488035 TO |
140 | ); |
141 | $i = 2; | |
142 | foreach($options as $index => $values){ | |
143 | $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}"); | |
efb29358 CW |
144 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
145 | // Sleep should never be used for wait for anything to load from the server | |
146 | // Justification for this instance: FIXME | |
6a488035 TO |
147 | sleep(1); |
148 | $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']); | |
149 | $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']); | |
150 | $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']); | |
151 | if($i > 3){ | |
76e86fd8 CW |
152 | $this->click('link=another choice'); |
153 | ||
6a488035 TO |
154 | } |
155 | $i++; | |
156 | } | |
157 | $this->waitForElementPresent( 'financial_type_id' ); | |
158 | $this->select("financial_type_id", "label={$contributionType}"); | |
159 | $this->waitForElementPresent('_qf_Field_next-bottom'); | |
160 | $this->click('_qf_Field_next-bottom'); | |
161 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c5f7368 | 162 | $this->waitForText('crm-notification-container', "Price Field '{$fields[0]}' has been saved."); |
76e86fd8 | 163 | |
6a488035 TO |
164 | // load the Price Set Preview and check for expected values |
165 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
166 | ||
167 | $contributionPageTitle = "Contribution Page $title"; | |
168 | $paymentProcessor = "Webtest Dummy $title"; | |
b45c587e | 169 | $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'), |
6a488035 TO |
170 | TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL |
171 | ); | |
172 | ||
173 | // Sign up for membership | |
6a488035 | 174 | $firstName = 'John_' . substr(sha1(rand()), 0, 7); |
42daf119 CW |
175 | $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7); |
176 | $email = "{$firstName}.{$lastName}@example.com"; | |
6a488035 TO |
177 | |
178 | $contactParams = array( | |
179 | 'first_name' => $firstName, | |
180 | 'last_name' => $lastName, | |
181 | 'email-5' => $email, | |
182 | ); | |
183 | //membership with number of terms as 2 | |
b45c587e | 184 | $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 2); |
6a488035 | 185 | //membership with number of terms as 3 which will renew the above membership |
b45c587e | 186 | $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 3, TRUE); |
6a488035 TO |
187 | |
188 | } | |
189 | ||
4cbe18b8 EM |
190 | /** |
191 | * @param $setTitle | |
192 | * @param $usedFor | |
193 | * @param null $contributionType | |
194 | * @param $setHelp | |
195 | */ | |
6a488035 | 196 | function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) { |
8fe1f83e | 197 | $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom'); |
6a488035 TO |
198 | |
199 | // Enter Priceset fields (Title, Used For ...) | |
200 | $this->type('title', $setTitle); | |
201 | if ($usedFor == 'Event') { | |
202 | $this->check('extends[1]'); | |
203 | } | |
204 | elseif ($usedFor == 'Contribution') { | |
205 | $this->check('extends[2]'); | |
206 | } | |
207 | elseif ($usedFor == 'Membership') { | |
208 | $this->click('extends[3]'); | |
209 | $this->waitForElementPresent( 'financial_type_id' ); | |
73072f84 | 210 | $this->select("css=select.crm-form-select", "label={$contributionType}"); |
6a488035 TO |
211 | } |
212 | ||
213 | $this->type('help_pre', $setHelp); | |
214 | ||
215 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); | |
343688b7 RK |
216 | $this->waitForElementPresent('_qf_Set_next-bottom'); |
217 | $this->click('_qf_Set_next-bottom'); | |
6c5f7368 | 218 | $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now."); |
6a488035 TO |
219 | } |
220 | ||
4cbe18b8 EM |
221 | /** |
222 | * @param $fields | |
223 | * @param $validateString | |
224 | * @param bool $dateSpecificFields | |
225 | * @param $title | |
226 | * @param $sid | |
227 | * @param $contributionType | |
228 | * | |
229 | * @return array | |
230 | */ | |
6a488035 TO |
231 | function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) { |
232 | $memTypeParams1 = $this->webtestAddMembershipType(); | |
42daf119 | 233 | $memTypeTitle1 = $memTypeParams1['membership_type']; |
343688b7 | 234 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href")); |
42daf119 | 235 | $memTypeId1 = $memTypeId1[1]; |
6a488035 TO |
236 | |
237 | $memTypeParams2 = $this->webtestAddMembershipType(); | |
42daf119 | 238 | $memTypeTitle2 = $memTypeParams2['membership_type']; |
343688b7 | 239 | $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href")); |
42daf119 | 240 | $memTypeId2 = $memTypeId2[1]; |
6a488035 | 241 | |
8fe1f83e | 242 | $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}"); |
6a488035 TO |
243 | |
244 | foreach ($fields as $label => $type) { | |
245 | $validateStrings[] = $label; | |
246 | ||
247 | $this->type('label', $label); | |
248 | $this->select('html_type', "value={$type}"); | |
249 | ||
250 | switch ($type) { | |
251 | case 'Radio': | |
252 | $options = array( | |
253 | 1 => array('label' => "$memTypeTitle1", | |
254 | 'membership_type_id' => $memTypeId1, | |
255 | 'amount' => 100.00, | |
256 | ), | |
257 | 2 => array( | |
258 | 'label' => "$memTypeTitle2", | |
259 | 'membership_type_id' => $memTypeId2, | |
260 | 'amount' => 50.00, | |
261 | ), | |
262 | ); | |
263 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
264 | break; | |
265 | ||
266 | case 'CheckBox': | |
267 | $options = array( | |
268 | 1 => array('label' => "$memTypeTitle1", | |
269 | 'membership_type_id' => $memTypeId1, | |
270 | 'amount' => 100.00, | |
271 | ), | |
272 | 2 => array( | |
273 | 'label' => "$memTypeTitle2", | |
274 | 'membership_type_id' => $memTypeId2, | |
275 | 'amount' => 50.00, | |
276 | ), | |
277 | ); | |
278 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
279 | break; | |
280 | ||
281 | default: | |
282 | break; | |
283 | } | |
284 | $this->select("financial_type_id", "label={$contributionType}"); | |
225a8648 | 285 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); |
6c5f7368 | 286 | $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved."); |
6a488035 TO |
287 | } |
288 | return array($memTypeTitle1, $memTypeTitle2); | |
289 | } | |
290 | ||
4cbe18b8 EM |
291 | /** |
292 | * @param $validateStrings | |
293 | * @param $sid | |
294 | */ | |
6a488035 TO |
295 | function _testVerifyPriceSet($validateStrings, $sid) { |
296 | // verify Price Set at Preview page | |
297 | // start at Manage Price Sets listing | |
8fe1f83e | 298 | $this->openCiviPage('admin/price', 'reset=1'); |
6a488035 TO |
299 | |
300 | // Use the price set id ($sid) to pick the correct row | |
73072f84 | 301 | $this->clickLink("css=tr#price_set-{$sid} a[title='Preview Price Set']", '_qf_Preview_cancel-bottom'); |
6a488035 TO |
302 | |
303 | // Check for expected price set field strings | |
304 | $this->assertStringsPresent($validateStrings); | |
305 | } | |
306 | ||
4cbe18b8 EM |
307 | /** |
308 | * @param $pageId | |
309 | * @param $contactParams | |
310 | * @param $memTypeTitle1 | |
311 | * @param $memTypeTitle2 | |
312 | * @param bool $renew | |
313 | */ | |
b45c587e | 314 | function _testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) { |
42daf119 | 315 | $this->webtestLogout(); |
6a488035 | 316 | |
b45c587e | 317 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom'); |
6a488035 TO |
318 | |
319 | //build the membership dates. | |
42daf119 | 320 | $currentYear = date('Y'); |
6a488035 | 321 | $currentMonth = date('m'); |
42daf119 CW |
322 | $previousDay = date('d') - 1; |
323 | $endYear = ($renew) ? $currentYear + 2 : $currentYear + 1; | |
324 | $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); | |
325 | $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); | |
326 | $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear)); | |
327 | $configVars = new CRM_Core_Config_Variables(); | |
6a488035 TO |
328 | foreach (array( |
329 | 'joinDate', 'startDate', 'endDate') as $date) { | |
330 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
331 | } | |
332 | ||
333 | $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input"); | |
334 | $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input"); | |
335 | ||
336 | $this->type('email-5', $contactParams['email-5']); | |
337 | $this->type('first_name', $contactParams['first_name']); | |
338 | $this->type('last_name', $contactParams['last_name']); | |
339 | ||
340 | $streetAddress = "100 Main Street"; | |
341 | $this->type("street_address-1", $streetAddress); | |
342 | $this->type("city-1", "San Francisco"); | |
343 | $this->type("postal_code-1", "94117"); | |
344 | $this->select("country-1", "value=1228"); | |
345 | $this->select("state_province-1", "value=1001"); | |
346 | ||
347 | //Credit Card Info | |
348 | $this->select("credit_card_type", "value=Visa"); | |
349 | $this->type("credit_card_number", "4111111111111111"); | |
350 | $this->type("cvv2", "000"); | |
351 | $this->select("credit_card_exp_date[M]", "value=1"); | |
352 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
353 | ||
354 | //Billing Info | |
355 | $this->type("billing_first_name", $contactParams['first_name'] . "billing"); | |
356 | $this->type("billing_last_name", $contactParams['last_name'] . "billing"); | |
357 | $this->type("billing_street_address-5", "15 Main St."); | |
358 | $this->type(" billing_city-5", "San Jose"); | |
359 | $this->select("billing_country_id-5", "value=1228"); | |
360 | $this->select("billing_state_province_id-5", "value=1004"); | |
361 | $this->type("billing_postal_code-5", "94129"); | |
225a8648 | 362 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 TO |
363 | |
364 | $this->click("_qf_Confirm_next-bottom"); | |
365 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
366 | ||
367 | //login to check membership | |
6a488035 TO |
368 | |
369 | // Log in using webtestLogin() method | |
370 | $this->webtestLogin(); | |
371 | ||
8fe1f83e | 372 | $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high'); |
6a488035 TO |
373 | |
374 | $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}"); | |
375 | $this->click("_qf_Search_refresh"); | |
376 | ||
377 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
8fe1f83e | 378 | $this->assertElementContainsText('crm-container', '2 Results'); |
6a488035 TO |
379 | |
380 | $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr"); | |
381 | $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']"); | |
382 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
383 | ||
384 | //View Membership Record | |
385 | $verifyData = array( | |
386 | 'Membership Type' => "$memTypeTitle1", | |
387 | 'Status' => 'New', | |
388 | 'Member Since' => $joinDate, | |
389 | 'Start date' => $startDate, | |
390 | 'End date' => $endDate, | |
391 | ); | |
392 | foreach ($verifyData as $label => $value) { | |
393 | $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", | |
394 | preg_quote($value) | |
395 | ); | |
396 | } | |
397 | ||
73072f84 | 398 | $this->clickLink('_qf_MembershipView_cancel-bottom', "xpath=//div[@id='memberSearch']/table/tbody/tr[2]", FALSE); |
6a488035 TO |
399 | $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle2}']/../td[11]/span/a[text()='View']"); |
400 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
401 | ||
402 | //View Membership Record | |
403 | $verifyData = array( | |
404 | 'Membership Type' => "$memTypeTitle2", | |
405 | 'Status' => 'New', | |
406 | 'Member Since' => $joinDate, | |
407 | 'Start date' => $startDate, | |
408 | 'End date' => $endDate, | |
409 | ); | |
410 | foreach ($verifyData as $label => $value) { | |
411 | $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", | |
412 | preg_quote($value) | |
413 | ); | |
414 | } | |
415 | } | |
76e86fd8 | 416 | |
4cbe18b8 EM |
417 | /** |
418 | * @param $pageId | |
419 | * @param $contactParams | |
420 | * @param $memTypeTitle1 | |
421 | * @param $term | |
422 | * @param bool $renew | |
423 | */ | |
b45c587e | 424 | function _testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, $term, $renew = FALSE){ |
6a488035 | 425 | if($renew){ |
8fe1f83e | 426 | $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high'); |
6a488035 | 427 | $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}"); |
225a8648 | 428 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr"); |
6a488035 TO |
429 | $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']"); |
430 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
431 | $year = CRM_Utils_Date::processDate($this->getText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='End date']/following-sibling::td")); | |
432 | $prevYear = substr($year, 0, 4); | |
433 | } | |
76e86fd8 | 434 | |
42daf119 | 435 | $this->webtestLogout(); |
6a488035 | 436 | |
b45c587e | 437 | $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom'); |
6a488035 TO |
438 | |
439 | //build the membership dates. | |
42daf119 | 440 | $currentYear = date('Y'); |
6a488035 | 441 | $currentMonth = date('m'); |
42daf119 CW |
442 | $previousDay = date('d') - 1; |
443 | $endYear = ($term == 3) ? $currentYear + 3 : (($term == 2) ? $currentYear + 2 : $currentYear + 1); | |
76e86fd8 CW |
444 | $endYear = ($renew) ? $endYear + ($prevYear - $currentYear) : $endYear; |
445 | ||
42daf119 CW |
446 | $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); |
447 | $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); | |
448 | $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear)); | |
449 | $configVars = new CRM_Core_Config_Variables(); | |
6a488035 TO |
450 | foreach (array( |
451 | 'joinDate', 'startDate', 'endDate') as $date) { | |
452 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
453 | } | |
42daf119 | 454 | $i = ($term == 3) ? 3 : (($term == 2) ? 2 : 1 ); |
6a488035 TO |
455 | $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input"); |
456 | $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input"); | |
457 | $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']"); | |
458 | ||
459 | $this->type('email-5', $contactParams['email-5']); | |
460 | $this->type('first_name', $contactParams['first_name']); | |
461 | $this->type('last_name', $contactParams['last_name']); | |
462 | ||
463 | $streetAddress = "100 Main Street"; | |
464 | $this->type("street_address-1", $streetAddress); | |
465 | $this->type("city-1", "San Francisco"); | |
466 | $this->type("postal_code-1", "94117"); | |
467 | $this->select("country-1", "value=1228"); | |
468 | $this->select("state_province-1", "value=1001"); | |
469 | ||
470 | //Credit Card Info | |
471 | $this->select("credit_card_type", "value=Visa"); | |
472 | $this->type("credit_card_number", "4111111111111111"); | |
473 | $this->type("cvv2", "000"); | |
474 | $this->select("credit_card_exp_date[M]", "value=1"); | |
475 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
476 | ||
477 | //Billing Info | |
478 | $this->type("billing_first_name", $contactParams['first_name'] . "billing"); | |
479 | $this->type("billing_last_name", $contactParams['last_name'] . "billing"); | |
480 | $this->type("billing_street_address-5", "15 Main St."); | |
481 | $this->type(" billing_city-5", "San Jose"); | |
482 | $this->select("billing_country_id-5", "value=1228"); | |
483 | $this->select("billing_state_province_id-5", "value=1004"); | |
484 | $this->type("billing_postal_code-5", "94129"); | |
225a8648 | 485 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 TO |
486 | |
487 | $this->click("_qf_Confirm_next-bottom"); | |
488 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
489 | ||
490 | //login to check membership | |
6a488035 TO |
491 | |
492 | // Log in using webtestLogin() method | |
493 | $this->webtestLogin(); | |
494 | ||
8fe1f83e | 495 | $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high'); |
6a488035 TO |
496 | |
497 | $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}"); | |
498 | $this->click("_qf_Search_refresh"); | |
499 | ||
500 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
8fe1f83e | 501 | $this->assertElementContainsText('crm-container', '1 Result '); |
6a488035 TO |
502 | |
503 | $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr"); | |
504 | $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']"); | |
505 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
506 | ||
507 | //View Membership Record | |
508 | $verifyData = array( | |
509 | 'Membership Type' => "$memTypeTitle1", | |
510 | 'Status' => 'New', | |
511 | 'Member Since' => $joinDate, | |
512 | 'Start date' => $startDate, | |
513 | 'End date' => $endDate, | |
514 | ); | |
515 | foreach ($verifyData as $label => $value) { | |
516 | $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", | |
517 | preg_quote($value) | |
518 | ); | |
519 | } | |
520 | //check if the membership amount is correct | |
27c7ef42 | 521 | $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"); |
6a488035 TO |
522 | $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']")); |
523 | } | |
524 | ||
525 | } | |
526 |