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