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