3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
29 require_once 'CiviTest/CiviMailUtils.php';
33 * Test APIv3 civicrm_contribute_* functions
35 * @package CiviCRM_APIv3
36 * @subpackage API_Contribution
38 class CRM_Contribute_Form_ContributionTest
extends CiviUnitTestCase
{
41 * Assume empty database with just civicrm_data.
43 protected $_individualId;
44 protected $_contribution;
45 protected $_financialTypeId = 1;
46 protected $_apiversion;
47 protected $_entity = 'Contribution';
49 protected $_ids = array();
50 protected $_pageParams = array();
53 * Parameters to create payment processor.
57 protected $_processorParams = array();
60 * ID of created event.
67 * Payment instrument mapping.
71 protected $paymentInstruments = array();
78 protected $products = array();
83 public function setUp() {
86 $this->_apiversion
= 3;
87 $this->_individualId
= $this->individualCreate();
88 $paymentProcessor = $this->processorCreate();
89 $this->_params
= array(
90 'contact_id' => $this->_individualId
,
91 'receive_date' => '20120511',
92 'total_amount' => 100.00,
93 'financial_type_id' => $this->_financialTypeId
,
94 'non_deductible_amount' => 10.00,
96 'net_amount' => 95.00,
98 'contribution_status_id' => 1,
100 $this->_processorParams
= array(
103 'payment_processor_type_id' => 10,
104 'financial_account_id' => 12,
107 'url_site' => 'http://dummy.com',
108 'url_recur' => 'http://dummy.com',
111 $this->_pageParams
= array(
112 'title' => 'Test Contribution Page',
113 'financial_type_id' => 1,
115 'financial_account_id' => 1,
116 'payment_processor' => $paymentProcessor->id
,
118 'is_allow_other_amount' => 1,
120 'max_amount' => 1000,
122 $instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
123 $this->paymentInstruments
= $instruments['values'];
124 $product1 = $this->callAPISuccess('product', 'create', array(
126 'options' => 'brainy smurf, clumsy smurf, papa smurf',
129 $this->products
[] = $product1['values'][$product1['id']];
133 * Clean up after each test.
135 public function tearDown() {
136 $this->quickCleanUpFinancialEntities();
140 * Test the submit function on the contribution page.
142 public function testSubmit() {
143 $form = new CRM_Contribute_Form_Contribution();
144 $form->testSubmit(array(
145 'total_amount' => 50,
146 'financial_type_id' => 1,
147 'receive_date' => '04/21/2015',
148 'receive_date_time' => '11:27PM',
149 'contact_id' => $this->_individualId
,
150 'payment_instrument_id' => array_search('Check', $this->paymentInstruments
),
151 'contribution_status_id' => 1,
153 CRM_Core_Action
::ADD
);
154 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId
), 1);
158 * Test the submit function on the contribution page.
160 public function testSubmitCreditCard() {
161 $form = new CRM_Contribute_Form_Contribution();
162 $form->testSubmit(array(
163 'total_amount' => 50,
164 'financial_type_id' => 1,
165 'receive_date' => '04/21/2015',
166 'receive_date_time' => '11:27PM',
167 'contact_id' => $this->_individualId
,
168 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments
),
169 'contribution_status_id' => 1,
170 ), CRM_Core_Action
::ADD
);
171 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId
), 1);
175 * Test the submit function on the contribution page.
177 public function testSubmitEmailReceipt() {
178 $form = new CRM_Contribute_Form_Contribution();
179 require_once 'CiviTest/CiviMailUtils.php';
180 $mut = new CiviMailUtils($this, TRUE);
181 $form->testSubmit(array(
182 'total_amount' => 50,
183 'financial_type_id' => 1,
184 'receive_date' => '04/21/2015',
185 'receive_date_time' => '11:27PM',
186 'contact_id' => $this->_individualId
,
187 'is_email_receipt' => TRUE,
188 'from_email_address' => 'test@test.com',
189 'contribution_status_id' => 1,
190 ), CRM_Core_Action
::ADD
);
191 $this->callAPISuccessGetCount('Contribution', array('contact_id' => $this->_individualId
), 1);
192 $mut->checkMailLog(array(
193 '<p>Please print this receipt for your records.</p>',
200 * Test that a contribution is assigned against a pledge.
202 public function testUpdatePledge() {
203 $pledge = $this->callAPISuccess('pledge', 'create', array(
204 'contact_id' => $this->_individualId
,
205 'pledge_create_date' => date('Ymd'),
206 'start_date' => date('Ymd'),
208 'pledge_status_id' => '2',
209 'pledge_financial_type_id' => '1',
210 'pledge_original_installment_amount' => 20,
211 'frequency_interval' => 5,
212 'frequency_unit' => 'year',
213 'frequency_day' => 15,
217 $pledgePaymentID = $this->callAPISuccess('pledge_payment', 'getvalue', array(
218 'pledge_id' => $pledge['id'],
219 'options' => array('limit' => 1),
222 $form = new CRM_Contribute_Form_Contribution();
223 $form->testSubmit(array(
224 'total_amount' => 50,
225 'financial_type_id' => 1,
226 'receive_date' => '04/21/2015',
227 'receive_date_time' => '11:27PM',
228 'contact_id' => $this->_individualId
,
229 'payment_instrument_id' => array_search('Check', $this->paymentInstruments
),
230 'pledge_payment_id' => $pledgePaymentID,
231 'contribution_status_id' => 1,
232 ), CRM_Core_Action
::ADD
);
233 $pledgePayment = $this->callAPISuccess('pledge_payment', 'getsingle', array('id' => $pledgePaymentID));
234 $this->assertNotEmpty($pledgePayment['contribution_id']);
235 $this->assertEquals($pledgePayment['actual_amount'], 50);
236 $this->assertEquals(1, $pledgePayment['status_id']);
240 * Test functions involving premiums.
242 public function testPremiumUpdate() {
243 $form = new CRM_Contribute_Form_Contribution();
244 $form->testSubmit(array(
245 'total_amount' => 50,
246 'financial_type_id' => 1,
247 'receive_date' => '04/21/2015',
248 'receive_date_time' => '11:27PM',
249 'contact_id' => $this->_individualId
,
250 'payment_instrument_id' => array_search('Check', $this->paymentInstruments
),
251 'contribution_status_id' => 1,
252 'product_name' => array($this->products
[0]['id'], 1),
253 'fulfilled_date' => '',
254 ), CRM_Core_Action
::ADD
);
255 $contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', array());
256 $this->assertEquals('clumsy smurf', $contributionProduct['product_option']);