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 $elements = $this->parseURL();
52 $sid = $elements['queryString']['sid'];
53 $this->assertType('numeric', $sid);
56 "National Membership $title" => 'Radio',
57 "Local Chapter $title" => 'CheckBox',
60 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
61 //var_dump($validateStrings);
63 // load the Price Set Preview and check for expected values
64 $this->_testVerifyPriceSet($validateStrings, $sid);
66 $contributionPageTitle = "Contribution Page $title";
67 $paymentProcessor = "Webtest Dummy $title";
68 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'),
69 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
72 // Sign up for membership
73 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
74 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
75 $email = "{$firstName}.{$lastName}@example.com";
77 $contactParams = array(
78 'first_name' => $firstName,
79 'last_name' => $lastName,
82 $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2);
84 // Renew this membership
85 $this->_testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
88 function testAddPriceSetWithMultipleTerms() {
89 // add the required permission
90 $permissions = array('edit-1-make-online-contributions');
91 $this->changePermissions($permissions);
93 // Log in as normal user
94 $this->webtestLogin();
96 $title = substr(sha1(rand()), 0, 7);
97 $setTitle = "Membership Fees - $title";
98 $usedFor = 'Membership';
99 $contributionType = 'Member Dues';
100 $setHelp = 'Select your membership options.';
101 $memTypeParams1 = $this->webtestAddMembershipType();
102 $memTypeTitle1 = $memTypeParams1['membership_type'];
103 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
104 $memTypeId1 = $memTypeId1[1];
105 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
107 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
108 // which is where we are after adding Price Set.
109 $elements = $this->parseURL();
110 $sid = $elements['queryString']['sid'];
111 $this->assertType('numeric', $sid);
113 $fields = array("National Membership $title", "Radio");
114 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
116 $validateStrings[] = $fields[0];
117 $this->type('label', $fields[0]);
118 $this->select('html_type', "value={$fields[1]}");
120 1 => array('label' => $memTypeTitle1."_1",
121 'membership_type_id' => $memTypeId1,
123 'membership_num_terms' => 1,
126 'label' => $memTypeTitle1."_2",
127 'membership_type_id' => $memTypeId1,
129 'membership_num_terms' => 2,
132 'label' => $memTypeTitle1."_3",
133 'membership_type_id' => $memTypeId1,
135 'membership_num_terms' => 3,
140 foreach($options as $index => $values){
141 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
142 // Because it tends to cause problems, all uses of sleep() must be justified in comments
143 // Sleep should never be used for wait for anything to load from the server
144 // Justification for this instance: FIXME
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');
155 $this->waitForElementPresent( 'financial_type_id' );
156 $this->select("financial_type_id", "label={$contributionType}");
157 $this->waitForElementPresent('_qf_Field_next-bottom');
158 $this->click('_qf_Field_next-bottom');
159 $this->waitForPageToLoad($this->getTimeoutMsec());
160 $this->waitForText('crm-notification-container', "Price Field '{$fields[0]}' has been saved.");
162 // load the Price Set Preview and check for expected values
163 $this->_testVerifyPriceSet($validateStrings, $sid);
165 $contributionPageTitle = "Contribution Page $title";
166 $paymentProcessor = "Webtest Dummy $title";
167 $pageId = $this->webtestAddContributionPage(NULL, NULL, $contributionPageTitle, array($paymentProcessor => 'Dummy'),
168 TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, $sid, FALSE, 1, NULL
171 // Sign up for membership
172 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
173 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
174 $email = "{$firstName}.{$lastName}@example.com";
176 $contactParams = array(
177 'first_name' => $firstName,
178 'last_name' => $lastName,
181 //membership with number of terms as 2
182 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 2);
183 //membership with number of terms as 3 which will renew the above membership
184 $this->_testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, 3, TRUE);
188 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
189 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
191 // Enter Priceset fields (Title, Used For ...)
192 $this->type('title', $setTitle);
193 if ($usedFor == 'Event') {
194 $this->check('extends[1]');
196 elseif ($usedFor == 'Contribution') {
197 $this->check('extends[2]');
199 elseif ($usedFor == 'Membership') {
200 $this->click('extends[3]');
201 $this->waitForElementPresent( 'financial_type_id' );
202 $this->select("css=select.form-select", "label={$contributionType}");
205 $this->type('help_pre', $setHelp);
207 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
208 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
209 $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
212 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
213 $memTypeParams1 = $this->webtestAddMembershipType();
214 $memTypeTitle1 = $memTypeParams1['membership_type'];
215 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
216 $memTypeId1 = $memTypeId1[1];
218 $memTypeParams2 = $this->webtestAddMembershipType();
219 $memTypeTitle2 = $memTypeParams2['membership_type'];
220 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
221 $memTypeId2 = $memTypeId2[1];
223 $this->openCiviPage('admin/price/field', "reset=1&action=add&sid={$sid}");
225 foreach ($fields as $label => $type) {
226 $validateStrings[] = $label;
228 $this->type('label', $label);
229 $this->select('html_type', "value={$type}");
234 1 => array('label' => "$memTypeTitle1",
235 'membership_type_id' => $memTypeId1,
239 'label' => "$memTypeTitle2",
240 'membership_type_id' => $memTypeId2,
244 $this->addMultipleChoiceOptions($options, $validateStrings);
249 1 => array('label' => "$memTypeTitle1",
250 'membership_type_id' => $memTypeId1,
254 'label' => "$memTypeTitle2",
255 'membership_type_id' => $memTypeId2,
259 $this->addMultipleChoiceOptions($options, $validateStrings);
265 $this->select("financial_type_id", "label={$contributionType}");
266 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
267 $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved.");
269 return array($memTypeTitle1, $memTypeTitle2);
272 function _testVerifyPriceSet($validateStrings, $sid) {
273 // verify Price Set at Preview page
274 // start at Manage Price Sets listing
275 $this->openCiviPage('admin/price', 'reset=1');
277 // Use the price set id ($sid) to pick the correct row
278 $this->clickLink("css=tr#row_{$sid} a[title='Preview Price Set']", '_qf_Preview_cancel-bottom');
280 // Check for expected price set field strings
281 $this->assertStringsPresent($validateStrings);
284 function _testSignUpOrRenewMembership($pageId, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
285 $this->webtestLogout();
287 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
289 //build the membership dates.
290 $currentYear = date('Y');
291 $currentMonth = date('m');
292 $previousDay = date('d') - 1;
293 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
294 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
295 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
296 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
297 $configVars = new CRM_Core_Config_Variables();
299 'joinDate', 'startDate', 'endDate') as $date) {
300 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
303 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
304 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
306 $this->type('email-5', $contactParams['email-5']);
307 $this->type('first_name', $contactParams['first_name']);
308 $this->type('last_name', $contactParams['last_name']);
310 $streetAddress = "100 Main Street";
311 $this->type("street_address-1", $streetAddress);
312 $this->type("city-1", "San Francisco");
313 $this->type("postal_code-1", "94117");
314 $this->select("country-1", "value=1228");
315 $this->select("state_province-1", "value=1001");
318 $this->select("credit_card_type", "value=Visa");
319 $this->type("credit_card_number", "4111111111111111");
320 $this->type("cvv2", "000");
321 $this->select("credit_card_exp_date[M]", "value=1");
322 $this->select("credit_card_exp_date[Y]", "value=2020");
325 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
326 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
327 $this->type("billing_street_address-5", "15 Main St.");
328 $this->type(" billing_city-5", "San Jose");
329 $this->select("billing_country_id-5", "value=1228");
330 $this->select("billing_state_province_id-5", "value=1004");
331 $this->type("billing_postal_code-5", "94129");
332 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
334 $this->click("_qf_Confirm_next-bottom");
335 $this->waitForPageToLoad($this->getTimeoutMsec());
337 //login to check membership
339 // Log in using webtestLogin() method
340 $this->webtestLogin();
342 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
344 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
345 $this->click("_qf_Search_refresh");
347 $this->waitForPageToLoad($this->getTimeoutMsec());
348 $this->assertElementContainsText('crm-container', '2 Results');
350 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
351 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
352 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
354 //View Membership Record
356 'Membership Type' => "$memTypeTitle1",
358 'Member Since' => $joinDate,
359 'Start date' => $startDate,
360 'End date' => $endDate,
362 foreach ($verifyData as $label => $value) {
363 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
368 $this->clickLink('_qf_MembershipView_cancel-bottom', "xpath=//div[@id='memberSearch']/table/tbody/tr[2]");
369 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle2}']/../td[11]/span/a[text()='View']");
370 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
372 //View Membership Record
374 'Membership Type' => "$memTypeTitle2",
376 'Member Since' => $joinDate,
377 'Start date' => $startDate,
378 'End date' => $endDate,
380 foreach ($verifyData as $label => $value) {
381 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
387 function _testMultilpeTermsMembershipRegistration($pageId, $contactParams, $memTypeTitle1, $term, $renew = FALSE){
389 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
390 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
391 $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='memberSearch']/table/tbody/tr");
392 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
393 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
394 $year = CRM_Utils_Date
::processDate($this->getText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='End date']/following-sibling::td"));
395 $prevYear = substr($year, 0, 4);
398 $this->webtestLogout();
400 $this->openCiviPage('contribute/transact', "reset=1&id=$pageId", '_qf_Main_upload-bottom');
402 //build the membership dates.
403 $currentYear = date('Y');
404 $currentMonth = date('m');
405 $previousDay = date('d') - 1;
406 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
407 $endYear = ($renew) ?
$endYear +
($prevYear - $currentYear) : $endYear;
409 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
410 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
411 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
412 $configVars = new CRM_Core_Config_Variables();
414 'joinDate', 'startDate', 'endDate') as $date) {
415 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
417 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
418 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
419 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
420 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
422 $this->type('email-5', $contactParams['email-5']);
423 $this->type('first_name', $contactParams['first_name']);
424 $this->type('last_name', $contactParams['last_name']);
426 $streetAddress = "100 Main Street";
427 $this->type("street_address-1", $streetAddress);
428 $this->type("city-1", "San Francisco");
429 $this->type("postal_code-1", "94117");
430 $this->select("country-1", "value=1228");
431 $this->select("state_province-1", "value=1001");
434 $this->select("credit_card_type", "value=Visa");
435 $this->type("credit_card_number", "4111111111111111");
436 $this->type("cvv2", "000");
437 $this->select("credit_card_exp_date[M]", "value=1");
438 $this->select("credit_card_exp_date[Y]", "value=2020");
441 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
442 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
443 $this->type("billing_street_address-5", "15 Main St.");
444 $this->type(" billing_city-5", "San Jose");
445 $this->select("billing_country_id-5", "value=1228");
446 $this->select("billing_state_province_id-5", "value=1004");
447 $this->type("billing_postal_code-5", "94129");
448 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
450 $this->click("_qf_Confirm_next-bottom");
451 $this->waitForPageToLoad($this->getTimeoutMsec());
453 //login to check membership
455 // Log in using webtestLogin() method
456 $this->webtestLogin();
458 $this->openCiviPage('member/search', 'reset=1', 'member_end_date_high');
460 $this->type("sort_name", "{$contactParams['first_name']} {$contactParams['last_name']}");
461 $this->click("_qf_Search_refresh");
463 $this->waitForPageToLoad($this->getTimeoutMsec());
464 $this->assertElementContainsText('crm-container', '1 Result ');
466 $this->waitForElementPresent("xpath=//div[@id='memberSearch']/table/tbody/tr");
467 $this->click("xpath=//div[@id='memberSearch']/table/tbody//tr/td[4][text()='{$memTypeTitle1}']/../td[11]/span/a[text()='View']");
468 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
470 //View Membership Record
472 'Membership Type' => "$memTypeTitle1",
474 'Member Since' => $joinDate,
475 'Start date' => $startDate,
476 'End date' => $endDate,
478 foreach ($verifyData as $label => $value) {
479 $this->verifyText("xpath=//form[@id='MembershipView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td",
483 //check if the membership amount is correct
484 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));