whitespace cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Member / DefaultMembershipPricesetTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25*/
26
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Member_DefaultMembershipPricesetTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testDefaultPricesetSelection() {
6a488035
TO
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
37
38 $title = substr(sha1(rand()), 0, 7);
39 $setTitle = "Membership Fees - $title";
40 $usedFor = 'Membership';
41 $contributionType = 'Member Dues';
42 $setHelp = 'Select your membership options.';
43 $this->_testAddSet($setTitle, $usedFor, $contributionType, $setHelp);
44
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 $elements = $this->parseURL();
48 $sid = $elements['queryString']['sid'];
49 $this->assertType('numeric', $sid);
50
51 $fields = array("National Membership $title" => 'Radio');
52 list($memTypeTitle1, $memTypeTitle2, $memTypeTitle3) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, TRUE, $contributionType);
53
54 $fields = array("Second Membership $title" => 'CheckBox');
55 list($memTypeTitle1, $memTypeTitle2, $memTypeTitle3) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, FALSE, $contributionType);
56
57 $hash = substr(sha1(rand()), 0, 7);
58 $rand = 2 * rand(2, 50);
59 $pageTitle = 'Contribution page for membership ' . $hash;
60 $processorName = 'Dummy ' . $hash;
61 $memPriceSetId = $sid;
62 $membershipContributionPageId = $this->webtestAddContributionPage($hash, $rand, $pageTitle, array($processorName => 'Dummy'), TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, $memPriceSetId, FALSE, NULL, NULL, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE);
63
64 $firstName = 'John_' . substr(sha1(rand()), 0, 7);
65 $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7);
66 $email = "{$firstName}.{$lastName}@example.com";
67 $contactParams = array(
68 'first_name' => $firstName,
69 'last_name' => $lastName,
70 'email-5' => $email,
71 );
72 $streetAddress = "100 Main Street";
73
74 //adding contact for membership sign up
75 $this->webtestAddContact($firstName, $lastName, $email);
76 $urlElements = $this->parseURL();
77 $cid = $urlElements['queryString']['cid'];
78 $this->assertType('numeric', $cid);
79
80 //senario 1
42daf119 81 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
6a488035
TO
82
83 $this->_testDefaultSenarios("National_Membership_{$title}-section", 2);
84 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
225a8648 85 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
86 $this->click("_qf_Confirm_next-bottom");
87 $this->waitForPageToLoad($this->getTimeoutMsec());
88
89 //senario 2
42daf119 90 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
6a488035
TO
91 // checking
92 $this->checkOptions("National_Membership_{$title}-section", 2);
93 // senario 1
94 $this->_testDefaultSenarios("National_Membership_{$title}-section", 4);
95 $this->_testDefaultSenarios("Second_Membership_{$title}-section", 2);
96 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
225a8648 97 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
98 $this->click("_qf_Confirm_next-bottom");
99 $this->waitForPageToLoad($this->getTimeoutMsec());
100
101 //senario 3
42daf119 102 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
6a488035
TO
103 // checking
104 $this->checkOptions("Second_Membership_{$title}-section", 2);
105 // senario 2
106
107 $this->_testDefaultSenarios("National_Membership_{$title}-section", 3);
108 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
225a8648 109 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
6a488035
TO
110 $this->click("_qf_Confirm_next-bottom");
111 $this->waitForPageToLoad($this->getTimeoutMsec());
112
113 //senario 4
42daf119 114 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
6a488035
TO
115 // checking senario 3
116 $this->assertTrue($this->isTextPresent("You have a current Lifetime Membership which does not need to be renewed."));
117
118 $this->_testDefaultSenarios("National_Membership_{$title}-section", 1);
119 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
225a8648 120 $this->clickLink("_qf_Main_upload-bottom", "_qf_Main_upload-bottom");
6a488035
TO
121 $this->assertTrue($this->isTextPresent("You already have a lifetime membership and cannot select a membership with a shorter term."));
122 }
123
124 function contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress) {
125 //Credit Card Info
126 $this->select("credit_card_type", "value=Visa");
127 $this->type("credit_card_number", "4111111111111111");
128 $this->type("cvv2", "000");
129 $this->select("credit_card_exp_date[M]", "value=1");
130 $this->select("credit_card_exp_date[Y]", "value=2020");
131
132 //Billing Info
133 $this->type("billing_first_name", $contactParams['first_name'] . "billing");
134 $this->type("billing_last_name", $contactParams['last_name'] . "billing");
135 $this->type("billing_street_address-5", "15 Main St.");
136 $this->type(" billing_city-5", "San Jose");
137 $this->select("billing_country_id-5", "value=1228");
138 $this->select("billing_state_province_id-5", "value=1004");
139 $this->type("billing_postal_code-5", "94129");
140 }
141
142 function checkOptions($priceSetSection, $optionNumber) {
143 $this->assertChecked("xpath=//div[@id='priceset']/div[@class='crm-section {$priceSetSection}']/div[2]/div[{$optionNumber}]/span/input");
144 }
145
146 function _testDefaultSenarios($priceSetSection, $optionNumber) {
147 $this->click("xpath=//div[@id='priceset']/div[@class='crm-section {$priceSetSection}']/div[2]/div[{$optionNumber}]/span/input");
148 }
149
150 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
42daf119 151 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
6a488035
TO
152
153 // Enter Priceset fields (Title, Used For ...)
154 $this->type('title', $setTitle);
155 if ($usedFor == 'Event') {
156 $this->check('extends[1]');
157 }
158 elseif ($usedFor == 'Contribution') {
159 $this->check('extends[2]');
160 }
161 elseif ($usedFor == 'Membership') {
162 $this->click('extends[3]');
42daf119 163 $this->waitForElementPresent( 'financial_type_id' );
6a488035
TO
164 $this->select("css=select.form-select", "label={$contributionType}");
165 }
166
167 $this->type('help_pre', $setHelp);
168
169 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
225a8648 170 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
6a488035
TO
171 $this->assertTrue($this->isTextPresent("Your Set '{$setTitle}' has been added. You can add fields to this set now."));
172 }
173
174 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $defaultPriceSet = FALSE, $contributionType) {
175 if ($defaultPriceSet) {
176
177 $memTypeTitle1 = 'General';
178 $memTypeId1 = 1;
179
180 $memTypeTitle2 = 'Student';
181 $memTypeId2 = 2;
182
183 $memTypeTitle3 = 'Lifetime';
184 $memTypeId3 = 3;
185 }
186 elseif (!$defaultPriceSet) {
187 $memTypeParams1 = $this->webtestAddMembershipType();
188 $memTypeTitle1 = $memTypeParams1['membership_type'];
189 $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle1}']/../td[12]/span/a[3]@href"));
190 $memTypeId1 = $memTypeId1[1];
191
192 $memTypeParams2 = $this->webtestAddMembershipType();
193 $memTypeTitle2 = $memTypeParams2['membership_type'];
194 $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle2}']/../td[12]/span/a[3]@href"));
195 $memTypeId2 = $memTypeId2[1];
196
197 $memTypeParams3 = $this->webtestAddMembershipType();
198 $memTypeTitle3 = $memTypeParams3['membership_type'];
199 $memTypeId3 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/div[2]/table/tbody//tr/td[text()='{$memTypeTitle3}']/../td[12]/span/a[3]@href"));
200 $memTypeId3 = $memTypeId3[1];
201 }
202
071a6d2e 203 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
6a488035
TO
204
205 foreach ($fields as $label => $type) {
206 $validateStrings[] = $label;
207
208 $this->type('label', $label);
209 $this->select('html_type', "value={$type}");
210
211 switch ($type) {
212 case 'Radio':
213 $options = array(
214 1 => array('label' => "$memTypeTitle1",
215 'membership_type_id' => $memTypeId1,
216 'amount' => '100.00',
217 ),
218 2 => array(
219 'label' => "$memTypeTitle2",
220 'membership_type_id' => $memTypeId2,
221 'amount' => '50.00',
222 ),
223 3 => array(
224 'label' => "$memTypeTitle3",
225 'membership_type_id' => $memTypeId3,
226 'amount' => '1,200.00',
227 ),
228 );
229 $this->addMultipleChoiceOptions($options, $validateStrings);
230 break;
231
232 case 'CheckBox':
233 $options = array(
234 1 => array('label' => "$memTypeTitle1",
235 'membership_type_id' => $memTypeId1,
236 'amount' => '100.00',
237 ),
238 2 => array(
239 'label' => "$memTypeTitle2",
240 'membership_type_id' => $memTypeId2,
241 'amount' => '50.00',
242 ),
243 3 => array(
244 'label' => "$memTypeTitle3",
245 'membership_type_id' => $memTypeId3,
246 'amount' => '1,200.00',
247 ),
248 );
249 $this->addMultipleChoiceOptions($options, $validateStrings);
250 break;
251
252 default:
253 break;
254 }
255 $this->select("financial_type_id", "label={$contributionType}");
225a8648 256 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
6a488035
TO
257 $this->assertTrue($this->isTextPresent("Price Field '{$label}' has been saved."));
258 }
259 return array($memTypeTitle1, $memTypeTitle2, $memTypeTitle3);
260 }
261}
262