3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 public 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 public 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]/div[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]}");
122 'label' => $memTypeTitle1 . "_1",
123 'membership_type_id' => $memTypeId1,
125 'membership_num_terms' => 1,
128 'label' => $memTypeTitle1 . "_2",
129 'membership_type_id' => $memTypeId1,
131 'membership_num_terms' => 2,
134 'label' => $memTypeTitle1 . "_3",
135 'membership_type_id' => $memTypeId1,
137 'membership_num_terms' => 3,
142 foreach ($options as $index => $values) {
143 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
144 $this->waitForAjaxContent();
145 $this->waitForElementPresent("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input");
146 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input", $values['membership_num_terms']);
147 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input", $values['label']);
148 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input", $values['amount']);
150 $this->click('link=another choice');
154 $this->waitForElementPresent('financial_type_id');
155 $this->select("financial_type_id", "label={$contributionType}");
156 $this->waitForElementPresent('_qf_Field_next-bottom');
157 $this->clickLink('_qf_Field_next-bottom');
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 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array('Test Processor' => 'Dummy'),
165 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
168 // Sign up for membership
169 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
170 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
171 $email = "{$firstName}.{$lastName}@example.com";
173 $contactParams = array(
174 'first_name' => $firstName,
175 'last_name' => $lastName,
178 //membership with number of terms as 2
179 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 2);
180 //membership with number of terms as 3 which will renew the above membership
181 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 3, TRUE);
188 * @param null $contributionType
191 public function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
192 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
194 // Enter Priceset fields (Title, Used For ...)
195 $this->type('title', $setTitle);
196 if ($usedFor == 'Event') {
197 $this->check('extends[1]');
199 elseif ($usedFor == 'Contribution') {
200 $this->check('extends[2]');
202 elseif ($usedFor == 'Membership') {
203 $this->click('extends[3]');
204 $this->waitForElementPresent('financial_type_id');
205 $this->select("css=select.crm-form-select", "label={$contributionType}");
208 $this->type('help_pre', $setHelp);
210 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
211 $this->waitForElementPresent('_qf_Set_next-bottom');
212 $this->click('_qf_Set_next-bottom');
213 $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
218 * @param $validateString
219 * @param bool $dateSpecificFields
222 * @param $contributionType
226 public function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
227 $memTypeParams1 = $this->webtestAddMembershipType();
228 $memTypeTitle1 = $memTypeParams1['membership_type'];
229 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle1}']/../../td[12]/span/a[3]@href"));
230 $memTypeId1 = $memTypeId1[1];
232 $memTypeParams2 = $this->webtestAddMembershipType();
233 $memTypeTitle2 = $memTypeParams2['membership_type'];
234 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle2}']/../../td[12]/span/a[3]@href"));
235 $memTypeId2 = $memTypeId2[1];
237 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
239 foreach ($fields as $label => $type) {
240 $validateStrings[] = $label;
242 $this->type('label', $label);
243 $this->select('html_type', "value={$type}");
249 'label' => "$memTypeTitle1",
250 'membership_type_id' => $memTypeId1,
254 'label' => "$memTypeTitle2",
255 'membership_type_id' => $memTypeId2,
259 $this->addMultipleChoiceOptions($options, $validateStrings);
265 'label' => "$memTypeTitle1",
266 'membership_type_id' => $memTypeId1,
270 'label' => "$memTypeTitle2",
271 'membership_type_id' => $memTypeId2,
275 $this->addMultipleChoiceOptions($options, $validateStrings);
281 $this->select("financial_type_id", "label={$contributionType}");
282 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
283 $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved.");
285 return array($memTypeTitle1, $memTypeTitle2);
289 * @param $validateStrings
292 public function _testVerifyPriceSet($validateStrings, $sid) {
293 // verify Price Set at Preview page
294 // start at Manage Price Sets listing
295 $this->openCiviPage('admin/price', 'reset=1');
297 // Use the price set id ($sid) to pick the correct row
298 $this->clickLink("css=tr#price_set-{$sid} a[title='Preview Price Set']", '_qf_Preview_cancel-bottom');
300 // Check for expected price set field strings
301 $this->assertStringsPresent($validateStrings);
306 * @param array $contactParams
307 * @param $memTypeTitle1
308 * @param $memTypeTitle2
311 public function _testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
312 $this->webtestLogout();
314 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
316 //build the membership dates.
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));
329 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
332 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
333 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
335 $this->type('email-5', $contactParams['email-5']);
336 $this->type('first_name', $contactParams['first_name']);
337 $this->type('last_name', $contactParams['last_name']);
339 $streetAddress = "100 Main Street";
340 $this->type("street_address-1", $streetAddress);
341 $this->type("city-1", "San Francisco");
342 $this->type("postal_code-1", "94117");
343 $this->select("country-1", "value=1228");
344 $this->select("state_province-1", "value=1001");
347 $this->select("credit_card_type", "value=Visa");
348 $this->type("credit_card_number", "4111111111111111");
349 $this->type("cvv2", "000");
350 $this->select("credit_card_exp_date[M]", "value=1");
351 $this->select("credit_card_exp_date[Y]", "value=2020");
354 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
355 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
356 $this->type("billing_street_address-5", "15 Main St.");
357 $this->type(" billing_city-5", "San Jose");
358 $this->select("billing_country_id-5", "value=1228");
359 $this->select("billing_state_province_id-5", "value=1004");
360 $this->type("billing_postal_code-5", "94129");
361 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
363 $this->click("_qf_Confirm_next-bottom");
364 $this->waitForPageToLoad($this->getTimeoutMsec());
366 //login to check membership
368 // Log in using webtestLogin() method
369 $this->webtestLogin();
371 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
373 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
374 $this->click("_qf_Search_refresh");
376 $this->waitForPageToLoad($this->getTimeoutMsec());
377 $this->assertElementContainsText('crm-container', '2 Results');
379 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
380 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
381 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
383 //View Membership Record
385 'Membership Type' => "$memTypeTitle1",
387 'Member Since' => $joinDate,
388 'Start date' => $startDate,
389 'End date' => $endDate,
391 foreach ($verifyData as $label => $value) {
392 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
397 $this->clickLink('_qf_MembershipView_cancel-bottom', "xpath=//div[@id='memberSearch']/table/tbody/tr[2]", FALSE);
398 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle2}']/../td[11]/span/a[text()='View']");
399 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
401 //View Membership Record
403 'Membership Type' => "$memTypeTitle2",
405 'Member Since' => $joinDate,
406 'Start date' => $startDate,
407 'End date' => $endDate,
409 foreach ($verifyData as $label => $value) {
410 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
418 * @param array $contactParams
419 * @param $memTypeTitle1
423 public function _testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, $term, $renew = FALSE) {
425 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
426 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
427 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
428 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
429 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
430 $year = CRM_Utils_Date
::processDate($this->getText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='End date']/following-sibling::td"));
431 $prevYear = substr($year, 0, 4);
434 $this->webtestLogout();
436 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
438 //build the membership dates.
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;
445 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
446 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
447 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
453 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
455 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1);
456 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
457 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
458 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
460 $this->type('email-5', $contactParams['email-5']);
461 $this->type('first_name', $contactParams['first_name']);
462 $this->type('last_name', $contactParams['last_name']);
464 $streetAddress = "100 Main Street";
465 $this->type("street_address-1", $streetAddress);
466 $this->type("city-1", "San Francisco");
467 $this->type("postal_code-1", "94117");
468 $this->select("country-1", "value=1228");
469 $this->select("state_province-1", "value=1001");
472 $this->select("credit_card_type", "value=Visa");
473 $this->type("credit_card_number", "4111111111111111");
474 $this->type("cvv2", "000");
475 $this->select("credit_card_exp_date[M]", "value=1");
476 $this->select("credit_card_exp_date[Y]", "value=2020");
479 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
480 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
481 $this->type("billing_street_address-5", "15 Main St.");
482 $this->type(" billing_city-5", "San Jose");
483 $this->select("billing_country_id-5", "value=1228");
484 $this->select("billing_state_province_id-5", "value=1004");
485 $this->type("billing_postal_code-5", "94129");
486 $this->clickLink("_qf_Main_upload-bottom", "_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->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr/td[1]/span[text()='{$amount}']");
523 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[2]/div[2]/table/tbody/tr/td[1]/span[text()='{$amount}']"));