3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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';
30 * Class WebTest_Member_OnlineMembershipAddPricesetTest
32 class WebTest_Member_OnlineMembershipAddPricesetTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testAddPriceSet() {
39 // add the required permission
40 $permissions = array('edit-1-make-online-contributions');
41 $this->changePermissions($permissions);
43 // Log in as normal user
44 $this->webtestLogin();
46 $title = substr(sha1(rand()), 0, 7);
47 $setTitle = "Membership Fees - $title";
48 $usedFor = 'Membership';
49 $contributionType = 'Donation';
50 $setHelp = 'Select your membership options.';
51 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
53 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
54 // which is where we are after adding Price Set.
55 $sid = $this->urlArg('sid');
56 $this->assertType('numeric', $sid);
59 "National Membership $title" => 'Radio',
60 "Local Chapter $title" => 'CheckBox',
63 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
64 //var_dump($validateStrings);
66 // load the Price Set Preview and check for expected values
67 $this->_testVerifyPriceSet($validateStrings, $sid);
69 $contributionPageTitle = "Contribution Page $title";
70 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array('Test Processor' => 'Dummy'),
71 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
74 // Sign up for membership
75 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
76 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
77 $email = "{$firstName}.{$lastName}@example.com";
79 $contactParams = array(
80 'first_name' => $firstName,
81 'last_name' => $lastName,
84 $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2);
86 // Renew this membership
87 $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
90 function testAddPriceSetWithMultipleTerms() {
91 // add the required permission
92 $permissions = array('edit-1-make-online-contributions');
93 $this->changePermissions($permissions);
95 // Log in as normal user
96 $this->webtestLogin();
98 $title = substr(sha1(rand()), 0, 7);
99 $setTitle = "Membership Fees - $title";
100 $usedFor = 'Membership';
101 $contributionType = 'Member Dues';
102 $setHelp = 'Select your membership options.';
103 $memTypeParams1 = $this->webtestAddMembershipType();
104 $memTypeTitle1 = $memTypeParams1['membership_type'];
105 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
106 $memTypeId1 = $memTypeId1[1];
107 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
109 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
110 // which is where we are after adding Price Set.
111 $sid = $this->urlArg('sid');
112 $this->assertType('numeric', $sid);
114 $fields = array("National Membership $title", "Radio");
115 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
117 $validateStrings[] = $fields[0];
118 $this->type('label', $fields[0]);
119 $this->select('html_type', "value={$fields[1]}");
121 1 => array('label' => $memTypeTitle1."_1",
122 'membership_type_id' => $memTypeId1,
124 'membership_num_terms' => 1,
127 'label' => $memTypeTitle1."_2",
128 'membership_type_id' => $memTypeId1,
130 'membership_num_terms' => 2,
133 'label' => $memTypeTitle1."_3",
134 'membership_type_id' => $memTypeId1,
136 'membership_num_terms' => 3,
141 foreach($options as $index => $values){
142 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
144 $this->waitForElementPresent("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input");
145 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']);
146 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']);
147 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']);
149 $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->clickLink('_qf_Field_next-bottom');
157 $this->waitForText('crm-notification-container', "Price Field '{$fields[0]}' has been saved.");
159 // load the Price Set Preview and check for expected values
160 $this->_testVerifyPriceSet($validateStrings, $sid);
162 $contributionPageTitle = "Contribution Page $title";
163 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array('Test Processor' => 'Dummy'),
164 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
167 // Sign up for membership
168 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
169 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
170 $email = "{$firstName}.{$lastName}@example.com";
172 $contactParams = array(
173 'first_name' => $firstName,
174 'last_name' => $lastName,
177 //membership with number of terms as 2
178 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 2);
179 //membership with number of terms as 3 which will renew the above membership
180 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 3, TRUE);
187 * @param null $contributionType
190 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
191 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
193 // Enter Priceset fields (Title, Used For ...)
194 $this->type('title', $setTitle);
195 if ($usedFor == 'Event') {
196 $this->check('extends[1]');
198 elseif ($usedFor == 'Contribution') {
199 $this->check('extends[2]');
201 elseif ($usedFor == 'Membership') {
202 $this->click('extends[3]');
203 $this->waitForElementPresent( 'financial_type_id' );
204 $this->select("css=select.crm-form-select", "label={$contributionType}");
207 $this->type('help_pre', $setHelp);
209 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
210 $this->waitForElementPresent('_qf_Set_next-bottom');
211 $this->click('_qf_Set_next-bottom');
212 $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
217 * @param $validateString
218 * @param bool $dateSpecificFields
221 * @param $contributionType
225 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
226 $memTypeParams1 = $this->webtestAddMembershipType();
227 $memTypeTitle1 = $memTypeParams1['membership_type'];
228 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
229 $memTypeId1 = $memTypeId1[1];
231 $memTypeParams2 = $this->webtestAddMembershipType();
232 $memTypeTitle2 = $memTypeParams2['membership_type'];
233 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
234 $memTypeId2 = $memTypeId2[1];
236 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
238 foreach ($fields as $label => $type) {
239 $validateStrings[] = $label;
241 $this->type('label', $label);
242 $this->select('html_type', "value={$type}");
247 1 => array('label' => "$memTypeTitle1",
248 'membership_type_id' => $memTypeId1,
252 'label' => "$memTypeTitle2",
253 'membership_type_id' => $memTypeId2,
257 $this->addMultipleChoiceOptions($options, $validateStrings);
262 1 => array('label' => "$memTypeTitle1",
263 'membership_type_id' => $memTypeId1,
267 'label' => "$memTypeTitle2",
268 'membership_type_id' => $memTypeId2,
272 $this->addMultipleChoiceOptions($options, $validateStrings);
278 $this->select("financial_type_id", "label={$contributionType}");
279 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
280 $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved.");
282 return array($memTypeTitle1, $memTypeTitle2);
286 * @param $validateStrings
289 function _testVerifyPriceSet($validateStrings, $sid) {
290 // verify Price Set at Preview page
291 // start at Manage Price Sets listing
292 $this->openCiviPage('admin/price', 'reset=1');
294 // Use the price set id ($sid) to pick the correct row
295 $this->clickLink("css=tr#price_set-{$sid} a[title='Preview Price Set']", '_qf_Preview_cancel-bottom');
297 // Check for expected price set field strings
298 $this->assertStringsPresent($validateStrings);
303 * @param $contactParams
304 * @param $memTypeTitle1
305 * @param $memTypeTitle2
308 function _testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
309 $this->webtestLogout();
311 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
313 //build the membership dates.
314 $currentYear = date('Y');
315 $currentMonth = date('m');
316 $previousDay = date('d') - 1;
317 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
318 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
319 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
320 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
321 $configVars = new CRM_Core_Config_Variables();
323 'joinDate', 'startDate', 'endDate') as $date) {
324 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
327 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
328 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
330 $this->type('email-5', $contactParams['email-5']);
331 $this->type('first_name', $contactParams['first_name']);
332 $this->type('last_name', $contactParams['last_name']);
334 $streetAddress = "100 Main Street";
335 $this->type("street_address-1", $streetAddress);
336 $this->type("city-1", "San Francisco");
337 $this->type("postal_code-1", "94117");
338 $this->select("country-1", "value=1228");
339 $this->select("state_province-1", "value=1001");
342 $this->select("credit_card_type", "value=Visa");
343 $this->type("credit_card_number", "4111111111111111");
344 $this->type("cvv2", "000");
345 $this->select("credit_card_exp_date[M]", "value=1");
346 $this->select("credit_card_exp_date[Y]", "value=2020");
349 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
350 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
351 $this->type("billing_street_address-5", "15 Main St.");
352 $this->type(" billing_city-5", "San Jose");
353 $this->select("billing_country_id-5", "value=1228");
354 $this->select("billing_state_province_id-5", "value=1004");
355 $this->type("billing_postal_code-5", "94129");
356 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
358 $this->click("_qf_Confirm_next-bottom");
359 $this->waitForPageToLoad($this->getTimeoutMsec());
361 //login to check membership
363 // Log in using webtestLogin() method
364 $this->webtestLogin();
366 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
368 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
369 $this->click("_qf_Search_refresh");
371 $this->waitForPageToLoad($this->getTimeoutMsec());
372 $this->assertElementContainsText('crm-container', '2 Results');
374 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
375 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
376 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
378 //View Membership Record
380 'Membership Type' => "$memTypeTitle1",
382 'Member Since' => $joinDate,
383 'Start date' => $startDate,
384 'End date' => $endDate,
386 foreach ($verifyData as $label => $value) {
387 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
392 $this->clickLink('_qf_MembershipView_cancel-bottom', "xpath=//div[@id='memberSearch']/table/tbody/tr[2]", FALSE);
393 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle2}']/../td[11]/span/a[text()='View']");
394 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
396 //View Membership Record
398 'Membership Type' => "$memTypeTitle2",
400 'Member Since' => $joinDate,
401 'Start date' => $startDate,
402 'End date' => $endDate,
404 foreach ($verifyData as $label => $value) {
405 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
413 * @param $contactParams
414 * @param $memTypeTitle1
418 function _testMultilpeTermsMembershipRegistration($pageId, $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->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
423 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
424 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
425 $year = CRM_Utils_Date
::processDate($this->getText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='End date']/following-sibling::td"));
426 $prevYear = substr($year, 0, 4);
429 $this->webtestLogout();
431 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
433 //build the membership dates.
434 $currentYear = date('Y');
435 $currentMonth = date('m');
436 $previousDay = date('d') - 1;
437 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
438 $endYear = ($renew) ?
$endYear +
($prevYear - $currentYear) : $endYear;
440 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
441 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
442 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
443 $configVars = new CRM_Core_Config_Variables();
445 'joinDate', 'startDate', 'endDate') as $date) {
446 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
448 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
449 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
450 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
451 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
453 $this->type('email-5', $contactParams['email-5']);
454 $this->type('first_name', $contactParams['first_name']);
455 $this->type('last_name', $contactParams['last_name']);
457 $streetAddress = "100 Main Street";
458 $this->type("street_address-1", $streetAddress);
459 $this->type("city-1", "San Francisco");
460 $this->type("postal_code-1", "94117");
461 $this->select("country-1", "value=1228");
462 $this->select("state_province-1", "value=1001");
465 $this->select("credit_card_type", "value=Visa");
466 $this->type("credit_card_number", "4111111111111111");
467 $this->type("cvv2", "000");
468 $this->select("credit_card_exp_date[M]", "value=1");
469 $this->select("credit_card_exp_date[Y]", "value=2020");
472 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
473 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
474 $this->type("billing_street_address-5", "15 Main St.");
475 $this->type(" billing_city-5", "San Jose");
476 $this->select("billing_country_id-5", "value=1228");
477 $this->select("billing_state_province_id-5", "value=1004");
478 $this->type("billing_postal_code-5", "94129");
479 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
481 $this->click("_qf_Confirm_next-bottom");
482 $this->waitForPageToLoad($this->getTimeoutMsec());
484 //login to check membership
486 // Log in using webtestLogin() method
487 $this->webtestLogin();
489 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
491 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
492 $this->click("_qf_Search_refresh");
494 $this->waitForPageToLoad($this->getTimeoutMsec());
495 $this->assertElementContainsText('crm-container', '1 Result ');
497 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
498 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
499 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
501 //View Membership Record
503 'Membership Type' => "$memTypeTitle1",
505 'Member Since' => $joinDate,
506 'Start date' => $startDate,
507 'End date' => $endDate,
509 foreach ($verifyData as $label => $value) {
510 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
514 //check if the membership amount is correct
515 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']");
516 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));