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