| 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_VerifySSLContributionTest |
| 31 | */ |
| 32 | class WebTest_Contribute_VerifySSLContributionTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected $initialized = FALSE; |
| 35 | protected $names = array(); |
| 36 | protected $pageId = 0; |
| 37 | |
| 38 | protected function setUp() { |
| 39 | parent::setUp(); |
| 40 | } |
| 41 | |
| 42 | public function testPaymentProcessorsSSL() { |
| 43 | $this->_initialize(); |
| 44 | $this->_tryPaymentProcessor($this->names['AuthNet']); |
| 45 | |
| 46 | // todo: write code to check other payment processors |
| 47 | /*$this->_tryPaymentProcessor($this->names['Google_Checkout']); |
| 48 | $this->_tryPaymentProcessor($this->names['PayPal']); |
| 49 | $this->_tryPaymentProcessor($this->names['PayPal_Standard']);*/ |
| 50 | } |
| 51 | |
| 52 | public function _initialize() { |
| 53 | if (!$this->initialized) { |
| 54 | // log in |
| 55 | $this->webtestLogin(); |
| 56 | |
| 57 | // build names |
| 58 | $hash = substr(sha1(rand()), 0, 7); |
| 59 | $contributionPageTitle = "Verify SSL ($hash)"; |
| 60 | $this->names['PayPal'] = "PayPal Pro ($hash)"; |
| 61 | $this->names['AuthNet'] = "AuthNet ($hash)"; |
| 62 | //$this->names['Google_Checkout'] = "Google Checkout ($hash)"; |
| 63 | //$this->names['PayPal_Standard'] = "PayPal Standard ($hash)"; |
| 64 | |
| 65 | $processors = array(); |
| 66 | foreach ($this->names as $key => $val) { |
| 67 | $processors[$val] = $key; |
| 68 | } |
| 69 | |
| 70 | // create new contribution page |
| 71 | $this->pageId = $this->webtestAddContributionPage( |
| 72 | $hash, |
| 73 | $rand = NULL, |
| 74 | $pageTitle = $contributionPageTitle, |
| 75 | $processor = $processors, |
| 76 | $amountSection = TRUE, |
| 77 | $payLater = FALSE, |
| 78 | $onBehalf = FALSE, |
| 79 | $pledges = FALSE, |
| 80 | $recurring = FALSE, |
| 81 | $membershipTypes = FALSE, |
| 82 | $memPriceSetId = NULL, |
| 83 | $friend = FALSE, |
| 84 | $profilePreId = NULL, |
| 85 | $profilePostId = NULL, |
| 86 | $premiums = FALSE, |
| 87 | $widget = FALSE, |
| 88 | $pcp = FALSE, |
| 89 | $isAddPaymentProcessor = TRUE, |
| 90 | $isPcpApprovalNeeded = FALSE, |
| 91 | $isSeparatePayment = FALSE, |
| 92 | $honoreeSection = FALSE, |
| 93 | $allowOtherAmmount = TRUE |
| 94 | ); |
| 95 | |
| 96 | // enable verify ssl |
| 97 | $this->openCiviPage("admin/setting/url", "reset=1"); |
| 98 | $this->click("id=CIVICRM_QFID_1_verifySSL"); |
| 99 | $this->click("id=_qf_Url_next-bottom"); |
| 100 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 101 | |
| 102 | $this->initialized = TRUE; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @param string $name |
| 108 | */ |
| 109 | public function _tryPaymentProcessor($name) { |
| 110 | // load contribution page |
| 111 | $this->openCiviPage("contribute/transact", "reset=1&action=preview&id={$this->pageId}", "_qf_Main_upload-bottom"); |
| 112 | |
| 113 | // fill out info |
| 114 | $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", "30"); |
| 115 | $this->type('email-5', "smith@example.com"); |
| 116 | |
| 117 | // choose the payment processor |
| 118 | $this->click("xpath=//label[text() = '{$name}']/preceding-sibling::input[1]"); |
| 119 | |
| 120 | // do we need to add credit card details? |
| 121 | if (strpos($name, "AuthNet") !== FALSE || strpos($name, "PayPal Pro") !== FALSE) { |
| 122 | $this->webtestAddCreditCardDetails(); |
| 123 | list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails(); |
| 124 | } |
| 125 | |
| 126 | // submit contribution |
| 127 | $this->clickLink("_qf_Main_upload-bottom", "_qf_Confirm_next-bottom"); |
| 128 | |
| 129 | // confirm contribution |
| 130 | $this->click("_qf_Confirm_next-bottom"); |
| 131 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 132 | $this->assertFalse($this->isTextPresent("Payment Processor Error message"), "Payment processor returned error message"); |
| 133 | } |
| 134 | } |