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