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_OfflineMembershipAddPricesetTest extends CiviSeleniumTestCase { | |
29 | ||
30 | protected function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function testAddPriceSet() { | |
6a488035 TO |
35 | // Log in using webtestLogin() method |
36 | $this->webtestLogin(); | |
37 | ||
38 | $title = substr(sha1(rand()), 0, 7); | |
39 | $setTitle = "Membership Fees - $title"; | |
40 | $usedFor = 'Membership'; | |
41 | $contributionType = 'Donation'; | |
42 | $setHelp = 'Select your membership options.'; | |
43 | $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp); | |
44 | ||
45 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
46 | // which is where we are after adding Price Set. | |
a471a3b6 | 47 | $sid = $this->urlArg('sid'); |
6a488035 TO |
48 | $this->assertType('numeric', $sid); |
49 | ||
50 | $fields = array( | |
51 | "National Membership $title" => 'Radio', | |
52 | "Local Chapter $title" => 'CheckBox', | |
53 | ); | |
54 | ||
55 | list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType); | |
6a488035 TO |
56 | |
57 | // load the Price Set Preview and check for expected values | |
58 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
59 | ||
60 | // Sign up for membership | |
61 | $firstName = 'John_' . substr(sha1(rand()), 0, 7); | |
62 | $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7); | |
63 | $email = "{$firstName}.{$lastName}@example.com"; | |
64 | $contactParams = array( | |
65 | 'first_name' => $firstName, | |
66 | 'last_name' => $lastName, | |
67 | 'email-5' => $email, | |
68 | ); | |
69 | ||
70 | // Add a contact from the quick add block | |
71 | $this->webtestAddContact($firstName, $lastName, $email); | |
72 | ||
73 | $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2); | |
74 | ||
75 | // Renew this membership | |
76 | $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE); | |
77 | } | |
78 | ||
79 | function testAddPriceSetWithMultipleTerms() { | |
6a488035 TO |
80 | // Log in using webtestLogin() method |
81 | $this->webtestLogin(); | |
0ff7ff97 | 82 | |
6a488035 TO |
83 | $title = substr(sha1(rand()), 0, 7); |
84 | $setTitle = "Membership Fees - $title"; | |
85 | $usedFor = 'Membership'; | |
86 | $contributionType = 'Member Dues'; | |
87 | $setHelp = 'Select your membership options.'; | |
88 | $memTypeParams1 = $this->webtestAddMembershipType(); | |
89 | $memTypeTitle1 = $memTypeParams1['membership_type']; | |
73072f84 | 90 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[1]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href")); |
6a488035 TO |
91 | $memTypeId1 = $memTypeId1[1]; |
92 | $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp); | |
93 | ||
94 | // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form | |
95 | // which is where we are after adding Price Set. | |
a471a3b6 | 96 | $sid = $this->urlArg('sid'); |
6a488035 TO |
97 | $this->assertType('numeric', $sid); |
98 | ||
99 | $fields = array("National Membership $title", "Radio"); | |
0ff7ff97 PJ |
100 | $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}"); |
101 | ||
6a488035 TO |
102 | $validateStrings[] = $fields[0]; |
103 | $this->type('label', $fields[0]); | |
104 | $this->select('html_type', "value={$fields[1]}"); | |
105 | $options = array( | |
0ff7ff97 PJ |
106 | 1 => array('label' => $memTypeTitle1."_1", |
107 | 'membership_type_id' => $memTypeId1, | |
108 | 'amount' => 50.00, | |
109 | 'membership_num_terms' => 1, | |
110 | ), | |
111 | 2 => array( | |
112 | 'label' => $memTypeTitle1."_2", | |
113 | 'membership_type_id' => $memTypeId1, | |
114 | 'amount' => 90.00, | |
115 | 'membership_num_terms' => 2, | |
116 | ), | |
117 | 3 => array( | |
118 | 'label' => $memTypeTitle1."_3", | |
119 | 'membership_type_id' => $memTypeId1, | |
120 | 'amount' => 120.00, | |
121 | 'membership_num_terms' => 3, | |
122 | ), | |
123 | ); | |
6a488035 TO |
124 | $i = 2; |
125 | foreach($options as $index => $values){ | |
126 | $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}"); | |
efb29358 CW |
127 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
128 | // Sleep should never be used for wait for anything to load from the server | |
129 | // Justification for this instance: FIXME | |
6a488035 TO |
130 | sleep(1); |
131 | $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']); | |
132 | $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']); | |
133 | $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']); | |
134 | if($i > 3){ | |
0ff7ff97 | 135 | $this->click('link=another choice'); |
6a488035 TO |
136 | } |
137 | $i++; | |
138 | } | |
139 | $this->waitForElementPresent( 'financial_type_id' ); | |
140 | $this->select("financial_type_id", "label={$contributionType}"); | |
141 | $this->waitForElementPresent('_qf_Field_next-bottom'); | |
142 | $this->click('_qf_Field_next-bottom'); | |
143 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c5f7368 | 144 | $this->waitForText('crm-notification-container', "Price Field '{$fields[0]}' has been saved."); |
0ff7ff97 | 145 | |
6a488035 TO |
146 | // load the Price Set Preview and check for expected values |
147 | $this->_testVerifyPriceSet($validateStrings, $sid); | |
148 | ||
149 | $firstName = 'John_' . substr(sha1(rand()), 0, 7); | |
150 | $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7); | |
151 | $email = "{$firstName}.{$lastName}@example.com"; | |
152 | ||
153 | $contactParams = array( | |
154 | 'first_name' => $firstName, | |
155 | 'last_name' => $lastName, | |
156 | 'email-5' => $email, | |
157 | ); | |
158 | $this->webtestAddContact($firstName, $lastName, $email); | |
159 | //membership with number of terms as 3 | |
160 | $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 3); | |
161 | //membership with number of terms as 2 | |
162 | $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 2); | |
0ff7ff97 | 163 | |
6a488035 TO |
164 | } |
165 | ||
6a488035 | 166 | function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) { |
0ff7ff97 | 167 | $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom'); |
6a488035 TO |
168 | |
169 | // Enter Priceset fields (Title, Used For ...) | |
170 | $this->type('title', $setTitle); | |
171 | if ($usedFor == 'Event') { | |
172 | $this->check('extends_1'); | |
173 | } | |
174 | elseif ($usedFor == 'Contribution') { | |
175 | $this->check('extends_2'); | |
176 | } | |
177 | elseif ($usedFor == 'Membership') { | |
178 | $this->click('extends_3'); | |
0ff7ff97 | 179 | $this->waitForElementPresent('financial_type_id'); |
73072f84 | 180 | $this->select("css=select.crm-form-select", "label={$contributionType}"); |
6a488035 | 181 | } |
6a488035 | 182 | $this->type('help_pre', $setHelp); |
6a488035 | 183 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); |
6a488035 | 184 | |
0ff7ff97 | 185 | $this->click('_qf_Set_next-bottom'); |
6a488035 | 186 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
6c5f7368 | 187 | $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now."); |
6a488035 TO |
188 | } |
189 | ||
190 | function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) { | |
191 | $memTypeParams1 = $this->webtestAddMembershipType(); | |
192 | $memTypeTitle1 = $memTypeParams1['membership_type']; | |
193 | ||
73072f84 | 194 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[1]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href")); |
6a488035 TO |
195 | $memTypeId1 = $memTypeId1[1]; |
196 | ||
197 | $memTypeParams2 = $this->webtestAddMembershipType(); | |
198 | $memTypeTitle2 = $memTypeParams2['membership_type']; | |
73072f84 | 199 | $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[1]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href")); |
6a488035 TO |
200 | $memTypeId2 = $memTypeId2[1]; |
201 | ||
0ff7ff97 | 202 | $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}"); |
6a488035 TO |
203 | |
204 | foreach ($fields as $label => $type) { | |
205 | $validateStrings[] = $label; | |
206 | ||
207 | $this->type('label', $label); | |
208 | $this->select('html_type', "value={$type}"); | |
209 | ||
210 | switch ($type) { | |
211 | case 'Radio': | |
212 | $options = array( | |
213 | 1 => array('label' => "$memTypeTitle1", | |
0ff7ff97 PJ |
214 | 'membership_type_id' => $memTypeId1, |
215 | 'amount' => 100.00, | |
6a488035 TO |
216 | ), |
217 | 2 => array( | |
218 | 'label' => "$memTypeTitle2", | |
219 | 'membership_type_id' => $memTypeId2, | |
220 | 'amount' => 50.00, | |
221 | ), | |
222 | ); | |
223 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
224 | break; | |
225 | ||
226 | case 'CheckBox': | |
227 | $options = array( | |
228 | 1 => array('label' => "$memTypeTitle1", | |
0ff7ff97 PJ |
229 | 'membership_type_id' => $memTypeId1, |
230 | 'amount' => 100.00, | |
6a488035 TO |
231 | ), |
232 | 2 => array( | |
233 | 'label' => "$memTypeTitle2", | |
234 | 'membership_type_id' => $memTypeId2, | |
235 | 'amount' => 50.00, | |
236 | ), | |
237 | ); | |
238 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
239 | break; | |
240 | ||
241 | default: | |
242 | break; | |
243 | } | |
244 | $this->select("financial_type_id", "label={$contributionType}"); | |
245 | $this->click('_qf_Field_next_new-bottom'); | |
246 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
6c5f7368 | 247 | $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved."); |
6a488035 TO |
248 | } |
249 | return array($memTypeTitle1, $memTypeTitle2); | |
250 | } | |
251 | ||
252 | function _testVerifyPriceSet($validateStrings, $sid) { | |
253 | // verify Price Set at Preview page | |
254 | // start at Manage Price Sets listing | |
0ff7ff97 | 255 | $this->openCiviPage('admin/price', 'reset=1'); |
6a488035 TO |
256 | |
257 | // Use the price set id ($sid) to pick the correct row | |
73072f84 | 258 | $this->click("css=tr#price_set-{$sid} a[title='Preview Price Set']"); |
6a488035 | 259 | |
6a488035 TO |
260 | // Look for Register button |
261 | $this->waitForElementPresent('_qf_Preview_cancel-bottom'); | |
262 | ||
263 | // Check for expected price set field strings | |
264 | $this->assertStringsPresent($validateStrings); | |
265 | } | |
266 | ||
267 | function _testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) { | |
268 | //build the membership dates. | |
269 | require_once 'CRM/Core/Config.php'; | |
270 | require_once 'CRM/Utils/Array.php'; | |
271 | require_once 'CRM/Utils/Date.php'; | |
272 | $currentYear = date('Y'); | |
273 | $currentMonth = date('m'); | |
274 | $previousDay = date('d') - 1; | |
275 | $endYear = ($renew) ? $currentYear + 2 : $currentYear + 1; | |
276 | $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); | |
277 | $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); | |
278 | $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear)); | |
279 | $configVars = new CRM_Core_Config_Variables(); | |
280 | foreach (array( | |
281 | 'joinDate', 'startDate', 'endDate') as $date) { | |
282 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
283 | } | |
284 | ||
285 | if (!$renew) { | |
42daf119 | 286 | |
6a488035 TO |
287 | $this->click('css=li#tab_member a'); |
288 | $this->waitForElementPresent('link=Add Membership'); | |
289 | ||
290 | $this->click('link=Add Membership'); | |
291 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
292 | ||
293 | $this->select('price_set_id', "value={$sid}"); | |
294 | $this->waitForElementPresent('pricesetTotal'); | |
295 | ||
296 | $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input"); | |
297 | $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input"); | |
298 | ||
299 | $this->type('source', 'Offline membership Sign Up Test Text'); | |
300 | $this->click('_qf_Membership_upload-bottom'); | |
301 | } | |
302 | else { | |
73072f84 | 303 | $this->click("xpath=//div[@id='memberships']/div//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
6a488035 TO |
304 | $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom'); |
305 | $this->click('_qf_MembershipRenewal_upload-bottom'); | |
306 | ||
307 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr"); | |
73072f84 | 308 | $this->click("xpath=//div[@id='memberships']/div//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']"); |
6a488035 TO |
309 | $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom'); |
310 | $this->click('_qf_MembershipRenewal_upload-bottom'); | |
311 | } | |
312 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr"); | |
313 | $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span/a[text()='View']"); | |
314 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
0ff7ff97 | 315 | |
6a488035 TO |
316 | //View Membership Record |
317 | $verifyData = array( | |
318 | 'Membership Type' => "{$memTypeTitle1}", | |
319 | 'Status' => 'New', | |
320 | 'Member Since' => $joinDate, | |
321 | 'Start date' => $startDate, | |
322 | 'End date' => $endDate, | |
323 | ); | |
0ff7ff97 | 324 | $this->webtestVerifyTabularData($verifyData); |
6a488035 TO |
325 | |
326 | $this->click('_qf_MembershipView_cancel-bottom'); | |
327 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr"); | |
328 | $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span/a[text()='View']"); | |
329 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
330 | ||
331 | //View Membership Record | |
332 | $verifyData = array( | |
333 | 'Membership Type' => "{$memTypeTitle2}", | |
334 | 'Status' => 'New', | |
335 | 'Member Since' => $joinDate, | |
336 | 'Start date' => $startDate, | |
337 | 'End date' => $endDate, | |
338 | ); | |
0ff7ff97 PJ |
339 | $this->webtestVerifyTabularData($verifyData); |
340 | ||
6a488035 TO |
341 | $this->click("_qf_MembershipView_cancel-bottom"); |
342 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr"); | |
343 | } | |
344 | ||
345 | function _testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, $term){ | |
346 | //build the membership dates. | |
347 | require_once 'CRM/Core/Config.php'; | |
348 | require_once 'CRM/Utils/Array.php'; | |
349 | require_once 'CRM/Utils/Date.php'; | |
350 | $currentYear = date('Y'); | |
351 | $currentMonth = date('m'); | |
352 | $previousDay = date('d') - 1; | |
353 | $endYear = ($term == 3) ? $currentYear + 3 : (($term == 2) ? $currentYear + 2 : $currentYear + 1); | |
354 | $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); | |
355 | $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear)); | |
356 | $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear)); | |
357 | $configVars = new CRM_Core_Config_Variables(); | |
358 | foreach (array( | |
359 | 'joinDate', 'startDate', 'endDate') as $date) { | |
360 | $$date = CRM_Utils_Date::customFormat($$date, $configVars->dateformatFull); | |
361 | } | |
0ff7ff97 | 362 | |
6a488035 TO |
363 | $this->click('css=li#tab_member a'); |
364 | $this->waitForElementPresent('link=Add Membership'); | |
0ff7ff97 | 365 | |
6a488035 TO |
366 | $this->click('link=Add Membership'); |
367 | $this->waitForElementPresent('_qf_Membership_cancel-bottom'); | |
0ff7ff97 | 368 | |
6a488035 TO |
369 | $this->select('price_set_id', "value={$sid}"); |
370 | $this->waitForElementPresent('pricesetTotal'); | |
0ff7ff97 | 371 | |
6a488035 TO |
372 | $i = ($term == 3) ? 3 : (($term == 2) ? 2 : 1 ); |
373 | $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input"); | |
374 | $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input"); | |
375 | $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']"); | |
0ff7ff97 | 376 | |
6a488035 | 377 | $this->type('source', 'Offline membership Sign Up Test Text'); |
565761e7 | 378 | $this->waitForElementPresent('recordContribution'); |
6a488035 | 379 | $this->click('_qf_Membership_upload-bottom'); |
0ff7ff97 | 380 | |
6a488035 TO |
381 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr"); |
382 | $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$endDate}']/../td[9]/span/a[text()='View']"); | |
383 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); | |
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 | ); | |
0ff7ff97 PJ |
392 | $this->webtestVerifyTabularData($verifyData); |
393 | ||
6a488035 | 394 | //check if the membership amount is correct |
27c7ef42 | 395 | $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"); |
6a488035 TO |
396 | $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']")); |
397 | $this->click("_qf_MembershipView_cancel-bottom"); | |
398 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
399 | } | |
42daf119 | 400 | } |