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_OfflineMembershipAddPricesetTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testAddPriceSet() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
38 $title = substr(sha1(rand()), 0, 7);
39 $setTitle = "Membership Fees - $title";
40 $usedFor = 'Membership';
41 $contributionType = 'Donation';
42 $setHelp = 'Select your membership options.';
43 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
45 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
46 // which is where we are after adding Price Set.
47 $sid = $this->urlArg('sid');
48 $this->assertType('numeric', $sid);
51 "National Membership $title" => 'Radio',
52 "Local Chapter $title" => 'CheckBox',
55 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
57 // load the Price Set Preview and check for expected values
58 $this->_testVerifyPriceSet($validateStrings, $sid);
60 // Sign up for membership
61 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
62 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
63 $email = "{$firstName}.{$lastName}@example.com";
64 $contactParams = array(
65 'first_name' => $firstName,
66 'last_name' => $lastName,
70 // Add a contact from the quick add block
71 $this->webtestAddContact($firstName, $lastName, $email);
73 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2);
75 // Renew this membership
76 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
79 function testAddPriceSetWithMultipleTerms() {
80 // Log in using webtestLogin() method
81 $this->webtestLogin();
83 $title = substr(sha1(rand()), 0, 7);
84 $setTitle = "Membership Fees - $title";
85 $usedFor = 'Membership';
86 $contributionType = 'Member Dues';
87 $setHelp = 'Select your membership options.';
88 $memTypeParams1 = $this->webtestAddMembershipType();
89 $memTypeTitle1 = $memTypeParams1['membership_type'];
90 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
91 $memTypeId1 = $memTypeId1[1];
92 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
94 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
95 // which is where we are after adding Price Set.
96 $sid = $this->urlArg('sid');
97 $this->assertType('numeric', $sid);
99 $fields = array("National Membership $title", "Radio");
100 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
102 $validateStrings[] = $fields[0];
103 $this->type('label', $fields[0]);
104 $this->select('html_type', "value={$fields[1]}");
106 1 => array('label' => $memTypeTitle1."_1",
107 'membership_type_id' => $memTypeId1,
109 'membership_num_terms' => 1,
112 'label' => $memTypeTitle1."_2",
113 'membership_type_id' => $memTypeId1,
115 'membership_num_terms' => 2,
118 'label' => $memTypeTitle1."_3",
119 'membership_type_id' => $memTypeId1,
121 'membership_num_terms' => 3,
125 foreach($options as $index => $values){
126 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
127 // Because it tends to cause problems, all uses of sleep() must be justified in comments
128 // Sleep should never be used for wait for anything to load from the server
129 // Justification for this instance: FIXME
131 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']);
132 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']);
133 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']);
135 $this->click('link=another choice');
139 $this->waitForElementPresent( 'financial_type_id' );
140 $this->select("financial_type_id", "label={$contributionType}");
141 $this->waitForElementPresent('_qf_Field_next-bottom');
142 $this->click('_qf_Field_next-bottom');
143 $this->waitForPageToLoad($this->getTimeoutMsec());
144 $this->waitForText('crm-notification-container', "Price Field '{$fields[0]}' has been saved.");
146 // load the Price Set Preview and check for expected values
147 $this->_testVerifyPriceSet($validateStrings, $sid);
149 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
150 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
151 $email = "{$firstName}.{$lastName}@example.com";
153 $contactParams = array(
154 'first_name' => $firstName,
155 'last_name' => $lastName,
158 $this->webtestAddContact($firstName, $lastName, $email);
159 //membership with number of terms as 3
160 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 3);
161 //membership with number of terms as 2
162 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 2);
166 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
167 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
169 // Enter Priceset fields (Title, Used For ...)
170 $this->type('title', $setTitle);
171 if ($usedFor == 'Event') {
172 $this->check('extends_1');
174 elseif ($usedFor == 'Contribution') {
175 $this->check('extends_2');
177 elseif ($usedFor == 'Membership') {
178 $this->click('extends_3');
179 $this->waitForElementPresent('financial_type_id');
180 $this->select("css=select.form-select", "label={$contributionType}");
182 $this->type('help_pre', $setHelp);
183 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
185 $this->click('_qf_Set_next-bottom');
186 $this->waitForElementPresent('_qf_Field_next-bottom');
187 $this->waitForText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
190 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
191 $memTypeParams1 = $this->webtestAddMembershipType();
192 $memTypeTitle1 = $memTypeParams1['membership_type'];
194 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
195 $memTypeId1 = $memTypeId1[1];
197 $memTypeParams2 = $this->webtestAddMembershipType();
198 $memTypeTitle2 = $memTypeParams2['membership_type'];
199 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
200 $memTypeId2 = $memTypeId2[1];
202 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
204 foreach ($fields as $label => $type) {
205 $validateStrings[] = $label;
207 $this->type('label', $label);
208 $this->select('html_type', "value={$type}");
213 1 => array('label' => "$memTypeTitle1",
214 'membership_type_id' => $memTypeId1,
218 'label' => "$memTypeTitle2",
219 'membership_type_id' => $memTypeId2,
223 $this->addMultipleChoiceOptions($options, $validateStrings);
228 1 => array('label' => "$memTypeTitle1",
229 'membership_type_id' => $memTypeId1,
233 'label' => "$memTypeTitle2",
234 'membership_type_id' => $memTypeId2,
238 $this->addMultipleChoiceOptions($options, $validateStrings);
244 $this->select("financial_type_id", "label={$contributionType}");
245 $this->click('_qf_Field_next_new-bottom');
246 $this->waitForPageToLoad($this->getTimeoutMsec());
247 $this->waitForText('crm-notification-container', "Price Field '{$label}' has been saved.");
249 return array($memTypeTitle1, $memTypeTitle2);
252 function _testVerifyPriceSet($validateStrings, $sid) {
253 // verify Price Set at Preview page
254 // start at Manage Price Sets listing
255 $this->openCiviPage('admin/price', 'reset=1');
257 // Use the price set id ($sid) to pick the correct row
258 $this->click("css=tr#row_{$sid} a[title='Preview Price Set']");
260 // Look for Register button
261 $this->waitForElementPresent('_qf_Preview_cancel-bottom');
263 // Check for expected price set field strings
264 $this->assertStringsPresent($validateStrings);
267 function _testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
268 //build the membership dates.
269 require_once 'CRM/Core/Config.php';
270 require_once 'CRM/Utils/Array.php';
271 require_once 'CRM/Utils/Date.php';
272 $currentYear = date('Y');
273 $currentMonth = date('m');
274 $previousDay = date('d') - 1;
275 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
276 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
277 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
278 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
279 $configVars = new CRM_Core_Config_Variables();
281 'joinDate', 'startDate', 'endDate') as $date) {
282 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
287 $this->click('css=li#tab_member a');
288 $this->waitForElementPresent('link=Add Membership');
290 $this->click('link=Add Membership');
291 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
293 $this->select('price_set_id', "value={$sid}");
294 $this->waitForElementPresent('pricesetTotal');
296 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
297 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
299 $this->type('source', 'Offline membership Sign Up Test Text');
300 $this->click('_qf_Membership_upload-bottom');
303 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
304 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
305 $this->click('_qf_MembershipRenewal_upload-bottom');
307 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
308 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
309 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
310 $this->click('_qf_MembershipRenewal_upload-bottom');
312 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
313 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span/a[text()='View']");
314 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
316 //View Membership Record
318 'Membership Type' => "{$memTypeTitle1}",
320 'Member Since' => $joinDate,
321 'Start date' => $startDate,
322 'End date' => $endDate,
324 $this->webtestVerifyTabularData($verifyData);
326 $this->click('_qf_MembershipView_cancel-bottom');
327 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
328 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span/a[text()='View']");
329 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
331 //View Membership Record
333 'Membership Type' => "{$memTypeTitle2}",
335 'Member Since' => $joinDate,
336 'Start date' => $startDate,
337 'End date' => $endDate,
339 $this->webtestVerifyTabularData($verifyData);
341 $this->click("_qf_MembershipView_cancel-bottom");
342 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
345 function _testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, $term){
346 //build the membership dates.
347 require_once 'CRM/Core/Config.php';
348 require_once 'CRM/Utils/Array.php';
349 require_once 'CRM/Utils/Date.php';
350 $currentYear = date('Y');
351 $currentMonth = date('m');
352 $previousDay = date('d') - 1;
353 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
354 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
355 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
356 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
357 $configVars = new CRM_Core_Config_Variables();
359 'joinDate', 'startDate', 'endDate') as $date) {
360 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
363 $this->click('css=li#tab_member a');
364 $this->waitForElementPresent('link=Add Membership');
366 $this->click('link=Add Membership');
367 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
369 $this->select('price_set_id', "value={$sid}");
370 $this->waitForElementPresent('pricesetTotal');
372 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
373 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
374 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
375 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
377 $this->type('source', 'Offline membership Sign Up Test Text');
378 $this->waitForElementPresent('recordContribution');
379 $this->click('_qf_Membership_upload-bottom');
381 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
382 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$endDate}']/../td[9]/span/a[text()='View']");
383 $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 $this->webtestVerifyTabularData($verifyData);
394 //check if the membership amount is correct
395 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));
396 $this->click("_qf_MembershipView_cancel-bottom");
397 $this->waitForPageToLoad($this->getTimeoutMsec());