Commit | Line | Data |
---|---|---|
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Member_DefaultMembershipPricesetTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Member_DefaultMembershipPricesetTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testDefaultPricesetSelection() { | |
6a488035 TO |
39 | // Log in using webtestLogin() method |
40 | $this->webtestLogin(); | |
41 | ||
42 | $title = substr(sha1(rand()), 0, 7); | |
43 | $setTitle = "Membership Fees - $title"; | |
44 | $usedFor = 'Membership'; | |
45 | $contributionType = 'Member Dues'; | |
46 | $setHelp = 'Select your membership options.'; | |
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 | ||
67 | $firstName = 'John_' . substr(sha1(rand()), 0, 7); | |
68 | $lastName = 'Anderson_' . substr(sha1(rand()), 0, 7); | |
69 | $email = "{$firstName}.{$lastName}@example.com"; | |
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 | |
42daf119 | 84 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_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 | |
42daf119 | 93 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_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 | |
42daf119 | 105 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_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 | |
42daf119 | 117 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_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); | |
0e6f669d | 123 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
6a488035 TO |
124 | } |
125 | ||
4cbe18b8 EM |
126 | /** |
127 | * @param $firstName | |
128 | * @param $lastName | |
129 | * @param $email | |
130 | * @param $contactParams | |
131 | * @param $streetAddress | |
132 | */ | |
6a488035 TO |
133 | function contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress) { |
134 | //Credit Card Info | |
135 | $this->select("credit_card_type", "value=Visa"); | |
136 | $this->type("credit_card_number", "4111111111111111"); | |
137 | $this->type("cvv2", "000"); | |
138 | $this->select("credit_card_exp_date[M]", "value=1"); | |
139 | $this->select("credit_card_exp_date[Y]", "value=2020"); | |
140 | ||
141 | //Billing Info | |
142 | $this->type("billing_first_name", $contactParams['first_name'] . "billing"); | |
143 | $this->type("billing_last_name", $contactParams['last_name'] . "billing"); | |
144 | $this->type("billing_street_address-5", "15 Main St."); | |
145 | $this->type(" billing_city-5", "San Jose"); | |
146 | $this->select("billing_country_id-5", "value=1228"); | |
147 | $this->select("billing_state_province_id-5", "value=1004"); | |
148 | $this->type("billing_postal_code-5", "94129"); | |
149 | } | |
150 | ||
4cbe18b8 EM |
151 | /** |
152 | * @param $priceSetSection | |
153 | * @param $optionNumber | |
154 | */ | |
6a488035 TO |
155 | function checkOptions($priceSetSection, $optionNumber) { |
156 | $this->assertChecked("xpath=//div[@id='priceset']/div[@class='crm-section {$priceSetSection}']/div[2]/div[{$optionNumber}]/span/input"); | |
157 | } | |
158 | ||
4cbe18b8 EM |
159 | /** |
160 | * @param $priceSetSection | |
161 | * @param $optionNumber | |
162 | */ | |
6a488035 TO |
163 | function _testDefaultSenarios($priceSetSection, $optionNumber) { |
164 | $this->click("xpath=//div[@id='priceset']/div[@class='crm-section {$priceSetSection}']/div[2]/div[{$optionNumber}]/span/input"); | |
165 | } | |
166 | ||
4cbe18b8 EM |
167 | /** |
168 | * @param $setTitle | |
169 | * @param $usedFor | |
170 | * @param null $contributionType | |
171 | * @param $setHelp | |
172 | */ | |
6a488035 | 173 | function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) { |
42daf119 | 174 | $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); |
6a488035 TO |
175 | |
176 | // Enter Priceset fields (Title, Used For ...) | |
177 | $this->type('title', $setTitle); | |
178 | if ($usedFor == 'Event') { | |
179 | $this->check('extends[1]'); | |
180 | } | |
181 | elseif ($usedFor == 'Contribution') { | |
182 | $this->check('extends[2]'); | |
183 | } | |
184 | elseif ($usedFor == 'Membership') { | |
185 | $this->click('extends[3]'); | |
42daf119 | 186 | $this->waitForElementPresent( 'financial_type_id' ); |
d17bd806 | 187 | $this->select("css=select.crm-form-select", "label={$contributionType}"); |
6a488035 TO |
188 | } |
189 | ||
190 | $this->type('help_pre', $setHelp); | |
191 | ||
192 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); | |
225a8648 | 193 | $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
194 | $this->assertTrue($this->isTextPresent("Your Set '{$setTitle}' has been added. You can add fields to this set now.")); |
195 | } | |
196 | ||
4cbe18b8 EM |
197 | /** |
198 | * @param $fields | |
199 | * @param $validateString | |
200 | * @param bool $dateSpecificFields | |
201 | * @param $title | |
202 | * @param $sid | |
203 | * @param bool $defaultPriceSet | |
204 | * @param $contributionType | |
205 | * | |
206 | * @return array | |
207 | */ | |
6a488035 TO |
208 | function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $defaultPriceSet = FALSE, $contributionType) { |
209 | if ($defaultPriceSet) { | |
210 | ||
211 | $memTypeTitle1 = 'General'; | |
212 | $memTypeId1 = 1; | |
213 | ||
214 | $memTypeTitle2 = 'Student'; | |
215 | $memTypeId2 = 2; | |
216 | ||
217 | $memTypeTitle3 = 'Lifetime'; | |
218 | $memTypeId3 = 3; | |
219 | } | |
220 | elseif (!$defaultPriceSet) { | |
221 | $memTypeParams1 = $this->webtestAddMembershipType(); | |
222 | $memTypeTitle1 = $memTypeParams1['membership_type']; | |
d17bd806 | 223 | $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 |
224 | $memTypeId1 = $memTypeId1[1]; |
225 | ||
226 | $memTypeParams2 = $this->webtestAddMembershipType(); | |
227 | $memTypeTitle2 = $memTypeParams2['membership_type']; | |
d17bd806 | 228 | $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 |
229 | $memTypeId2 = $memTypeId2[1]; |
230 | ||
231 | $memTypeParams3 = $this->webtestAddMembershipType(); | |
232 | $memTypeTitle3 = $memTypeParams3['membership_type']; | |
d17bd806 | 233 | $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 |
234 | $memTypeId3 = $memTypeId3[1]; |
235 | } | |
236 | ||
071a6d2e | 237 | $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}"); |
6a488035 TO |
238 | |
239 | foreach ($fields as $label => $type) { | |
240 | $validateStrings[] = $label; | |
241 | ||
242 | $this->type('label', $label); | |
243 | $this->select('html_type', "value={$type}"); | |
244 | ||
245 | switch ($type) { | |
246 | case 'Radio': | |
247 | $options = array( | |
248 | 1 => array('label' => "$memTypeTitle1", | |
249 | 'membership_type_id' => $memTypeId1, | |
250 | 'amount' => '100.00', | |
251 | ), | |
252 | 2 => array( | |
253 | 'label' => "$memTypeTitle2", | |
254 | 'membership_type_id' => $memTypeId2, | |
255 | 'amount' => '50.00', | |
256 | ), | |
257 | 3 => array( | |
258 | 'label' => "$memTypeTitle3", | |
259 | 'membership_type_id' => $memTypeId3, | |
260 | 'amount' => '1,200.00', | |
261 | ), | |
262 | ); | |
263 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
264 | break; | |
265 | ||
266 | case 'CheckBox': | |
267 | $options = array( | |
268 | 1 => array('label' => "$memTypeTitle1", | |
269 | 'membership_type_id' => $memTypeId1, | |
270 | 'amount' => '100.00', | |
271 | ), | |
272 | 2 => array( | |
273 | 'label' => "$memTypeTitle2", | |
274 | 'membership_type_id' => $memTypeId2, | |
275 | 'amount' => '50.00', | |
276 | ), | |
277 | 3 => array( | |
278 | 'label' => "$memTypeTitle3", | |
279 | 'membership_type_id' => $memTypeId3, | |
280 | 'amount' => '1,200.00', | |
281 | ), | |
282 | ); | |
283 | $this->addMultipleChoiceOptions($options, $validateStrings); | |
284 | break; | |
285 | ||
286 | default: | |
287 | break; | |
288 | } | |
289 | $this->select("financial_type_id", "label={$contributionType}"); | |
225a8648 | 290 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); |
6a488035 TO |
291 | $this->assertTrue($this->isTextPresent("Price Field '{$label}' has been saved.")); |
292 | } | |
293 | return array($memTypeTitle1, $memTypeTitle2, $memTypeTitle3); | |
294 | } | |
295 | } | |
296 |