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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Member_OfflineMembershipAddPricesetTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testAddPriceSet() {
36 // This is the path where our testing install resides.
37 // The rest of URL is defined in CiviSeleniumTestCase base class, in
39 $this->open($this->sboxPath
);
41 // Log in using webtestLogin() method
42 $this->webtestLogin();
44 $title = substr(sha1(rand()), 0, 7);
45 $setTitle = "Membership Fees - $title";
46 $usedFor = 'Membership';
47 $contributionType = 'Donation';
48 $setHelp = 'Select your membership options.';
49 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
51 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
52 // which is where we are after adding Price Set.
53 $elements = $this->parseURL();
54 $sid = $elements['queryString']['sid'];
55 $this->assertType('numeric', $sid);
58 "National Membership $title" => 'Radio',
59 "Local Chapter $title" => 'CheckBox',
62 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
64 // load the Price Set Preview and check for expected values
65 $this->_testVerifyPriceSet($validateStrings, $sid);
67 // Sign up for membership
68 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
69 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
70 $email = "{$firstName}.{$lastName}@example.com";
71 $contactParams = array(
72 'first_name' => $firstName,
73 'last_name' => $lastName,
77 // Add a contact from the quick add block
78 $this->webtestAddContact($firstName, $lastName, $email);
80 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2);
82 // Renew this membership
83 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
86 function testAddPriceSetWithMultipleTerms() {
87 // This is the path where our testing install resides.
88 // The rest of URL is defined in CiviSeleniumTestCase base class, in
90 $this->open($this->sboxPath
);
92 // Log in using webtestLogin() method
93 $this->webtestLogin();
95 $title = substr(sha1(rand()), 0, 7);
96 $setTitle = "Membership Fees - $title";
97 $usedFor = 'Membership';
98 $contributionType = 'Member Dues';
99 $setHelp = 'Select your membership options.';
100 $memTypeParams1 = $this->webtestAddMembershipType();
101 $memTypeTitle1 = $memTypeParams1['membership_type'];
102 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
103 $memTypeId1 = $memTypeId1[1];
104 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
106 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
107 // which is where we are after adding Price Set.
108 $elements = $this->parseURL();
109 $sid = $elements['queryString']['sid'];
110 $this->assertType('numeric', $sid);
112 $fields = array("National Membership $title", "Radio");
113 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
115 $validateStrings[] = $fields[0];
116 $this->type('label', $fields[0]);
117 $this->select('html_type', "value={$fields[1]}");
119 1 => array('label' => $memTypeTitle1."_1",
120 'membership_type_id' => $memTypeId1,
122 'membership_num_terms' => 1,
125 'label' => $memTypeTitle1."_2",
126 'membership_type_id' => $memTypeId1,
128 'membership_num_terms' => 2,
131 'label' => $memTypeTitle1."_3",
132 'membership_type_id' => $memTypeId1,
134 'membership_num_terms' => 3,
138 foreach($options as $index => $values){
139 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
141 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']);
142 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']);
143 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']);
145 $this->click('link=another choice');
149 $this->waitForElementPresent( 'financial_type_id' );
150 $this->select("financial_type_id", "label={$contributionType}");
151 $this->waitForElementPresent('_qf_Field_next-bottom');
152 $this->click('_qf_Field_next-bottom');
153 $this->waitForPageToLoad($this->getTimeoutMsec());
154 $this->assertTrue($this->isTextPresent("Price Field '{$fields[0]}' has been saved."));
156 // load the Price Set Preview and check for expected values
157 $this->_testVerifyPriceSet($validateStrings, $sid);
159 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
160 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
161 $email = "{$firstName}.{$lastName}@example.com";
163 $contactParams = array(
164 'first_name' => $firstName,
165 'last_name' => $lastName,
168 $this->webtestAddContact($firstName, $lastName, $email);
169 //membership with number of terms as 3
170 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 3);
171 //membership with number of terms as 2
172 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 2);
177 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
178 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
180 // Enter Priceset fields (Title, Used For ...)
181 $this->type('title', $setTitle);
182 if ($usedFor == 'Event') {
183 $this->check('extends_1');
185 elseif ($usedFor == 'Contribution') {
186 $this->check('extends_2');
188 elseif ($usedFor == 'Membership') {
189 $this->click('extends_3');
190 $this->waitForElementPresent('financial_type_id');
191 $this->select("css=select.form-select", "label={$contributionType}");
193 $this->type('help_pre', $setHelp);
194 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
196 $this->click('_qf_Set_next-bottom');
197 $this->waitForElementPresent('_qf_Field_next-bottom');
198 $this->assertElementContainsText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
201 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
202 $memTypeParams1 = $this->webtestAddMembershipType();
203 $memTypeTitle1 = $memTypeParams1['membership_type'];
205 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
206 $memTypeId1 = $memTypeId1[1];
208 $memTypeParams2 = $this->webtestAddMembershipType();
209 $memTypeTitle2 = $memTypeParams2['membership_type'];
210 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
211 $memTypeId2 = $memTypeId2[1];
213 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
215 foreach ($fields as $label => $type) {
216 $validateStrings[] = $label;
218 $this->type('label', $label);
219 $this->select('html_type', "value={$type}");
224 1 => array('label' => "$memTypeTitle1",
225 'membership_type_id' => $memTypeId1,
229 'label' => "$memTypeTitle2",
230 'membership_type_id' => $memTypeId2,
234 $this->addMultipleChoiceOptions($options, $validateStrings);
239 1 => array('label' => "$memTypeTitle1",
240 'membership_type_id' => $memTypeId1,
244 'label' => "$memTypeTitle2",
245 'membership_type_id' => $memTypeId2,
249 $this->addMultipleChoiceOptions($options, $validateStrings);
255 $this->select("financial_type_id", "label={$contributionType}");
256 $this->click('_qf_Field_next_new-bottom');
257 $this->waitForPageToLoad($this->getTimeoutMsec());
258 $this->assertElementContainsText('crm-notification-container', "Price Field '{$label}' has been saved.");
260 return array($memTypeTitle1, $memTypeTitle2);
263 function _testVerifyPriceSet($validateStrings, $sid) {
264 // verify Price Set at Preview page
265 // start at Manage Price Sets listing
266 $this->openCiviPage('admin/price', 'reset=1');
268 // Use the price set id ($sid) to pick the correct row
269 $this->click("css=tr#row_{$sid} a[title='Preview Price Set']");
271 // Look for Register button
272 $this->waitForElementPresent('_qf_Preview_cancel-bottom');
274 // Check for expected price set field strings
275 $this->assertStringsPresent($validateStrings);
278 function _testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
279 //build the membership dates.
280 require_once 'CRM/Core/Config.php';
281 require_once 'CRM/Utils/Array.php';
282 require_once 'CRM/Utils/Date.php';
283 $currentYear = date('Y');
284 $currentMonth = date('m');
285 $previousDay = date('d') - 1;
286 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
287 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
288 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
289 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
290 $configVars = new CRM_Core_Config_Variables();
292 'joinDate', 'startDate', 'endDate') as $date) {
293 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
297 // Go directly to the URL of the screen that you will be testing (Activity Tab).
298 $this->click('css=li#tab_member a');
299 $this->waitForElementPresent('link=Add Membership');
301 $this->click('link=Add Membership');
302 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
304 $this->select('price_set_id', "value={$sid}");
305 $this->waitForElementPresent('pricesetTotal');
307 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
308 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
310 $this->type('source', 'Offline membership Sign Up Test Text');
311 $this->click('_qf_Membership_upload-bottom');
314 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
315 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
316 $this->click('_qf_MembershipRenewal_upload-bottom');
318 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
319 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
320 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
321 $this->click('_qf_MembershipRenewal_upload-bottom');
323 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
324 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span/a[text()='View']");
325 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
327 //View Membership Record
329 'Membership Type' => "{$memTypeTitle1}",
331 'Member Since' => $joinDate,
332 'Start date' => $startDate,
333 'End date' => $endDate,
335 $this->webtestVerifyTabularData($verifyData);
337 $this->click('_qf_MembershipView_cancel-bottom');
338 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
339 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span/a[text()='View']");
340 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
342 //View Membership Record
344 'Membership Type' => "{$memTypeTitle2}",
346 'Member Since' => $joinDate,
347 'Start date' => $startDate,
348 'End date' => $endDate,
350 $this->webtestVerifyTabularData($verifyData);
352 $this->click("_qf_MembershipView_cancel-bottom");
353 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
356 function _testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, $term){
357 //build the membership dates.
358 require_once 'CRM/Core/Config.php';
359 require_once 'CRM/Utils/Array.php';
360 require_once 'CRM/Utils/Date.php';
361 $currentYear = date('Y');
362 $currentMonth = date('m');
363 $previousDay = date('d') - 1;
364 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
365 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
366 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
367 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
368 $configVars = new CRM_Core_Config_Variables();
370 'joinDate', 'startDate', 'endDate') as $date) {
371 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
374 // Go directly to the URL of the screen that you will be testing (Activity Tab).
375 $this->click('css=li#tab_member a');
376 $this->waitForElementPresent('link=Add Membership');
378 $this->click('link=Add Membership');
379 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
381 $this->select('price_set_id', "value={$sid}");
382 $this->waitForElementPresent('pricesetTotal');
384 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
385 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
386 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
387 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
389 $this->type('source', 'Offline membership Sign Up Test Text');
390 $this->click('_qf_Membership_upload-bottom');
392 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
393 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$endDate}']/../td[9]/span/a[text()='View']");
394 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
395 //View Membership Record
397 'Membership Type' => "$memTypeTitle1",
399 'Member Since' => $joinDate,
400 'Start date' => $startDate,
401 'End date' => $endDate,
403 $this->webtestVerifyTabularData($verifyData);
405 //check if the membership amount is correct
406 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));
407 $this->click("_qf_MembershipView_cancel-bottom");
408 $this->waitForPageToLoad($this->getTimeoutMsec());