3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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';
32 * Test APIv3 civicrm_contribute_* functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_Contribution
37 class api_v3_OrderTest
extends CiviUnitTestCase
{
40 * Assume empty database with just civicrm_data.
42 protected $_individualId;
43 protected $_financialTypeId = 1;
44 protected $_apiversion;
50 public function setUp() {
53 $this->_apiversion
= 3;
54 $this->_individualId
= $this->individualCreate();
58 * Clean up after each test.
60 public function tearDown() {
61 $this->quickCleanUpFinancialEntities();
62 $this->quickCleanup(array('civicrm_uf_match'));
68 public function testGetOrder() {
69 $contribution = $this->addOrder(FALSE, 100);
72 'contribution_id' => $contribution['id'],
75 $order = $this->callAPISuccess('Order', 'get', $params);
77 $this->assertEquals(1, $order['count']);
78 $expectedResult = array(
79 $contribution['id'] => array(
80 'total_amount' => 100,
81 'contribution_id' => $contribution['id'],
82 'contribution_status' => 'Completed',
87 'entity_table' => 'civicrm_contribution',
88 'entity_id' => $contribution['id'],
89 'contribution_id' => $contribution['id'],
92 'financial_type_id' => 1,
94 $this->checkPaymentResult($order, $expectedResult, $lineItems);
95 $this->callAPISuccess('Contribution', 'Delete', array(
96 'id' => $contribution['id'],
101 * Test Get Order api for participant contribution.
103 public function testGetOrderParticipant() {
104 $contribution = $this->addOrder(FALSE, 100);
105 list($items, $contribution) = $this->createParticipantWithContribution();
108 'contribution_id' => $contribution['id'],
111 $order = $this->callAPISuccess('Order', 'get', $params);
113 $this->assertEquals(2, count($order['values'][$contribution['id']]['line_items']));
114 $this->callAPISuccess('Contribution', 'Delete', array(
115 'id' => $contribution['id'],
120 * Function to assert db values
122 public function checkPaymentResult($results, $expectedResult, $lineItems = NULL) {
123 foreach ($expectedResult[$results['id']] as $key => $value) {
124 $this->assertEquals($results['values'][$results['id']][$key], $value);
128 foreach ($lineItems as $key => $items) {
129 foreach ($items as $k => $item) {
130 $this->assertEquals($results['values'][$results['id']]['line_items'][$key][$k], $item);
139 * @param bool $isPriceSet
140 * @param float $amount
141 * @param array $extraParams
145 public function addOrder($isPriceSet, $amount = 300, $extraParams = array()) {
147 'contact_id' => $this->_individualId
,
148 'receive_date' => '2010-01-20',
149 'total_amount' => $amount,
150 'financial_type_id' => $this->_financialTypeId
,
151 'contribution_status_id' => 1,
155 $priceFields = $this->createPriceSet();
156 foreach ($priceFields['values'] as $key => $priceField) {
157 $lineItems[1][$key] = array(
158 'price_field_id' => $priceField['price_field_id'],
159 'price_field_value_id' => $priceField['id'],
160 'label' => $priceField['label'],
161 'field_title' => $priceField['label'],
163 'unit_price' => $priceField['amount'],
164 'line_total' => $priceField['amount'],
165 'financial_type_id' => $priceField['financial_type_id'],
168 $p['line_item'] = $lineItems;
170 $p = array_merge($extraParams, $p);
171 return $this->callAPISuccess('Contribution', 'create', $p);