| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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_Contribute_OnlineContributionTest |
| 31 | */ |
| 32 | class WebTest_Contribute_OnlineContributionTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testOnlineContributionAdd() { |
| 39 | $this->webtestLogin(); |
| 40 | |
| 41 | // Use default payment processor |
| 42 | $processorName = 'Test Processor'; |
| 43 | $processorType = 'Dummy'; |
| 44 | $pageTitle = substr(sha1(rand()), 0, 7); |
| 45 | $rand = 2 * rand(10, 50); |
| 46 | $hash = substr(sha1(rand()), 0, 7); |
| 47 | $amountSection = TRUE; |
| 48 | $payLater = FALSE; |
| 49 | $onBehalf = FALSE; |
| 50 | $pledges = FALSE; |
| 51 | $recurring = FALSE; |
| 52 | $memberships = FALSE; |
| 53 | $friend = TRUE; |
| 54 | $profilePreId = 1; |
| 55 | $profilePostId = NULL; |
| 56 | $premiums = FALSE; |
| 57 | $widget = FALSE; |
| 58 | $pcp = FALSE; |
| 59 | $memPriceSetId = NULL; |
| 60 | |
| 61 | // create a new online contribution page |
| 62 | // create contribution page with randomized title and default params |
| 63 | $pageId = $this->webtestAddContributionPage($hash, |
| 64 | $rand, |
| 65 | $pageTitle, |
| 66 | array($processorName => $processorType), |
| 67 | $amountSection, |
| 68 | $payLater, |
| 69 | $onBehalf, |
| 70 | $pledges, |
| 71 | $recurring, |
| 72 | $memberships, |
| 73 | $memPriceSetId, |
| 74 | $friend, |
| 75 | $profilePreId, |
| 76 | $profilePostId, |
| 77 | $premiums, |
| 78 | $widget, |
| 79 | $pcp |
| 80 | ); |
| 81 | |
| 82 | //logout |
| 83 | $this->webtestLogout(); |
| 84 | |
| 85 | //Open Live Contribution Page |
| 86 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); |
| 87 | |
| 88 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); |
| 89 | $lastName = 'An' . substr(sha1(rand()), 0, 7); |
| 90 | $honorFirstName = 'In' . substr(sha1(rand()), 0, 4); |
| 91 | $honorLastName = 'Hon' . substr(sha1(rand()), 0, 7); |
| 92 | $honorEmail = $honorFirstName . "@example.com"; |
| 93 | $honorSortName = $honorLastName . ', ' . $honorFirstName; |
| 94 | $honorDisplayName = 'Ms. ' . $honorFirstName . ' ' . $honorLastName; |
| 95 | |
| 96 | $this->type("email-5", $firstName . "@example.com"); |
| 97 | |
| 98 | $this->type("first_name", $firstName); |
| 99 | $this->type("last_name", $lastName); |
| 100 | |
| 101 | $this->click("xpath=//div[@class='crm-section other_amount-section']//div[2]/input"); |
| 102 | $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", 100); |
| 103 | |
| 104 | $streetAddress = "100 Main Street"; |
| 105 | $this->type("street_address-1", $streetAddress); |
| 106 | $this->type("city-1", "San Francisco"); |
| 107 | $this->type("postal_code-1", "94117"); |
| 108 | $this->select("country-1", "value=1228"); |
| 109 | $this->select("state_province-1", "value=1001"); |
| 110 | |
| 111 | // Honoree Info |
| 112 | $this->click("xpath=id('Main')/div[2]/fieldset/div[2]/div/label[text()='In Honor of']"); |
| 113 | |
| 114 | $this->select("honor[prefix_id]", "label=Ms."); |
| 115 | $this->type("honor[first_name]", $honorFirstName); |
| 116 | $this->type("honor[last_name]", $honorLastName); |
| 117 | $this->type("honor[email-1]", $honorEmail); |
| 118 | |
| 119 | //Credit Card Info |
| 120 | $this->select("credit_card_type", "value=Visa"); |
| 121 | $this->type("credit_card_number", "4111111111111111"); |
| 122 | $this->type("cvv2", "000"); |
| 123 | $this->select("credit_card_exp_date[M]", "value=1"); |
| 124 | $this->select("credit_card_exp_date[Y]", "value=2020"); |
| 125 | |
| 126 | //Billing Info |
| 127 | $this->type("billing_first_name", $firstName . "billing"); |
| 128 | $this->type("billing_last_name", $lastName . "billing"); |
| 129 | $this->type("billing_street_address-5", "15 Main St."); |
| 130 | $this->type(" billing_city-5", "San Jose"); |
| 131 | $this->select("billing_country_id-5", "value=1228"); |
| 132 | $this->select("billing_state_province_id-5", "value=1004"); |
| 133 | $this->type("billing_postal_code-5", "94129"); |
| 134 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 135 | |
| 136 | $this->click("_qf_Confirm_next-bottom"); |
| 137 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 138 | |
| 139 | //login to check contribution |
| 140 | |
| 141 | // Log in using webtestLogin() method |
| 142 | $this->webtestLogin(); |
| 143 | |
| 144 | //Find Contribution |
| 145 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
| 146 | |
| 147 | $this->type("sort_name", "$lastName $firstName"); |
| 148 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']"); |
| 149 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
| 150 | |
| 151 | //View Contribution Record and verify data |
| 152 | $expected = array( |
| 153 | 'From' => "{$firstName} {$lastName}", |
| 154 | 'Financial Type' => 'Donation', |
| 155 | 'Total Amount' => '100.00', |
| 156 | 'Contribution Status' => 'Completed', |
| 157 | ); |
| 158 | $this->webtestVerifyTabularData($expected); |
| 159 | |
| 160 | //View Soft Credit record of type 'Honor of' |
| 161 | $this->waitForTextPresent($honorDisplayName); |
| 162 | $this->waitForTextPresent('100.00 (In Honor of)'); |
| 163 | |
| 164 | // Check for Honoree contact created |
| 165 | $this->click("css=input#sort_name_navigation"); |
| 166 | $this->type("css=input#sort_name_navigation", $honorSortName); |
| 167 | $this->typeKeys("css=input#sort_name_navigation", $honorSortName); |
| 168 | |
| 169 | // wait for result list |
| 170 | $this->waitForElementPresent("css=ul.ui-autocomplete li"); |
| 171 | |
| 172 | // visit contact summary page |
| 173 | $this->click("css=ul.ui-autocomplete li"); |
| 174 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 175 | |
| 176 | // Is contact present? |
| 177 | $this->assertTrue($this->isTextPresent("$honorDisplayName"), "Honoree contact not found."); |
| 178 | |
| 179 | } |
| 180 | |
| 181 | public function testOnlineContributionWithZeroAmount() { |
| 182 | $this->webtestLogin(); |
| 183 | |
| 184 | // Use default payment processor |
| 185 | $processorName = 'Test Processor'; |
| 186 | $processorType = 'Dummy'; |
| 187 | $pageTitle = substr(sha1(rand()), 0, 7); |
| 188 | $rand = 2 * rand(10, 50); |
| 189 | $hash = substr(sha1(rand()), 0, 7); |
| 190 | $amountSection = TRUE; |
| 191 | $payLater = FALSE; |
| 192 | $onBehalf = FALSE; |
| 193 | $pledges = FALSE; |
| 194 | $recurring = FALSE; |
| 195 | $memberships = FALSE; |
| 196 | $friend = FALSE; |
| 197 | $profilePreId = NULL; |
| 198 | $profilePostId = NULL; |
| 199 | $premiums = FALSE; |
| 200 | $widget = FALSE; |
| 201 | $pcp = FALSE; |
| 202 | $memPriceSetId = NULL; |
| 203 | |
| 204 | // create a new online contribution page |
| 205 | // create contribution page with randomized title and default params |
| 206 | $pageId = $this->webtestAddContributionPage($hash, |
| 207 | $rand, |
| 208 | $pageTitle, |
| 209 | array($processorName => $processorType), |
| 210 | $amountSection, |
| 211 | $payLater, |
| 212 | $onBehalf, |
| 213 | $pledges, |
| 214 | $recurring, |
| 215 | $memberships, |
| 216 | $memPriceSetId, |
| 217 | $friend, |
| 218 | $profilePreId, |
| 219 | $profilePostId, |
| 220 | $premiums, |
| 221 | $widget, |
| 222 | $pcp |
| 223 | ); |
| 224 | |
| 225 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom'); |
| 226 | $this->type('label_1', "Label $hash"); |
| 227 | $this->type('value_1', 0); |
| 228 | $this->clickLink('_qf_Amount_upload_done-top'); |
| 229 | |
| 230 | //Contribution using Contribution Options |
| 231 | $this->_doContributionAndVerifyData($pageId); |
| 232 | |
| 233 | //add priceset |
| 234 | $this->openCiviPage("admin/price", "reset=1&action=add", '_qf_Set_next-bottom'); |
| 235 | $this->type('title', "Test Priceset $rand"); |
| 236 | $this->check('extends_2'); |
| 237 | $this->select("financial_type_id", "label=Donation"); |
| 238 | $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom', FALSE); |
| 239 | $sid = $this->urlArg('sid'); |
| 240 | //add field |
| 241 | $this->type('label', "Testfield"); |
| 242 | $this->select('html_type', "value=Radio"); |
| 243 | $this->type('option_label_1', 'test Label'); |
| 244 | $this->type('option_amount_1', 0.00); |
| 245 | $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom', FALSE); |
| 246 | $this->openCiviPage("admin/contribute/amount", "reset=1&action=update&id=$pageId", '_qf_Amount_cancel-bottom'); |
| 247 | $this->select('price_set_id', "value=$sid"); |
| 248 | $this->clickLink('_qf_Amount_upload_done-bottom', FALSE); |
| 249 | |
| 250 | //Contribution using priceset |
| 251 | $this->_doContributionAndVerifyData($pageId, TRUE); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * @param int $pageId |
| 256 | * @param bool $priceSet |
| 257 | */ |
| 258 | public function _doContributionAndVerifyData($pageId, $priceSet = FALSE) { |
| 259 | //logout |
| 260 | $this->webtestLogout(); |
| 261 | $amountLabel = 'Total Amount'; |
| 262 | $amountValue = '0.00'; |
| 263 | //Open Live Contribution Page |
| 264 | $this->openCiviPage("contribute/transact", "reset=1&id=$pageId", "_qf_Main_upload-bottom"); |
| 265 | |
| 266 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); |
| 267 | $lastName = 'An' . substr(sha1(rand()), 0, 7); |
| 268 | |
| 269 | $this->type("email-5", $firstName . "@example.com"); |
| 270 | |
| 271 | if ($priceSet) { |
| 272 | $this->click("xpath=//div[@id='priceset']/div/div[2]/div/span/input"); |
| 273 | $amountLabel = 'Contribution Amount'; |
| 274 | $amountValue = 'Contribution Total: $ 0.00'; |
| 275 | } |
| 276 | |
| 277 | //Credit Card Info |
| 278 | $this->select("credit_card_type", "value=Visa"); |
| 279 | $this->type("credit_card_number", "4111111111111111"); |
| 280 | $this->type("cvv2", "000"); |
| 281 | $this->select("credit_card_exp_date[M]", "value=1"); |
| 282 | $this->select("credit_card_exp_date[Y]", "value=2020"); |
| 283 | |
| 284 | //Billing Info |
| 285 | $this->type("billing_first_name", $firstName); |
| 286 | $this->type("billing_last_name", $lastName); |
| 287 | $this->type("billing_street_address-5", "15 Main St."); |
| 288 | $this->type(" billing_city-5", "San Jose"); |
| 289 | $this->select("billing_country_id-5", "value=1228"); |
| 290 | $this->select("billing_state_province_id-5", "value=1004"); |
| 291 | $this->type("billing_postal_code-5", "94129"); |
| 292 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 293 | |
| 294 | $this->clickLink("_qf_Confirm_next-bottom", NULL); |
| 295 | |
| 296 | //login to check contribution |
| 297 | |
| 298 | // Log in using webtestLogin() method |
| 299 | $this->webtestLogin(); |
| 300 | |
| 301 | //Find Contribution |
| 302 | $this->openCiviPage("contribute/search", "reset=1", "contribution_date_low"); |
| 303 | |
| 304 | $this->type("sort_name", "$lastName $firstName"); |
| 305 | $this->clickLink("_qf_Search_refresh", "xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", FALSE); |
| 306 | $this->clickLink("xpath=//div[@id='contributionSearch']//table//tbody/tr[1]/td[11]/span/a[text()='View']", "_qf_ContributionView_cancel-bottom", FALSE); |
| 307 | |
| 308 | //View Contribution Record and verify data |
| 309 | $expected = array( |
| 310 | 'From' => "{$firstName} {$lastName}", |
| 311 | 'Financial Type' => 'Donation', |
| 312 | $amountLabel => $amountValue, |
| 313 | 'Contribution Status' => 'Completed', |
| 314 | ); |
| 315 | $this->webtestVerifyTabularData($expected); |
| 316 | } |
| 317 | } |