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