3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Member_DefaultMembershipPricesetTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testDefaultPricesetSelection() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
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);
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 $sid = $this->urlArg('sid');
48 $this->assertType('numeric', $sid);
50 $fields = array("National Membership $title" => 'Radio');
51 list($memTypeTitle1, $memTypeTitle2, $memTypeTitle3) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, TRUE, $contributionType);
53 $fields = array("Second Membership $title" => 'CheckBox');
54 list($memTypeTitle1, $memTypeTitle2, $memTypeTitle3) = $this->_testAddPriceFields($fields, $validateStrings, FALSE, $title, $sid, FALSE, $contributionType);
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);
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,
71 $streetAddress = "100 Main Street";
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);
80 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
82 $this->_testDefaultSenarios("National_Membership_{$title}-section", 2);
83 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
84 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
85 $this->click("_qf_Confirm_next-bottom");
86 $this->waitForPageToLoad($this->getTimeoutMsec());
89 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
91 $this->checkOptions("National_Membership_{$title}-section", 2);
93 $this->_testDefaultSenarios("National_Membership_{$title}-section", 4);
94 $this->_testDefaultSenarios("Second_Membership_{$title}-section", 2);
95 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
96 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
97 $this->click("_qf_Confirm_next-bottom");
98 $this->waitForPageToLoad($this->getTimeoutMsec());
101 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
103 $this->checkOptions("Second_Membership_{$title}-section", 2);
106 $this->_testDefaultSenarios("National_Membership_{$title}-section", 3);
107 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
108 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
109 $this->click("_qf_Confirm_next-bottom");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
113 $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}", "_qf_Main_upload-bottom");
114 // checking senario 3
115 $this->assertTrue($this->isTextPresent("You have a current Lifetime Membership which does not need to be renewed."));
117 $this->_testDefaultSenarios("National_Membership_{$title}-section", 1);
118 $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress);
119 $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom");
122 function contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress) {
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");
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");
140 function checkOptions($priceSetSection, $optionNumber) {
141 $this->assertChecked("xpath=//div[@id='priceset']/div[@class='crm-section {$priceSetSection}']/div[2]/div[{$optionNumber}]/span/input");
144 function _testDefaultSenarios($priceSetSection, $optionNumber) {
145 $this->click("xpath=//div[@id='priceset']/div[@class='crm-section {$priceSetSection}']/div[2]/div[{$optionNumber}]/span/input");
148 function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) {
149 $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom');
151 // Enter Priceset fields (Title, Used For ...)
152 $this->type('title', $setTitle);
153 if ($usedFor == 'Event') {
154 $this->check('extends[1]');
156 elseif ($usedFor == 'Contribution') {
157 $this->check('extends[2]');
159 elseif ($usedFor == 'Membership') {
160 $this->click('extends[3]');
161 $this->waitForElementPresent( 'financial_type_id' );
162 $this->select("css=select.crm-form-select", "label={$contributionType}");
165 $this->type('help_pre', $setHelp);
167 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
168 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
169 $this->assertTrue($this->isTextPresent("Your Set '{$setTitle}' has been added. You can add fields to this set now."));
172 function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $defaultPriceSet = FALSE, $contributionType) {
173 if ($defaultPriceSet) {
175 $memTypeTitle1 = 'General';
178 $memTypeTitle2 = 'Student';
181 $memTypeTitle3 = 'Lifetime';
184 elseif (!$defaultPriceSet) {
185 $memTypeParams1 = $this->webtestAddMembershipType();
186 $memTypeTitle1 = $memTypeParams1['membership_type'];
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"));
188 $memTypeId1 = $memTypeId1[1];
190 $memTypeParams2 = $this->webtestAddMembershipType();
191 $memTypeTitle2 = $memTypeParams2['membership_type'];
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"));
193 $memTypeId2 = $memTypeId2[1];
195 $memTypeParams3 = $this->webtestAddMembershipType();
196 $memTypeTitle3 = $memTypeParams3['membership_type'];
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"));
198 $memTypeId3 = $memTypeId3[1];
201 $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}");
203 foreach ($fields as $label => $type) {
204 $validateStrings[] = $label;
206 $this->type('label', $label);
207 $this->select('html_type', "value={$type}");
212 1 => array('label' => "$memTypeTitle1",
213 'membership_type_id' => $memTypeId1,
214 'amount' => '100.00',
217 'label' => "$memTypeTitle2",
218 'membership_type_id' => $memTypeId2,
222 'label' => "$memTypeTitle3",
223 'membership_type_id' => $memTypeId3,
224 'amount' => '1,200.00',
227 $this->addMultipleChoiceOptions($options, $validateStrings);
232 1 => array('label' => "$memTypeTitle1",
233 'membership_type_id' => $memTypeId1,
234 'amount' => '100.00',
237 'label' => "$memTypeTitle2",
238 'membership_type_id' => $memTypeId2,
242 'label' => "$memTypeTitle3",
243 'membership_type_id' => $memTypeId3,
244 'amount' => '1,200.00',
247 $this->addMultipleChoiceOptions($options, $validateStrings);
253 $this->select("financial_type_id", "label={$contributionType}");
254 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
255 $this->assertTrue($this->isTextPresent("Price Field '{$label}' has been saved."));
257 return array($memTypeTitle1, $memTypeTitle2, $memTypeTitle3);