| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
| 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 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
| 28 | |
| 29 | /** |
| 30 | * Class WebTest_Member_DefaultMembershipPricesetTest |
| 31 | */ |
| 32 | class WebTest_Member_DefaultMembershipPricesetTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testDefaultPricesetSelection() { |
| 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. |
| 51 | $sid = $this->urlArg('sid'); |
| 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 |
| 84 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}&action=preview", "_qf_Main_upload-bottom"); |
| 85 | |
| 86 | $this->_testDefaultSenarios("national_membership_{$title}-section", 2); |
| 87 | $this->contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress); |
| 88 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 89 | $this->click("_qf_Confirm_next-bottom"); |
| 90 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 91 | |
| 92 | //senario 2 |
| 93 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}&action=preview", "_qf_Main_upload-bottom"); |
| 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); |
| 100 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 101 | $this->click("_qf_Confirm_next-bottom"); |
| 102 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 103 | |
| 104 | //senario 3 |
| 105 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}&action=preview", "_qf_Main_upload-bottom"); |
| 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); |
| 112 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 113 | $this->click("_qf_Confirm_next-bottom"); |
| 114 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 115 | |
| 116 | //senario 4 |
| 117 | $this->openCiviPage("contribute/transact", "reset=1&id={$membershipContributionPageId}&cid={$cid}&action=preview", "_qf_Main_upload-bottom"); |
| 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); |
| 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.")); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @param string $firstName |
| 129 | * @param string $lastName |
| 130 | * @param $email |
| 131 | * @param array $contactParams |
| 132 | * @param $streetAddress |
| 133 | */ |
| 134 | public function contactInfoFill($firstName, $lastName, $email, $contactParams, $streetAddress) { |
| 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 | |
| 152 | /** |
| 153 | * @param $priceSetSection |
| 154 | * @param $optionNumber |
| 155 | */ |
| 156 | public function checkOptions($priceSetSection, $optionNumber) { |
| 157 | $this->assertChecked("xpath=//div[@id='priceset']/div[@class='crm-section {$priceSetSection}']/div[2]/div[{$optionNumber}]/span/input"); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @param $priceSetSection |
| 162 | * @param $optionNumber |
| 163 | */ |
| 164 | public 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 | /** |
| 169 | * @param $setTitle |
| 170 | * @param $usedFor |
| 171 | * @param null $contributionType |
| 172 | * @param $setHelp |
| 173 | */ |
| 174 | public function _testAddSet($setTitle, $usedFor, $contributionType = NULL, $setHelp) { |
| 175 | $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); |
| 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]'); |
| 187 | $this->waitForElementPresent('financial_type_id'); |
| 188 | $this->select("css=select.crm-form-select", "label={$contributionType}"); |
| 189 | } |
| 190 | |
| 191 | $this->type('help_pre', $setHelp); |
| 192 | |
| 193 | $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.'); |
| 194 | $this->clickLink('_qf_Set_next-bottom'); |
| 195 | $this->assertTrue($this->isTextPresent("Your Set '{$setTitle}' has been added. You can add fields to this set now.")); |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * @param $fields |
| 200 | * @param $validateString |
| 201 | * @param bool $dateSpecificFields |
| 202 | * @param $title |
| 203 | * @param int $sid |
| 204 | * @param bool $defaultPriceSet |
| 205 | * @param $contributionType |
| 206 | * |
| 207 | * @return array |
| 208 | */ |
| 209 | public function _testAddPriceFields(&$fields, &$validateString, $dateSpecificFields = FALSE, $title, $sid, $defaultPriceSet = FALSE, $contributionType) { |
| 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(); |
| 223 | $memTypeTitle1 = $memTypeParams1['membership_type']; |
| 224 | $memTypeId1 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td/div[text()='{$memTypeTitle1}']/../../td[12]/span/a[3]@href")); |
| 225 | $memTypeId1 = $memTypeId1[1]; |
| 226 | |
| 227 | $memTypeParams2 = $this->webtestAddMembershipType(); |
| 228 | $memTypeTitle2 = $memTypeParams2['membership_type']; |
| 229 | $memTypeId2 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td/div[text()='{$memTypeTitle2}']/../../td[12]/span/a[3]@href")); |
| 230 | $memTypeId2 = $memTypeId2[1]; |
| 231 | |
| 232 | $memTypeParams3 = $this->webtestAddMembershipType(); |
| 233 | $memTypeTitle3 = $memTypeParams3['membership_type']; |
| 234 | $memTypeId3 = explode('&id=', $this->getAttribute("xpath=//div[@id='membership_type']/table/tbody//tr/td/div[text()='{$memTypeTitle3}']/../../td[12]/span/a[3]@href")); |
| 235 | $memTypeId3 = $memTypeId3[1]; |
| 236 | } |
| 237 | |
| 238 | $this->openCiviPage("admin/price/field", "reset=1&action=add&sid={$sid}"); |
| 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( |
| 249 | 1 => array( |
| 250 | 'label' => "$memTypeTitle1", |
| 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( |
| 270 | 1 => array( |
| 271 | 'label' => "$memTypeTitle1", |
| 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}"); |
| 293 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom'); |
| 294 | $this->assertTrue($this->isTextPresent("Price Field '{$label}' has been saved.")); |
| 295 | } |
| 296 | return array($memTypeTitle1, $memTypeTitle2, $memTypeTitle3); |
| 297 | } |
| 298 | |
| 299 | } |