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_OfflineMembershipAddPricesetTest
32 class WebTest_Member_OfflineMembershipAddPricesetTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAddPriceSet() {
39 // Log in using webtestLogin() method
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 $sid = $this->urlArg('sid');
52 $this->assertType('numeric', $sid);
55 "National Membership $title" => 'Radio',
56 "Local Chapter $title" => 'CheckBox',
59 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
61 // load the Price Set Preview and check for expected values
62 $this->_testVerifyPriceSet($validateStrings, $sid);
64 // Sign up for membership
65 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
66 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
67 $email = "{$firstName}.{$lastName}@example.com";
68 $contactParams = array(
69 'first_name' => $firstName,
70 'last_name' => $lastName,
74 // Add a contact from the quick add block
75 $this->webtestAddContact($firstName, $lastName, $email);
77 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2);
79 // Renew this membership
80 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
83 public function testAddPriceSetWithMultipleTerms() {
84 // Log in using webtestLogin() method
85 $this->webtestLogin();
87 $title = substr(sha1(rand()), 0, 7);
88 $setTitle = "Membership Fees - $title";
89 $usedFor = 'Membership';
90 $contributionType = 'Member Dues';
91 $setHelp = 'Select your membership options.';
92 $memTypeParams1 = $this->webtestAddMembershipType();
93 $memTypeTitle1 = $memTypeParams1['membership_type'];
94 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle1}']/../../td[12]/span/a[3]@href"));
95 $memTypeId1 = $memTypeId1[1];
96 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
98 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
99 // which is where we are after adding Price Set.
100 $sid = $this->urlArg('sid');
101 $this->assertType('numeric', $sid);
103 $fields = array("National Membership $title", "Radio");
104 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
106 $validateStrings[] = $fields[0];
107 $this->type('label', $fields[0]);
108 $this->select('html_type', "value={$fields[1]}");
111 'label' => $memTypeTitle1 . "_1",
112 'membership_type_id' => $memTypeId1,
114 'membership_num_terms' => 1,
117 'label' => $memTypeTitle1 . "_2",
118 'membership_type_id' => $memTypeId1,
120 'membership_num_terms' => 2,
123 'label' => $memTypeTitle1 . "_3",
124 'membership_type_id' => $memTypeId1,
126 'membership_num_terms' => 3,
130 foreach ($options as $index => $values) {
131 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
132 // Because it tends to cause problems, all uses of sleep() must be justified in comments
133 // Sleep should never be used for wait for anything to load from the server
134 // Justification for this instance: FIXME
136 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input", $values['membership_num_terms']);
137 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input", $values['label']);
138 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input", $values['amount']);
140 $this->click('link=another choice');
144 $this->waitForElementPresent('financial_type_id');
145 $this->select("financial_type_id", "label={$contributionType}");
146 $this->waitForElementPresent('_qf_Field_next-bottom');
147 $this->click('_qf_Field_next-bottom');
148 $this->waitForText('crm-notification-container', "Price Field '{$fields[0]}' has been saved.");
150 // load the Price Set Preview and check for expected values
151 $this->_testVerifyPriceSet($validateStrings, $sid);
153 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
154 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
155 $email = "{$firstName}.{$lastName}@example.com";
157 $contactParams = array(
158 'first_name' => $firstName,
159 'last_name' => $lastName,
162 $this->webtestAddContact($firstName, $lastName, $email);
163 //membership with number of terms as 3
164 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 3);
165 //membership with number of terms as 2
166 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 2);
173 * @param null $contributionType
176 public function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
177 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
179 // Enter Priceset fields (Title, Used For ...)
180 $this->type('title', $setTitle);
181 if ($usedFor == 'Event') {
182 $this->check('extends_1');
184 elseif ($usedFor == 'Contribution') {
185 $this->check('extends_2');
187 elseif ($usedFor == 'Membership') {
188 $this->click('extends_3');
189 $this->waitForElementPresent('financial_type_id');
190 $this->select("css=select.crm-form-select", "label={$contributionType}");
192 $this->type('help_pre', $setHelp);
193 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
195 $this->click('_qf_Set_next-bottom');
196 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']//div[2]/a");
197 $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
202 * @param $validateString
203 * @param bool $dateSpecificFields
206 * @param $contributionType
210 public function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
211 $memTypeParams1 = $this->webtestAddMembershipType();
212 $memTypeTitle1 = $memTypeParams1['membership_type'];
214 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle1}']/../../td[12]/span/a[3]@href"));
215 $memTypeId1 = $memTypeId1[1];
217 $memTypeParams2 = $this->webtestAddMembershipType();
218 $memTypeTitle2 = $memTypeParams2['membership_type'];
219 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td[1]/div[text()='{$memTypeTitle2}']/../../td[12]/span/a[3]@href"));
220 $memTypeId2 = $memTypeId2[1];
222 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
224 foreach ($fields as $label => $type) {
225 $validateStrings[] = $label;
227 $this->type('label', $label);
228 $this->select('html_type', "value={$type}");
234 'label' => "$memTypeTitle1",
235 'membership_type_id' => $memTypeId1,
239 'label' => "$memTypeTitle2",
240 'membership_type_id' => $memTypeId2,
244 $this->addMultipleChoiceOptions($options, $validateStrings);
250 'label' => "$memTypeTitle1",
251 'membership_type_id' => $memTypeId1,
255 'label' => "$memTypeTitle2",
256 'membership_type_id' => $memTypeId2,
260 $this->addMultipleChoiceOptions($options, $validateStrings);
266 $this->select("financial_type_id", "label={$contributionType}");
267 $this->click('_qf_Field_next_new-bottom');
268 $this->waitForPageToLoad($this->getTimeoutMsec());
269 $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved.");
271 return array($memTypeTitle1, $memTypeTitle2);
275 * @param $validateStrings
278 public function _testVerifyPriceSet($validateStrings, $sid) {
279 // verify Price Set at Preview page
280 // start at Manage Price Sets listing
281 $this->openCiviPage('admin/price', 'reset=1');
283 // Use the price set id ($sid) to pick the correct row
284 $this->click("css=tr#price_set-{$sid} a[title='Preview Price Set']");
286 // Look for Register button
287 $this->waitForElementPresent('_qf_Preview_cancel-bottom');
289 // Check for expected price set field strings
290 $this->assertStringsPresent($validateStrings);
295 * @param array $contactParams
296 * @param $memTypeTitle1
297 * @param $memTypeTitle2
300 public function _testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
301 //build the membership dates.
302 require_once 'CRM/Core/Config.php';
303 require_once 'CRM/Utils/Array.php';
304 require_once 'CRM/Utils/Date.php';
305 $currentYear = date('Y');
306 $currentMonth = date('m');
307 $previousDay = date('d') - 1;
308 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
309 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
310 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
311 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
317 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
322 $this->click('css=li#tab_member a');
323 $this->waitForElementPresent('link=Add Membership');
324 if ($this->isTextPresent("No memberships have been recorded for this contact.")) {
325 $this->waitForTextPresent('No memberships have been recorded for this contact.');
328 $this->clickAjaxLink('link=Add Membership');
329 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
331 $this->select('price_set_id', "value={$sid}");
332 $this->waitForElementPresent('pricesetTotal');
334 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
335 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
337 $this->type('source', 'Offline membership Sign Up Test Text');
338 $this->click('_qf_Membership_upload-bottom');
341 $this->click("xpath=//div[@id='memberships']/div//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span[2][text()='Renew...']/ul/li/a[text()='Renew']");
342 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
343 $this->waitForAjaxContent();
344 $this->click('_qf_MembershipRenewal_upload-bottom');
346 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
347 $this->click("xpath=//div[@id='memberships']/div//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span[2][text()='Renew...']/ul/li/a[text()='Renew']");
348 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
349 $this->waitForAjaxContent();
350 $this->click('_qf_MembershipRenewal_upload-bottom');
352 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span/a[text()='View']");
353 $this->waitForAjaxContent();
354 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span/a[text()='View']");
355 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]");
357 //View Membership Record
359 'Membership Type' => "{$memTypeTitle1}",
361 'Member Since' => $joinDate,
362 'Start date' => $startDate,
363 'End date' => $endDate,
365 $this->webtestVerifyTabularData($verifyData);
367 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
368 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span/a[text()='View']");
369 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span/a[text()='View']");
370 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]");
372 //View Membership Record
374 'Membership Type' => "{$memTypeTitle2}",
376 'Member Since' => $joinDate,
377 'Start date' => $startDate,
378 'End date' => $endDate,
380 $this->webtestVerifyTabularData($verifyData);
382 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
383 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
388 * @param array $contactParams
389 * @param $memTypeTitle1
392 public function _testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, $term) {
393 //build the membership dates.
394 require_once 'CRM/Core/Config.php';
395 require_once 'CRM/Utils/Array.php';
396 require_once 'CRM/Utils/Date.php';
397 $currentYear = date('Y');
398 $currentMonth = date('m');
399 $previousDay = date('d') - 1;
400 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
401 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
402 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
403 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
409 $
$date = CRM_Utils_Date
::customFormat($
$date, $this->webtestGetSetting('dateformatFull'));
412 $this->click('css=li#tab_member a');
413 $this->waitForElementPresent('link=Add Membership');
414 if ($this->isTextPresent("No memberships have been recorded for this contact.")) {
415 $this->waitForTextPresent('No memberships have been recorded for this contact.');
418 $this->clickAjaxLink('link=Add Membership');
419 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
421 $this->select('price_set_id', "value={$sid}");
422 $this->waitForElementPresent('pricesetTotal');
424 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1);
425 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
426 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
427 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
429 $this->type('source', 'Offline membership Sign Up Test Text');
430 $this->waitForElementPresent('recordContribution');
431 $this->click('_qf_Membership_upload-bottom');
433 $this->waitForElementPresent("xpath=//table[@class='display dataTable no-footer']/tbody//tr/td[4][text()='{$endDate}']/../td[9]/span[1]/a[1]");
434 $this->click("xpath=//table[@class='display dataTable no-footer']/tbody//tr/td[4][text()='{$endDate}']/../td[9]/span[1]/a[1]");
435 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]");
436 //View Membership Record
438 'Membership Type' => "$memTypeTitle1",
440 'Member Since' => $joinDate,
441 'Start date' => $startDate,
442 'End date' => $endDate,
444 $this->webtestVerifyTabularData($verifyData);
446 //check if the membership amount is correct
447 $this->waitForElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[@class='crm-accordion-wrapper']/div/table/tbody/tr/td/span[text()='{$amount}']");
448 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/div[@class='crm-accordion-wrapper']/div/table/tbody/tr/td/span[text()='{$amount}']"));
449 $this->click("_qf_MembershipView_cancel-bottom");