missing space
[civicrm-core.git] / tests / phpunit / CRM / Contribute / Form / ContributionTest.php
CommitLineData
a084385f
EM
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29require_once 'CiviTest/CiviMailUtils.php';
30
31
32/**
33 * Test APIv3 civicrm_contribute_* functions
34 *
35 * @package CiviCRM_APIv3
36 * @subpackage API_Contribution
37 */
38class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
39
40 /**
41 * Assume empty database with just civicrm_data.
42 */
43 protected $_individualId;
44 protected $_contribution;
45 protected $_financialTypeId = 1;
46 protected $_apiversion;
47 protected $_entity = 'Contribution';
48 protected $_params;
49 protected $_ids = array();
50 protected $_pageParams = array();
51
52 /**
53 * Parameters to create payment processor.
54 *
55 * @var array
56 */
57 protected $_processorParams = array();
58
59 /**
60 * ID of created event.
61 *
62 * @var int
63 */
64 protected $_eventID;
65
66 /**
67 * Payment instrument mapping.
68 *
69 * @var array
70 */
71 protected $paymentInstruments = array();
72
73 /**
74 * Setup function.
75 */
76 public function setUp() {
77 parent::setUp();
78
79 $this->_apiversion = 3;
80 $this->_individualId = $this->individualCreate();
81 $paymentProcessor = $this->processorCreate();
82 $this->_params = array(
83 'contact_id' => $this->_individualId,
84 'receive_date' => '20120511',
85 'total_amount' => 100.00,
86 'financial_type_id' => $this->_financialTypeId,
87 'non_deductible_amount' => 10.00,
88 'fee_amount' => 5.00,
89 'net_amount' => 95.00,
90 'source' => 'SSF',
91 'contribution_status_id' => 1,
92 );
93 $this->_processorParams = array(
94 'domain_id' => 1,
95 'name' => 'Dummy',
96 'payment_processor_type_id' => 10,
97 'financial_account_id' => 12,
98 'is_active' => 1,
99 'user_name' => '',
100 'url_site' => 'http://dummy.com',
101 'url_recur' => 'http://dummy.com',
102 'billing_mode' => 1,
103 );
104 $this->_pageParams = array(
105 'title' => 'Test Contribution Page',
106 'financial_type_id' => 1,
107 'currency' => 'USD',
108 'financial_account_id' => 1,
109 'payment_processor' => $paymentProcessor->id,
110 'is_active' => 1,
111 'is_allow_other_amount' => 1,
112 'min_amount' => 10,
113 'max_amount' => 1000,
114 );
115 $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
116 $this->paymentInstruments = $instruments['values'];
117 }
118
119 /**
120 * Clean up after each test.
121 */
122 public function tearDown() {
123 $this->quickCleanUpFinancialEntities();
124 }
125
126 /**
127 * Test the submit function on the contribution page.
128 */
129 public function testSubmit() {
130 $form = new CRM_Contribute_Form_Contribution();
131 $form->testSubmit(array(
132 'total_amount' => 50,
133 'financial_type_id' => 1,
134 'receive_date' => '04/21/2015',
135 'receive_date_time' => '11:27PM',
136 'contact_id' => $this->_individualId,
137 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
138 ));
139 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
140 }
141
142 /**
143 * Test the submit function on the contribution page.
144 */
145 public function testSubmitCreditCard() {
146 $form = new CRM_Contribute_Form_Contribution();
147 $form->testSubmit(array(
148 'total_amount' => 50,
149 'financial_type_id' => 1,
150 'receive_date' => '04/21/2015',
151 'receive_date_time' => '11:27PM',
152 'contact_id' => $this->_individualId,
153 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
154 ));
155 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
156 }
157
158 /**
159 * Test the submit function on the contribution page.
160 */
161 public function testSubmitEmailReceipt() {
162 $form = new CRM_Contribute_Form_Contribution();
163 require_once 'CiviTest/CiviMailUtils.php';
164 $mut = new CiviMailUtils($this, TRUE);
165 $form->testSubmit(array(
166 'total_amount' => 50,
167 'financial_type_id' => 1,
168 'receive_date' => '04/21/2015',
169 'receive_date_time' => '11:27PM',
170 'contact_id' => $this->_individualId,
171 'is_email_receipt' => TRUE,
172 'from_email_address' => 'test@test.com',
173 ));
174 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId), 1);
175 $mut->checkMailLog(array(
176 '<p>Please print this receipt for your records.</p>',
177 )
178 );
179 $mut->stop();
180 }
df729ab1 181
a084385f 182}