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 $paymentProcessor = "Webtest Dummy $title";
71 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'),
72 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
75 // Sign up for membership
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($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2);
87 // Renew this membership
88 $this->_testSignUpOrRenewMembership($pageId, $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']/table/tbody//tr/td[1][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 $sid = $this->urlArg('sid');
113 $this->assertType('numeric', $sid);
115 $fields = array("National Membership $title", "Radio");
116 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
118 $validateStrings[] = $fields[0];
119 $this->type('label', $fields[0]);
120 $this->select('html_type', "value={$fields[1]}");
122 1 => array('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 // Because it tends to cause problems, all uses of sleep() must be justified in comments
145 // Sleep should never be used for wait for anything to load from the server
146 // Justification for this instance: FIXME
148 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']);
149 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']);
150 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']);
152 $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->waitForText('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 $pageId = $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 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
175 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
176 $email = "{$firstName}.{$lastName}@example.com";
178 $contactParams = array(
179 'first_name' => $firstName,
180 'last_name' => $lastName,
183 //membership with number of terms as 2
184 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 2);
185 //membership with number of terms as 3 which will renew the above membership
186 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 3, TRUE);
193 * @param null $contributionType
196 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
197 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
199 // Enter Priceset fields (Title, Used For ...)
200 $this->type('title', $setTitle);
201 if ($usedFor == 'Event') {
202 $this->check('extends[1]');
204 elseif ($usedFor == 'Contribution') {
205 $this->check('extends[2]');
207 elseif ($usedFor == 'Membership') {
208 $this->click('extends[3]');
209 $this->waitForElementPresent( 'financial_type_id' );
210 $this->select("css=select.crm-form-select", "label={$contributionType}");
213 $this->type('help_pre', $setHelp);
215 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
216 $this->waitForElementPresent('_qf_Set_next-bottom');
217 $this->click('_qf_Set_next-bottom');
218 $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
223 * @param $validateString
224 * @param bool $dateSpecificFields
227 * @param $contributionType
231 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
232 $memTypeParams1 = $this->webtestAddMembershipType();
233 $memTypeTitle1 = $memTypeParams1['membership_type'];
234 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
235 $memTypeId1 = $memTypeId1[1];
237 $memTypeParams2 = $this->webtestAddMembershipType();
238 $memTypeTitle2 = $memTypeParams2['membership_type'];
239 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1][text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
240 $memTypeId2 = $memTypeId2[1];
242 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
244 foreach ($fields as $label => $type) {
245 $validateStrings[] = $label;
247 $this->type('label', $label);
248 $this->select('html_type', "value={$type}");
253 1 => array('label' => "$memTypeTitle1",
254 'membership_type_id' => $memTypeId1,
258 'label' => "$memTypeTitle2",
259 'membership_type_id' => $memTypeId2,
263 $this->addMultipleChoiceOptions($options, $validateStrings);
268 1 => array('label' => "$memTypeTitle1",
269 'membership_type_id' => $memTypeId1,
273 'label' => "$memTypeTitle2",
274 'membership_type_id' => $memTypeId2,
278 $this->addMultipleChoiceOptions($options, $validateStrings);
284 $this->select("financial_type_id", "label={$contributionType}");
285 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
286 $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved.");
288 return array($memTypeTitle1, $memTypeTitle2);
292 * @param $validateStrings
295 function _testVerifyPriceSet($validateStrings, $sid) {
296 // verify Price Set at Preview page
297 // start at Manage Price Sets listing
298 $this->openCiviPage('admin/price', 'reset=1');
300 // Use the price set id ($sid) to pick the correct row
301 $this->clickLink("css=tr#price_set-{$sid} a[title='Preview Price Set']", '_qf_Preview_cancel-bottom');
303 // Check for expected price set field strings
304 $this->assertStringsPresent($validateStrings);
309 * @param $contactParams
310 * @param $memTypeTitle1
311 * @param $memTypeTitle2
314 function _testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
315 $this->webtestLogout();
317 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
319 //build the membership dates.
320 $currentYear = date('Y');
321 $currentMonth = date('m');
322 $previousDay = date('d') - 1;
323 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
324 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
325 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
326 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
327 $configVars = new CRM_Core_Config_Variables();
329 'joinDate', 'startDate', 'endDate') as $date) {
330 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
333 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
334 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
336 $this->type('email-5', $contactParams['email-5']);
337 $this->type('first_name', $contactParams['first_name']);
338 $this->type('last_name', $contactParams['last_name']);
340 $streetAddress = "100 Main Street";
341 $this->type("street_address-1", $streetAddress);
342 $this->type("city-1", "San Francisco");
343 $this->type("postal_code-1", "94117");
344 $this->select("country-1", "value=1228");
345 $this->select("state_province-1", "value=1001");
348 $this->select("credit_card_type", "value=Visa");
349 $this->type("credit_card_number", "4111111111111111");
350 $this->type("cvv2", "000");
351 $this->select("credit_card_exp_date[M]", "value=1");
352 $this->select("credit_card_exp_date[Y]", "value=2020");
355 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
356 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
357 $this->type("billing_street_address-5", "15 Main St.");
358 $this->type(" billing_city-5", "San Jose");
359 $this->select("billing_country_id-5", "value=1228");
360 $this->select("billing_state_province_id-5", "value=1004");
361 $this->type("billing_postal_code-5", "94129");
362 $this->clickLink("_qf_Main_upload-bottom", "_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->clickLink('_qf_MembershipView_cancel-bottom', "xpath=//div[@id='memberSearch']/table/tbody/tr[2]", FALSE);
399 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle2}']/../td[11]/span/a[text()='View']");
400 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
402 //View Membership Record
404 'Membership Type' => "$memTypeTitle2",
406 'Member Since' => $joinDate,
407 'Start date' => $startDate,
408 'End date' => $endDate,
410 foreach ($verifyData as $label => $value) {
411 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
419 * @param $contactParams
420 * @param $memTypeTitle1
424 function _testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, $term, $renew = FALSE){
426 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
427 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
428 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
429 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
430 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
431 $year = CRM_Utils_Date
::processDate($this->getText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='End date']/following-sibling::td"));
432 $prevYear = substr($year, 0, 4);
435 $this->webtestLogout();
437 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
439 //build the membership dates.
440 $currentYear = date('Y');
441 $currentMonth = date('m');
442 $previousDay = date('d') - 1;
443 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
444 $endYear = ($renew) ?
$endYear +
($prevYear - $currentYear) : $endYear;
446 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
447 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
448 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
449 $configVars = new CRM_Core_Config_Variables();
451 'joinDate', 'startDate', 'endDate') as $date) {
452 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
454 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
455 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
456 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
457 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
459 $this->type('email-5', $contactParams['email-5']);
460 $this->type('first_name', $contactParams['first_name']);
461 $this->type('last_name', $contactParams['last_name']);
463 $streetAddress = "100 Main Street";
464 $this->type("street_address-1", $streetAddress);
465 $this->type("city-1", "San Francisco");
466 $this->type("postal_code-1", "94117");
467 $this->select("country-1", "value=1228");
468 $this->select("state_province-1", "value=1001");
471 $this->select("credit_card_type", "value=Visa");
472 $this->type("credit_card_number", "4111111111111111");
473 $this->type("cvv2", "000");
474 $this->select("credit_card_exp_date[M]", "value=1");
475 $this->select("credit_card_exp_date[Y]", "value=2020");
478 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
479 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
480 $this->type("billing_street_address-5", "15 Main St.");
481 $this->type(" billing_city-5", "San Jose");
482 $this->select("billing_country_id-5", "value=1228");
483 $this->select("billing_state_province_id-5", "value=1004");
484 $this->type("billing_postal_code-5", "94129");
485 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
487 $this->click("_qf_Confirm_next-bottom");
488 $this->waitForPageToLoad($this->getTimeoutMsec());
490 //login to check membership
492 // Log in using webtestLogin() method
493 $this->webtestLogin();
495 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
497 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
498 $this->click("_qf_Search_refresh");
500 $this->waitForPageToLoad($this->getTimeoutMsec());
501 $this->assertElementContainsText('crm-container', '1 Result ');
503 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
504 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
505 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
507 //View Membership Record
509 'Membership Type' => "$memTypeTitle1",
511 'Member Since' => $joinDate,
512 'Start date' => $startDate,
513 'End date' => $endDate,
515 foreach ($verifyData as $label => $value) {
516 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
520 //check if the membership amount is correct
521 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']");
522 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));