3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class api_v3_LineItemTest
16 class api_v3_LineItemTest
extends CiviUnitTestCase
{
17 protected $_apiversion = 3;
18 protected $testAmount = 34567;
21 protected $contactIds = [];
22 protected $_entity = 'line_item';
23 protected $contribution_result = NULL;
25 public $DBResetRequired = TRUE;
26 protected $_financialTypeId = 1;
28 public function setUp() {
30 $this->useTransaction(TRUE);
31 $this->_individualId
= $this->individualCreate();
32 $contributionParams = [
33 'contact_id' => $this->_individualId
,
34 'receive_date' => '20120511',
35 'total_amount' => 100.00,
36 'financial_type_id' => $this->_financialTypeId
,
37 'non_deductible_amount' => 10.00,
38 'fee_amount' => 51.00,
39 'net_amount' => 91.00,
41 'contribution_status_id' => 1,
43 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
45 'price_field_value_id' => 1,
46 'price_field_id' => 1,
47 'entity_table' => 'civicrm_contribution',
48 'entity_id' => $contribution['id'],
55 public function testCreateLineItem() {
56 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->params +
['debug' => 1], __FUNCTION__
, __FILE__
);
57 $this->assertEquals(1, $result['count']);
58 $this->assertNotNull($result['values'][$result['id']]['id']);
59 $this->getAndCheck($this->params
, $result['id'], $this->_entity
);
62 public function testGetBasicLineItem() {
64 'entity_table' => 'civicrm_contribution',
66 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
67 $this->assertEquals(1, $getResult['count']);
70 public function testDeleteLineItem() {
72 'entity_table' => 'civicrm_contribution',
74 $getResult = $this->callAPISuccess($this->_entity
, 'get', $getParams);
75 $deleteParams = ['id' => $getResult['id']];
76 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
77 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
78 $this->assertEquals(0, $checkDeleted['count']);
81 public function testGetFieldsLineItem() {
82 $result = $this->callAPISuccess($this->_entity
, 'getfields', ['action' => 'create']);
83 $this->assertEquals(1, $result['values']['entity_id']['api.required']);