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