3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 class api_v3_LineItemTest
extends CiviUnitTestCase
{
30 protected $_apiversion = 3;
31 protected $testAmount = 34567;
34 protected $contactIds = array();
35 protected $_entity = 'line_item';
36 protected $contribution_result = null;
37 public $_eNoticeCompliant = TRUE;
38 public $DBResetRequired = TRUE;
39 protected $_financialTypeId = 1;
41 public function setUp() {
43 $this->_individualId
= $this->individualCreate();
44 $contributionParams = array(
45 'contact_id' => $this->_individualId
,
46 'receive_date' => '20120511',
47 'total_amount' => 100.00,
48 'financial_type_id' => $this->_financialTypeId
,
49 'non_deductible_amount' => 10.00,
50 'fee_amount' => 51.00,
51 'net_amount' => 91.00,
53 'contribution_status_id' => 1,
55 $contribution = $this->callAPISuccess('contribution','create', $contributionParams);
56 $this->params
= array(
57 'price_field_value_id' => 1,
58 'price_field_id' => 1,
59 'entity_table' => 'civicrm_contribution',
60 'entity_id' => $contribution['id'],
69 foreach ($this->contactIds
as $id) {
70 $this->callAPISuccess('contact', 'delete', array('id' => $id));
75 'civicrm_contribution',
81 public function testCreateLineItem() {
87 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->params +
array('debug' => 1), __FUNCTION__
, __FILE__
);
88 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
89 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
90 $this->getAndCheck($this->params
, $result['id'], $this->_entity
);
93 public function testGetBasicLineItem() {
95 'entity_table' => 'civicrm_contribution',
97 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
98 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
101 public function testDeleteLineItem() {
102 $getParams = array( 'entity_table' => 'civicrm_contribution',
104 $getResult = $this->callAPISuccess($this->_entity
, 'get', $getParams);
105 $deleteParams = array('id' => $getResult['id']);
106 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
107 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', array());
108 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__
);
111 public function testGetFieldsLineItem() {
112 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create', 'action' => 'create'));
113 $this->assertEquals(1, $result['values']['entity_id']['api.required']);
116 public static function setUpBeforeClass() {
117 // put stuff here that should happen before all tests in this unit
120 public static function tearDownAfterClass(){
121 $tablesToTruncate = array(
123 'civicrm_financial_type',
124 'civicrm_contribution',
127 $unitTest = new CiviUnitTestCase();
128 $unitTest->quickCleanup($tablesToTruncate);