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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Member_OnlineMembershipAddPricesetTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testAddPriceSet() {
36 // add the required permission
37 $permissions = array('edit-1-make-online-contributions');
38 $this->changePermissions($permissions);
40 // Log in as normal user
41 $this->webtestLogin();
43 $title = substr(sha1(rand()), 0, 7);
44 $setTitle = "Membership Fees - $title";
45 $usedFor = 'Membership';
46 $contributionType = 'Donation';
47 $setHelp = 'Select your membership options.';
48 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
50 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
51 // which is where we are after adding Price Set.
52 $elements = $this->parseURL();
53 $sid = $elements['queryString']['sid'];
54 $this->assertType('numeric', $sid);
57 "National Membership $title" => 'Radio',
58 "Local Chapter $title" => 'CheckBox',
61 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
62 //var_dump($validateStrings);
64 // load the Price Set Preview and check for expected values
65 $this->_testVerifyPriceSet($validateStrings, $sid);
67 $contributionPageTitle = "Contribution Page $title";
68 $paymentProcessor = "Webtest Dummy $title";
69 $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'),
70 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
73 // Sign up for membership
74 $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
76 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
77 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
78 $email = "{$firstName}.{$lastName}@example.com";
80 $contactParams = array(
81 'first_name' => $firstName,
82 'last_name' => $lastName,
85 $this->_testSignUpOrRenewMembership($registerUrl, $contactParams, $memTypeTitle1, $memTypeTitle2);
87 // Renew this membership
88 $this->_testSignUpOrRenewMembership($registerUrl, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
91 function testAddPriceSetWithMultipleTerms() {
92 // add the required permission
93 $permissions = array('edit-1-make-online-contributions');
94 $this->changePermissions($permissions);
96 // Log in as normal user
97 $this->webtestLogin();
99 $title = substr(sha1(rand()), 0, 7);
100 $setTitle = "Membership Fees - $title";
101 $usedFor = 'Membership';
102 $contributionType = 'Member Dues';
103 $setHelp = 'Select your membership options.';
104 $memTypeParams1 = $this->webtestAddMembershipType();
105 $memTypeTitle1 = $memTypeParams1['membership_type'];
106 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
107 $memTypeId1 = $memTypeId1[1];
108 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
110 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
111 // which is where we are after adding Price Set.
112 $elements = $this->parseURL();
113 $sid = $elements['queryString']['sid'];
114 $this->assertType('numeric', $sid);
116 $fields = array("National Membership $title", "Radio");
117 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
119 $validateStrings[] = $fields[0];
120 $this->type('label', $fields[0]);
121 $this->select('html_type', "value={$fields[1]}");
123 1 => array('label' => $memTypeTitle1."_1",
124 'membership_type_id' => $memTypeId1,
126 'membership_num_terms' => 1,
129 'label' => $memTypeTitle1."_2",
130 'membership_type_id' => $memTypeId1,
132 'membership_num_terms' => 2,
135 'label' => $memTypeTitle1."_3",
136 'membership_type_id' => $memTypeId1,
138 'membership_num_terms' => 3,
143 foreach($options as $index => $values){
144 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
145 // Because it tends to cause problems, all uses of sleep() must be justified in comments
146 // Sleep should never be used for wait for anything to load from the server
147 // Justification for this instance: FIXME
149 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']);
150 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']);
151 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']);
153 $this->click('link=another choice');
157 $this->waitForElementPresent( 'financial_type_id' );
158 $this->select("financial_type_id", "label={$contributionType}");
159 $this->waitForElementPresent('_qf_Field_next-bottom');
160 $this->click('_qf_Field_next-bottom');
161 $this->waitForPageToLoad($this->getTimeoutMsec());
162 $this->assertElementContainsText('crm-notification-container', "Price Field '{$fields[0]}' has been saved.");
164 // load the Price Set Preview and check for expected values
165 $this->_testVerifyPriceSet($validateStrings, $sid);
167 $contributionPageTitle = "Contribution Page $title";
168 $paymentProcessor = "Webtest Dummy $title";
169 $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'),
170 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
173 // Sign up for membership
174 $registerUrl = $this->_testVerifyRegisterPage($contributionPageTitle);
176 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
177 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
178 $email = "{$firstName}.{$lastName}@example.com";
180 $contactParams = array(
181 'first_name' => $firstName,
182 'last_name' => $lastName,
185 //membership with number of terms as 2
186 $this->_testMultilpeTermsMembershipRegistration($registerUrl, $contactParams, $memTypeTitle1, 2);
187 //membership with number of terms as 3 which will renew the above membership
188 $this->_testMultilpeTermsMembershipRegistration($registerUrl, $contactParams, $memTypeTitle1, 3, TRUE);
192 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
193 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
195 // Enter Priceset fields (Title, Used For ...)
196 $this->type('title', $setTitle);
197 if ($usedFor == 'Event') {
198 $this->check('extends[1]');
200 elseif ($usedFor == 'Contribution') {
201 $this->check('extends[2]');
203 elseif ($usedFor == 'Membership') {
204 $this->click('extends[3]');
205 $this->waitForElementPresent( 'financial_type_id' );
206 $this->select("css=select.form-select", "label={$contributionType}");
209 $this->type('help_pre', $setHelp);
211 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
212 $this->click('_qf_Set_next-bottom');
214 $this->waitForPageToLoad($this->getTimeoutMsec());
215 $this->waitForElementPresent('_qf_Field_next-bottom');
216 $this->assertElementContainsText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
219 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
220 $memTypeParams1 = $this->webtestAddMembershipType();
221 $memTypeTitle1 = $memTypeParams1['membership_type'];
222 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
223 $memTypeId1 = $memTypeId1[1];
225 $memTypeParams2 = $this->webtestAddMembershipType();
226 $memTypeTitle2 = $memTypeParams2['membership_type'];
227 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
228 $memTypeId2 = $memTypeId2[1];
230 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
232 foreach ($fields as $label => $type) {
233 $validateStrings[] = $label;
235 $this->type('label', $label);
236 $this->select('html_type', "value={$type}");
241 1 => array('label' => "$memTypeTitle1",
242 'membership_type_id' => $memTypeId1,
246 'label' => "$memTypeTitle2",
247 'membership_type_id' => $memTypeId2,
251 $this->addMultipleChoiceOptions($options, $validateStrings);
256 1 => array('label' => "$memTypeTitle1",
257 'membership_type_id' => $memTypeId1,
261 'label' => "$memTypeTitle2",
262 'membership_type_id' => $memTypeId2,
266 $this->addMultipleChoiceOptions($options, $validateStrings);
272 $this->select("financial_type_id", "label={$contributionType}");
273 $this->click('_qf_Field_next_new-bottom');
274 $this->waitForPageToLoad($this->getTimeoutMsec());
275 $this->waitForElementPresent('_qf_Field_next-bottom');
276 $this->assertElementContainsText('crm-notification-container', "Price Field '{$label}' has been saved.");
278 return array($memTypeTitle1, $memTypeTitle2);
281 function _testVerifyPriceSet($validateStrings, $sid) {
282 // verify Price Set at Preview page
283 // start at Manage Price Sets listing
284 $this->openCiviPage('admin/price', 'reset=1');
286 // Use the price set id ($sid) to pick the correct row
287 $this->click("css=tr#row_{$sid} a[title='Preview Price Set']");
289 $this->waitForPageToLoad($this->getTimeoutMsec());
290 // Look for Register button
291 $this->waitForElementPresent('_qf_Preview_cancel-bottom');
293 // Check for expected price set field strings
294 $this->assertStringsPresent($validateStrings);
297 function _testVerifyRegisterPage($contributionPageTitle) {
298 $this->openCiviPage('admin/contribute', 'reset=1', '_qf_SearchContribution_refresh');
299 $this->type('title', $contributionPageTitle);
300 $this->click('_qf_SearchContribution_refresh');
301 $this->waitForPageToLoad('50000');
302 $id = $this->getAttribute("//div[@id='configure_contribution_page']//div[@class='dataTables_wrapper']/table/tbody/tr@id");
303 $id = explode('_', $id);
304 $registerUrl = array('url' => 'contribute/transact', 'args' => "reset=1&id=$id[1]");
308 function _testSignUpOrRenewMembership($registerUrl, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
309 $this->webtestLogout();
311 $this->openCiviPage($registerUrl['url'], $registerUrl['args'], '_qf_Main_upload-bottom');
313 //build the membership dates.
314 require_once 'CRM/Core/Config.php';
315 require_once 'CRM/Utils/Array.php';
316 require_once 'CRM/Utils/Date.php';
317 $currentYear = date('Y');
318 $currentMonth = date('m');
319 $previousDay = date('d') - 1;
320 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
321 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
322 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
323 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
324 $configVars = new CRM_Core_Config_Variables();
326 'joinDate', 'startDate', 'endDate') as $date) {
327 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
330 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
331 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
333 $this->type('email-5', $contactParams['email-5']);
334 $this->type('first_name', $contactParams['first_name']);
335 $this->type('last_name', $contactParams['last_name']);
337 $streetAddress = "100 Main Street";
338 $this->type("street_address-1", $streetAddress);
339 $this->type("city-1", "San Francisco");
340 $this->type("postal_code-1", "94117");
341 $this->select("country-1", "value=1228");
342 $this->select("state_province-1", "value=1001");
345 $this->select("credit_card_type", "value=Visa");
346 $this->type("credit_card_number", "4111111111111111");
347 $this->type("cvv2", "000");
348 $this->select("credit_card_exp_date[M]", "value=1");
349 $this->select("credit_card_exp_date[Y]", "value=2020");
352 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
353 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
354 $this->type("billing_street_address-5", "15 Main St.");
355 $this->type(" billing_city-5", "San Jose");
356 $this->select("billing_country_id-5", "value=1228");
357 $this->select("billing_state_province_id-5", "value=1004");
358 $this->type("billing_postal_code-5", "94129");
359 $this->click("_qf_Main_upload-bottom");
361 $this->waitForPageToLoad($this->getTimeoutMsec());
362 $this->waitForElementPresent("_qf_Confirm_next-bottom");
364 $this->click("_qf_Confirm_next-bottom");
365 $this->waitForPageToLoad($this->getTimeoutMsec());
367 //login to check membership
369 // Log in using webtestLogin() method
370 $this->webtestLogin();
372 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
374 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
375 $this->click("_qf_Search_refresh");
377 $this->waitForPageToLoad($this->getTimeoutMsec());
378 $this->assertElementContainsText('crm-container', '2 Results');
380 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
381 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
382 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
384 //View Membership Record
386 'Membership Type' => "$memTypeTitle1",
388 'Member Since' => $joinDate,
389 'Start date' => $startDate,
390 'End date' => $endDate,
392 foreach ($verifyData as $label => $value) {
393 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
398 $this->click('_qf_MembershipView_cancel-bottom');
399 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr[2]");
400 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle2}']/../td[11]/span/a[text()='View']");
401 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
403 //View Membership Record
405 'Membership Type' => "$memTypeTitle2",
407 'Member Since' => $joinDate,
408 'Start date' => $startDate,
409 'End date' => $endDate,
411 foreach ($verifyData as $label => $value) {
412 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
418 function _testMultilpeTermsMembershipRegistration($registerUrl, $contactParams, $memTypeTitle1, $term, $renew = FALSE){
420 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
421 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
422 $this->click("_qf_Search_refresh");
423 $this->waitForPageToLoad($this->getTimeoutMsec());
424 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
425 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
426 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
427 $year = CRM_Utils_Date
::processDate($this->getText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='End date']/following-sibling::td"));
428 $prevYear = substr($year, 0, 4);
431 $this->webtestLogout();
433 $this->openCiviPage($registerUrl['url'], $registerUrl['args'], '_qf_Main_upload-bottom');
435 //build the membership dates.
436 require_once 'CRM/Core/Config.php';
437 require_once 'CRM/Utils/Array.php';
438 require_once 'CRM/Utils/Date.php';
439 $currentYear = date('Y');
440 $currentMonth = date('m');
441 $previousDay = date('d') - 1;
442 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
443 $endYear = ($renew) ?
$endYear +
($prevYear - $currentYear) : $endYear;
444 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
445 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
446 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
447 $configVars = new CRM_Core_Config_Variables();
449 'joinDate', 'startDate', 'endDate') as $date) {
450 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
452 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
453 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
454 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
455 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
457 $this->type('email-5', $contactParams['email-5']);
458 $this->type('first_name', $contactParams['first_name']);
459 $this->type('last_name', $contactParams['last_name']);
461 $streetAddress = "100 Main Street";
462 $this->type("street_address-1", $streetAddress);
463 $this->type("city-1", "San Francisco");
464 $this->type("postal_code-1", "94117");
465 $this->select("country-1", "value=1228");
466 $this->select("state_province-1", "value=1001");
469 $this->select("credit_card_type", "value=Visa");
470 $this->type("credit_card_number", "4111111111111111");
471 $this->type("cvv2", "000");
472 $this->select("credit_card_exp_date[M]", "value=1");
473 $this->select("credit_card_exp_date[Y]", "value=2020");
476 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
477 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
478 $this->type("billing_street_address-5", "15 Main St.");
479 $this->type(" billing_city-5", "San Jose");
480 $this->select("billing_country_id-5", "value=1228");
481 $this->select("billing_state_province_id-5", "value=1004");
482 $this->type("billing_postal_code-5", "94129");
483 $this->click("_qf_Main_upload-bottom");
485 $this->waitForPageToLoad($this->getTimeoutMsec());
486 $this->waitForElementPresent("_qf_Confirm_next-bottom");
488 $this->click("_qf_Confirm_next-bottom");
489 $this->waitForPageToLoad($this->getTimeoutMsec());
491 //login to check membership
493 // Log in using webtestLogin() method
494 $this->webtestLogin();
496 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
498 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
499 $this->click("_qf_Search_refresh");
501 $this->waitForPageToLoad($this->getTimeoutMsec());
502 $this->assertElementContainsText('crm-container', '1 Result ');
504 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
505 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
506 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
508 //View Membership Record
510 'Membership Type' => "$memTypeTitle1",
512 'Member Since' => $joinDate,
513 'Start date' => $startDate,
514 'End date' => $endDate,
516 foreach ($verifyData as $label => $value) {
517 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
521 //check if the membership amount is correct
522 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));