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