Merge pull request #17294 from agh1/sr-rel-perms
[civicrm-core.git] / tests / phpunit / api / v3 / LineItemTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class api_v3_LineItemTest
14 * @group headless
15 */
16 class api_v3_LineItemTest extends CiviUnitTestCase {
17 protected $_apiversion = 3;
18 protected $testAmount = 34567;
19 protected $params;
20 protected $id = 0;
21 protected $contactIds = [];
22 protected $_entity = 'line_item';
23 protected $contribution_result = NULL;
24
25 public $DBResetRequired = TRUE;
26 protected $_financialTypeId = 1;
27
28 public function setUp() {
29 parent::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,
40 'source' => 'SSF',
41 'contribution_status_id' => 1,
42 ];
43 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
44 $this->params = [
45 'price_field_value_id' => 1,
46 'price_field_id' => 1,
47 'entity_table' => 'civicrm_contribution',
48 'entity_id' => $contribution['id'],
49 'qty' => 1,
50 'unit_price' => 50,
51 'line_total' => 50,
52 ];
53 }
54
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);
60 }
61
62 public function testGetBasicLineItem() {
63 $getParams = [
64 'entity_table' => 'civicrm_contribution',
65 ];
66 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
67 $this->assertEquals(1, $getResult['count']);
68 }
69
70 public function testDeleteLineItem() {
71 $getParams = [
72 'entity_table' => 'civicrm_contribution',
73 ];
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']);
79 }
80
81 public function testGetFieldsLineItem() {
82 $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
83 $this->assertEquals(1, $result['values']['entity_id']['api.required']);
84 }
85
86 }