Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / WebTest / Contribute / ConfirmOptionalTest.php
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contribute_ConfirmOptionalTest extends CiviSeleniumTestCase {
30 protected $pageId = 0;
31
32 protected function setUp() {
33 parent::setUp();
34 }
35
36 function testWithConfirm() {
37 $this->_addContributionPage(TRUE);
38 $this->_fillOutContributionPage();
39
40 // confirm contribution
41 $this->assertFalse($this->isTextPresent("Your transaction has been processed successfully"), "Loaded thank you page");
42 $this->waitForElementPresent("_qf_Confirm_next-bottom");
43 $this->assertTrue($this->isTextPresent("Please verify the information below carefully"), "Should load confirmation page");
44 $this->click("_qf_Confirm_next-bottom");
45 $this->waitForPageToLoad($this->getTimeoutMsec());
46
47 // thank you page
48 $this->assertTrue($this->isTextPresent("Your transaction has been processed successfully"), "Should load thank you page");
49 }
50
51 function testWithoutConfirm() {
52 $this->_addContributionPage(FALSE);
53 $this->_fillOutContributionPage();
54
55 // thank you page
56 $this->assertTrue($this->isTextPresent("Your transaction has been processed successfully"), "Didn't load thank you page after main page");
57 $this->assertFalse($this->isTextPresent("Your contribution will not be completed until"), "Loaded confirmation page");
58 }
59
60 protected function _addContributionPage($isConfirmEnabled) {
61 // log in
62 $this->open($this->sboxPath);
63 $this->webtestLogin();
64
65 // create new contribution page
66 $hash = substr(sha1(rand()), 0, 7);
67 $this->pageId = $this->webtestAddContributionPage(
68 $hash,
69 $rand = NULL,
70 $pageTitle = "Test Confirm ($hash)",
71 $processor = array("Dummy ($hash)" => 'Dummy'),
72 $amountSection = TRUE,
73 $payLater = FALSE,
74 $onBehalf = FALSE,
75 $pledges = FALSE,
76 $recurring = FALSE,
77 $membershipTypes = FALSE,
78 $memPriceSetId = NULL,
79 $friend = FALSE,
80 $profilePreId = NULL,
81 $profilePostId = NULL,
82 $premiums = FALSE,
83 $widget = FALSE,
84 $pcp = FALSE,
85 $isAddPaymentProcessor = TRUE,
86 $isPcpApprovalNeeded = FALSE,
87 $isSeparatePayment = FALSE,
88 $honoreeSection = FALSE,
89 $allowOtherAmmount = TRUE,
90 $isConfirmEnabled = $isConfirmEnabled
91 );
92 }
93
94 protected function _fillOutContributionPage() {
95 // load contribution page
96 $this->open($this->sboxPath . "civicrm/contribute/transact?reset=1&id={$this->pageId}");
97 $this->waitForPageToLoad("3000");
98 $this->waitForElementPresent("_qf_Main_upload-bottom");
99
100 // fill out info
101 $this->type("xpath=//div[@class='crm-section other_amount-section']//div[2]/input", "30");
102 $this->webtestAddCreditCardDetails();
103 list($firstName, $middleName, $lastName) = $this->webtestAddBillingDetails();
104 $this->type('email-5', "$lastName@example.com");
105
106 // submit contribution
107 $this->click("_qf_Main_upload-bottom");
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109 }
110 }
111