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 // Log in using webtestLogin() method
37 $this->webtestLogin();
39 $title = substr(sha1(rand()), 0, 7);
40 $setTitle = "Membership Fees - $title";
41 $usedFor = 'Membership';
42 $contributionType = 'Donation';
43 $setHelp = 'Select your membership options.';
44 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
46 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
47 // which is where we are after adding Price Set.
48 $elements = $this->parseURL();
49 $sid = $elements['queryString']['sid'];
50 $this->assertType('numeric', $sid);
53 "National Membership $title" => 'Radio',
54 "Local Chapter $title" => 'CheckBox',
57 list($memTypeTitle1, $memTypeTitle2) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, $contributionType);
59 // load the Price Set Preview and check for expected values
60 $this->_testVerifyPriceSet($validateStrings, $sid);
62 // Sign up for membership
63 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
64 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
65 $email = "{$firstName}.{$lastName}@example.com";
66 $contactParams = array(
67 'first_name' => $firstName,
68 'last_name' => $lastName,
72 // Add a contact from the quick add block
73 $this->webtestAddContact($firstName, $lastName, $email);
75 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2);
77 // Renew this membership
78 $this->_testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = TRUE);
81 function testAddPriceSetWithMultipleTerms() {
82 // Log in using webtestLogin() method
83 $this->webtestLogin();
85 $title = substr(sha1(rand()), 0, 7);
86 $setTitle = "Membership Fees - $title";
87 $usedFor = 'Membership';
88 $contributionType = 'Member Dues';
89 $setHelp = 'Select your membership options.';
90 $memTypeParams1 = $this->webtestAddMembershipType();
91 $memTypeTitle1 = $memTypeParams1['membership_type'];
92 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
93 $memTypeId1 = $memTypeId1[1];
94 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
96 // Get the price set id ($sid) by retrieving and parsing the URL of the New Price Field form
97 // which is where we are after adding Price Set.
98 $elements = $this->parseURL();
99 $sid = $elements['queryString']['sid'];
100 $this->assertType('numeric', $sid);
102 $fields = array("National Membership $title", "Radio");
103 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
105 $validateStrings[] = $fields[0];
106 $this->type('label', $fields[0]);
107 $this->select('html_type', "value={$fields[1]}");
109 1 => array('label' => $memTypeTitle1."_1",
110 'membership_type_id' => $memTypeId1,
112 'membership_num_terms' => 1,
115 'label' => $memTypeTitle1."_2",
116 'membership_type_id' => $memTypeId1,
118 'membership_num_terms' => 2,
121 'label' => $memTypeTitle1."_3",
122 'membership_type_id' => $memTypeId1,
124 'membership_num_terms' => 3,
128 foreach($options as $index => $values){
129 $this->select("membership_type_id_{$index}", "value={$values['membership_type_id']}");
130 // Because it tends to cause problems, all uses of sleep() must be justified in comments
131 // Sleep should never be used for wait for anything to load from the server
132 // Justification for this instance: FIXME
134 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[4]/input",$values['membership_num_terms']);
135 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[5]/input",$values['label']);
136 $this->type("xpath=//table[@id='optionField']/tbody/tr[$i]/td[6]/input",$values['amount']);
138 $this->click('link=another choice');
142 $this->waitForElementPresent( 'financial_type_id' );
143 $this->select("financial_type_id", "label={$contributionType}");
144 $this->waitForElementPresent('_qf_Field_next-bottom');
145 $this->click('_qf_Field_next-bottom');
146 $this->waitForPageToLoad($this->getTimeoutMsec());
147 $this->assertElementContainsText('crm-notification-container', "Price Field '{$fields[0]}' has been saved.");
149 // load the Price Set Preview and check for expected values
150 $this->_testVerifyPriceSet($validateStrings, $sid);
152 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
153 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
154 $email = "{$firstName}.{$lastName}@example.com";
156 $contactParams = array(
157 'first_name' => $firstName,
158 'last_name' => $lastName,
161 $this->webtestAddContact($firstName, $lastName, $email);
162 //membership with number of terms as 3
163 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 3);
164 //membership with number of terms as 2
165 $this->_testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, 2);
170 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
171 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
173 // Enter Priceset fields (Title, Used For ...)
174 $this->type('title', $setTitle);
175 if ($usedFor == 'Event') {
176 $this->check('extends_1');
178 elseif ($usedFor == 'Contribution') {
179 $this->check('extends_2');
181 elseif ($usedFor == 'Membership') {
182 $this->click('extends_3');
183 $this->waitForElementPresent('financial_type_id');
184 $this->select("css=select.form-select", "label={$contributionType}");
186 $this->type('help_pre', $setHelp);
187 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
189 $this->click('_qf_Set_next-bottom');
190 $this->waitForElementPresent('_qf_Field_next-bottom');
191 $this->assertElementContainsText('crm-notification-container', "Your Set '{$setTitle}' has been added. You can add fields to this set now.");
194 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $contributionType) {
195 $memTypeParams1 = $this->webtestAddMembershipType();
196 $memTypeTitle1 = $memTypeParams1['membership_type'];
198 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
199 $memTypeId1 = $memTypeId1[1];
201 $memTypeParams2 = $this->webtestAddMembershipType();
202 $memTypeTitle2 = $memTypeParams2['membership_type'];
203 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
204 $memTypeId2 = $memTypeId2[1];
206 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
208 foreach ($fields as $label => $type) {
209 $validateStrings[] = $label;
211 $this->type('label', $label);
212 $this->select('html_type', "value={$type}");
217 1 => array('label' => "$memTypeTitle1",
218 'membership_type_id' => $memTypeId1,
222 'label' => "$memTypeTitle2",
223 'membership_type_id' => $memTypeId2,
227 $this->addMultipleChoiceOptions($options, $validateStrings);
232 1 => array('label' => "$memTypeTitle1",
233 'membership_type_id' => $memTypeId1,
237 'label' => "$memTypeTitle2",
238 'membership_type_id' => $memTypeId2,
242 $this->addMultipleChoiceOptions($options, $validateStrings);
248 $this->select("financial_type_id", "label={$contributionType}");
249 $this->click('_qf_Field_next_new-bottom');
250 $this->waitForPageToLoad($this->getTimeoutMsec());
251 $this->assertElementContainsText('crm-notification-container', "Price Field '{$label}' has been saved.");
253 return array($memTypeTitle1, $memTypeTitle2);
256 function _testVerifyPriceSet($validateStrings, $sid) {
257 // verify Price Set at Preview page
258 // start at Manage Price Sets listing
259 $this->openCiviPage('admin/price', 'reset=1');
261 // Use the price set id ($sid) to pick the correct row
262 $this->click("css=tr#row_{$sid} a[title='Preview Price Set']");
264 // Look for Register button
265 $this->waitForElementPresent('_qf_Preview_cancel-bottom');
267 // Check for expected price set field strings
268 $this->assertStringsPresent($validateStrings);
271 function _testSignUpOrRenewMembership($sid, $contactParams, $memTypeTitle1, $memTypeTitle2, $renew = FALSE) {
272 //build the membership dates.
273 require_once 'CRM/Core/Config.php';
274 require_once 'CRM/Utils/Array.php';
275 require_once 'CRM/Utils/Date.php';
276 $currentYear = date('Y');
277 $currentMonth = date('m');
278 $previousDay = date('d') - 1;
279 $endYear = ($renew) ?
$currentYear +
2 : $currentYear +
1;
280 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
281 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
282 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
283 $configVars = new CRM_Core_Config_Variables();
285 'joinDate', 'startDate', 'endDate') as $date) {
286 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
291 $this->click('css=li#tab_member a');
292 $this->waitForElementPresent('link=Add Membership');
294 $this->click('link=Add Membership');
295 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
297 $this->select('price_set_id', "value={$sid}");
298 $this->waitForElementPresent('pricesetTotal');
300 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div/span/input");
301 $this->click("xpath=//div[@id='priceset']/div[3]/div[2]/div[2]/span/input");
303 $this->type('source', 'Offline membership Sign Up Test Text');
304 $this->click('_qf_Membership_upload-bottom');
307 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
308 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
309 $this->click('_qf_MembershipRenewal_upload-bottom');
311 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
312 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span[2][text()='more']/ul/li/a[text()='Renew']");
313 $this->waitForElementPresent('_qf_MembershipRenewal_cancel-bottom');
314 $this->click('_qf_MembershipRenewal_upload-bottom');
316 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
317 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[9]/span/a[text()='View']");
318 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
320 //View Membership Record
322 'Membership Type' => "{$memTypeTitle1}",
324 'Member Since' => $joinDate,
325 'Start date' => $startDate,
326 'End date' => $endDate,
328 $this->webtestVerifyTabularData($verifyData);
330 $this->click('_qf_MembershipView_cancel-bottom');
331 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
332 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[9]/span/a[text()='View']");
333 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
335 //View Membership Record
337 'Membership Type' => "{$memTypeTitle2}",
339 'Member Since' => $joinDate,
340 'Start date' => $startDate,
341 'End date' => $endDate,
343 $this->webtestVerifyTabularData($verifyData);
345 $this->click("_qf_MembershipView_cancel-bottom");
346 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
349 function _testMultilpeTermsMembershipRegistration($sid, $contactParams, $memTypeTitle1, $term){
350 //build the membership dates.
351 require_once 'CRM/Core/Config.php';
352 require_once 'CRM/Utils/Array.php';
353 require_once 'CRM/Utils/Date.php';
354 $currentYear = date('Y');
355 $currentMonth = date('m');
356 $previousDay = date('d') - 1;
357 $endYear = ($term == 3) ?
$currentYear +
3 : (($term == 2) ?
$currentYear +
2 : $currentYear +
1);
358 $joinDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
359 $startDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, date('d'), $currentYear));
360 $endDate = date('Y-m-d', mktime(0, 0, 0, $currentMonth, $previousDay, $endYear));
361 $configVars = new CRM_Core_Config_Variables();
363 'joinDate', 'startDate', 'endDate') as $date) {
364 $
$date = CRM_Utils_Date
::customFormat($
$date, $configVars->dateformatFull
);
367 $this->click('css=li#tab_member a');
368 $this->waitForElementPresent('link=Add Membership');
370 $this->click('link=Add Membership');
371 $this->waitForElementPresent('_qf_Membership_cancel-bottom');
373 $this->select('price_set_id', "value={$sid}");
374 $this->waitForElementPresent('pricesetTotal');
376 $i = ($term == 3) ?
3 : (($term == 2) ?
2 : 1 );
377 $this->waitForElementPresent("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
378 $this->click("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/input");
379 $amount = $this->getText("xpath=//div[@id='priceset']/div[2]/div[2]/div[$i]/span/label/span[@class='crm-price-amount-amount']");
381 $this->type('source', 'Offline membership Sign Up Test Text');
382 $this->click('_qf_Membership_upload-bottom');
384 $this->waitForElementPresent("xpath=//div[@id='memberships']//table/tbody/tr");
385 $this->click("xpath=//div[@id='memberships']//table/tbody//tr/td[text()='{$endDate}']/../td[9]/span/a[text()='View']");
386 $this->waitForElementPresent("_qf_MembershipView_cancel-bottom");
387 //View Membership Record
389 'Membership Type' => "$memTypeTitle1",
391 'Member Since' => $joinDate,
392 'Start date' => $startDate,
393 'End date' => $endDate,
395 $this->webtestVerifyTabularData($verifyData);
397 //check if the membership amount is correct
398 $this->assertTrue($this->isElementPresent("xpath=//form[@id='MembershipView']/div[2]/div/table[2]/tbody/tr/td/span[text()='{$amount}']"));
399 $this->click("_qf_MembershipView_cancel-bottom");
400 $this->waitForPageToLoad($this->getTimeoutMsec());