3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Member_OnlineMembershipAddPricesetTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testAddPriceSet() {
35 // add the required permission
36 $permissions = array('edit-1-make-online-contributions');
37 $this->changePermissions($permissions);
39 // Log in as normal user
40 $this->webtestLogin();
42 $title = substr(sha1(rand()), 0, 7);
43 $setTitle = "Membership Fees - $title";
44 $usedFor = 'Membership';
45 $contributionType = 'Donation';
46 $setHelp = 'Select your membership options.';
47 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
49 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
50 // which is where we are after adding Price Set.
51 $sid = $this->urlArg('sid');
52 $this->assertType('numeric', $sid);
55 "National Membership $title" => 'Radio',
56 "Local Chapter $title" => 'CheckBox',
59 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
60 //var_dump($validateStrings);
62 // load the Price Set Preview and check for expected values
63 $this->_testVerifyPriceSet($validateStrings, $sid);
65 $contributionPageTitle = "Contribution Page $title";
66 $paymentProcessor = "Webtest Dummy $title";
67 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'),
68 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
71 // Sign up for membership
72 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
73 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
74 $email = "{$firstName}.{$lastName}@example.com";
76 $contactParams = array(
77 'first_name' => $firstName,
78 'last_name' => $lastName,
81 $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2);
83 // Renew this membership
84 $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
87 function testAddPriceSetWithMultipleTerms() {
88 // add the required permission
89 $permissions = array('edit-1-make-online-contributions');
90 $this->changePermissions($permissions);
92 // Log in as normal user
93 $this->webtestLogin();
95 $title = substr(sha1(rand()), 0, 7);
96 $setTitle = "Membership Fees - $title";
97 $usedFor = 'Membership';
98 $contributionType = 'Member Dues';
99 $setHelp = 'Select your membership options.';
100 $memTypeParams1 = $this->webtestAddMembershipType();
101 $memTypeTitle1 = $memTypeParams1['membership_type'];
102 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
103 $memTypeId1 = $memTypeId1[1];
104 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
106 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
107 // which is where we are after adding Price Set.
108 $sid = $this->urlArg('sid');
109 $this->assertType('numeric', $sid);
111 $fields = array("National Membership $title", "Radio");
112 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
114 $validateStrings[] = $fields[0];
115 $this->type('label', $fields[0]);
116 $this->select('html_type', "value={$fields[1]}");
118 1 => array('label' => $memTypeTitle1."_1",
119 'membership_type_id' => $memTypeId1,
121 'membership_num_terms' => 1,
124 'label' => $memTypeTitle1."_2",
125 'membership_type_id' => $memTypeId1,
127 'membership_num_terms' => 2,
130 'label' => $memTypeTitle1."_3",
131 'membership_type_id' => $memTypeId1,
133 'membership_num_terms' => 3,
138 foreach($options as $index => $values){
139 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
140 // Because it tends to cause problems, all uses of sleep() must be justified in comments
141 // Sleep should never be used for wait for anything to load from the server
142 // Justification for this instance: FIXME
144 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']);
145 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']);
146 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']);
148 $this->click('link=another choice');
153 $this->waitForElementPresent( 'financial_type_id' );
154 $this->select("financial_type_id", "label={$contributionType}");
155 $this->waitForElementPresent('_qf_Field_next-bottom');
156 $this->click('_qf_Field_next-bottom');
157 $this->waitForPageToLoad($this->getTimeoutMsec());
158 $this->waitForText('crm-notification-container', "Price Field '{$fields[0]}' has been saved.");
160 // load the Price Set Preview and check for expected values
161 $this->_testVerifyPriceSet($validateStrings, $sid);
163 $contributionPageTitle = "Contribution Page $title";
164 $paymentProcessor = "Webtest Dummy $title";
165 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'),
166 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
169 // Sign up for membership
170 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
171 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
172 $email = "{$firstName}.{$lastName}@example.com";
174 $contactParams = array(
175 'first_name' => $firstName,
176 'last_name' => $lastName,
179 //membership with number of terms as 2
180 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 2);
181 //membership with number of terms as 3 which will renew the above membership
182 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 3, TRUE);
186 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
187 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
189 // Enter Priceset fields (Title, Used For ...)
190 $this->type('title', $setTitle);
191 if ($usedFor == 'Event') {
192 $this->check('extends[1]');
194 elseif ($usedFor == 'Contribution') {
195 $this->check('extends[2]');
197 elseif ($usedFor == 'Membership') {
198 $this->click('extends[3]');
199 $this->waitForElementPresent( 'financial_type_id' );
200 $this->select("css=select.form-select", "label={$contributionType}");
203 $this->type('help_pre', $setHelp);
205 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
206 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
207 $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
210 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
211 $memTypeParams1 = $this->webtestAddMembershipType();
212 $memTypeTitle1 = $memTypeParams1['membership_type'];
213 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
214 $memTypeId1 = $memTypeId1[1];
216 $memTypeParams2 = $this->webtestAddMembershipType();
217 $memTypeTitle2 = $memTypeParams2['membership_type'];
218 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
219 $memTypeId2 = $memTypeId2[1];
221 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
223 foreach ($fields as $label => $type) {
224 $validateStrings[] = $label;
226 $this->type('label', $label);
227 $this->select('html_type', "value={$type}");
232 1 => array('label' => "$memTypeTitle1",
233 'membership_type_id' => $memTypeId1,
237 'label' => "$memTypeTitle2",
238 'membership_type_id' => $memTypeId2,
242 $this->addMultipleChoiceOptions($options, $validateStrings);
247 1 => array('label' => "$memTypeTitle1",
248 'membership_type_id' => $memTypeId1,
252 'label' => "$memTypeTitle2",
253 'membership_type_id' => $memTypeId2,
257 $this->addMultipleChoiceOptions($options, $validateStrings);
263 $this->select("financial_type_id", "label={$contributionType}");
264 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
265 $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved.");
267 return array($memTypeTitle1, $memTypeTitle2);
270 function _testVerifyPriceSet($validateStrings, $sid) {
271 // verify Price Set at Preview page
272 // start at Manage Price Sets listing
273 $this->openCiviPage('admin/price', 'reset=1');
275 // Use the price set id ($sid) to pick the correct row
276 $this->clickLink("css=tr#row_{$sid} a[title='Preview Price Set']", '_qf_Preview_cancel-bottom');
278 // Check for expected price set field strings
279 $this->assertStringsPresent($validateStrings);
282 function _testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
283 $this->webtestLogout();
285 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
287 //build the membership dates.
288 $currentYear = date('Y');
289 $currentMonth = date('m');
290 $previousDay = date('d') - 1;
291 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
292 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
293 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
294 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
295 $configVars = new CRM_Core_Config_Variables();
297 'joinDate', 'startDate', 'endDate') as $date) {
298 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
301 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
302 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
304 $this->type('email-5', $contactParams['email-5']);
305 $this->type('first_name', $contactParams['first_name']);
306 $this->type('last_name', $contactParams['last_name']);
308 $streetAddress = "100 Main Street";
309 $this->type("street_address-1", $streetAddress);
310 $this->type("city-1", "San Francisco");
311 $this->type("postal_code-1", "94117");
312 $this->select("country-1", "value=1228");
313 $this->select("state_province-1", "value=1001");
316 $this->select("credit_card_type", "value=Visa");
317 $this->type("credit_card_number", "4111111111111111");
318 $this->type("cvv2", "000");
319 $this->select("credit_card_exp_date[M]", "value=1");
320 $this->select("credit_card_exp_date[Y]", "value=2020");
323 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
324 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
325 $this->type("billing_street_address-5", "15 Main St.");
326 $this->type(" billing_city-5", "San Jose");
327 $this->select("billing_country_id-5", "value=1228");
328 $this->select("billing_state_province_id-5", "value=1004");
329 $this->type("billing_postal_code-5", "94129");
330 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
332 $this->click("_qf_Confirm_next-bottom");
333 $this->waitForPageToLoad($this->getTimeoutMsec());
335 //login to check membership
337 // Log in using webtestLogin() method
338 $this->webtestLogin();
340 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
342 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
343 $this->click("_qf_Search_refresh");
345 $this->waitForPageToLoad($this->getTimeoutMsec());
346 $this->assertElementContainsText('crm-container', '2 Results');
348 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
349 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
350 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
352 //View Membership Record
354 'Membership Type' => "$memTypeTitle1",
356 'Member Since' => $joinDate,
357 'Start date' => $startDate,
358 'End date' => $endDate,
360 foreach ($verifyData as $label => $value) {
361 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
366 $this->clickLink('_qf_MembershipView_cancel-bottom', "xpath=//div[@id='memberSearch']/table/tbody/tr[2]");
367 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle2}']/../td[11]/span/a[text()='View']");
368 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
370 //View Membership Record
372 'Membership Type' => "$memTypeTitle2",
374 'Member Since' => $joinDate,
375 'Start date' => $startDate,
376 'End date' => $endDate,
378 foreach ($verifyData as $label => $value) {
379 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
385 function _testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, $term, $renew = FALSE){
387 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
388 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
389 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
390 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
391 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
392 $year = CRM_Utils_Date
::processDate($this->getText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='End date']/following-sibling::td"));
393 $prevYear = substr($year, 0, 4);
396 $this->webtestLogout();
398 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
400 //build the membership dates.
401 $currentYear = date('Y');
402 $currentMonth = date('m');
403 $previousDay = date('d') - 1;
404 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
405 $endYear = ($renew) ?
$endYear +
($prevYear - $currentYear) : $endYear;
407 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
408 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
409 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
410 $configVars = new CRM_Core_Config_Variables();
412 'joinDate', 'startDate', 'endDate') as $date) {
413 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
415 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
416 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
417 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
418 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
420 $this->type('email-5', $contactParams['email-5']);
421 $this->type('first_name', $contactParams['first_name']);
422 $this->type('last_name', $contactParams['last_name']);
424 $streetAddress = "100 Main Street";
425 $this->type("street_address-1", $streetAddress);
426 $this->type("city-1", "San Francisco");
427 $this->type("postal_code-1", "94117");
428 $this->select("country-1", "value=1228");
429 $this->select("state_province-1", "value=1001");
432 $this->select("credit_card_type", "value=Visa");
433 $this->type("credit_card_number", "4111111111111111");
434 $this->type("cvv2", "000");
435 $this->select("credit_card_exp_date[M]", "value=1");
436 $this->select("credit_card_exp_date[Y]", "value=2020");
439 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
440 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
441 $this->type("billing_street_address-5", "15 Main St.");
442 $this->type(" billing_city-5", "San Jose");
443 $this->select("billing_country_id-5", "value=1228");
444 $this->select("billing_state_province_id-5", "value=1004");
445 $this->type("billing_postal_code-5", "94129");
446 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
448 $this->click("_qf_Confirm_next-bottom");
449 $this->waitForPageToLoad($this->getTimeoutMsec());
451 //login to check membership
453 // Log in using webtestLogin() method
454 $this->webtestLogin();
456 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
458 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
459 $this->click("_qf_Search_refresh");
461 $this->waitForPageToLoad($this->getTimeoutMsec());
462 $this->assertElementContainsText('crm-container', '1 Result ');
464 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
465 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
466 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
468 //View Membership Record
470 'Membership Type' => "$memTypeTitle1",
472 'Member Since' => $joinDate,
473 'Start date' => $startDate,
474 'End date' => $endDate,
476 foreach ($verifyData as $label => $value) {
477 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
481 //check if the membership amount is correct
482 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));