-
-
Notifications
You must be signed in to change notification settings - Fork 827
/
Copy pathLineItemTest.php
116 lines (107 loc) · 3.51 KB
/
LineItemTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Class api_v3_LineItemTest
* @group headless
*/
class api_v3_LineItemTest extends CiviUnitTestCase {
use CRM_Financial_Form_SalesTaxTrait;
protected $params;
/**
* Should financials be checked after the test but before tear down.
*
* @var bool
*/
protected $isValidateFinancialsOnPostAssert = TRUE;
/**
* Prepare for test.
*
* @throws \CRM_Core_Exception
*/
public function setUp(): void {
parent::setUp();
$this->useTransaction();
$contributionParams = [
'contact_id' => $this->individualCreate(),
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => 'Donation',
'non_deductible_amount' => 10.00,
'fee_amount' => 51.00,
'net_amount' => 91.00,
'source' => 'SSF',
'contribution_status_id' => 1,
];
$contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
$this->params = [
'price_field_value_id' => 1,
'price_field_id' => 1,
'entity_table' => 'civicrm_contribution',
'entity_id' => $contribution['id'],
'qty' => 1,
'unit_price' => 50,
'line_total' => 50,
];
}
/**
* Test tax is calculated correctly on the line item.
*
* @param int $version
*
* @dataProvider versionThreeAndFour
* @throws \CRM_Core_Exception
*/
public function testCreateLineItemWithTax($version): void {
$this->_apiversion = $version;
$this->enableSalesTaxOnFinancialType('Donation');
$this->params['financial_type_id'] = 'Donation';
$result = $this->callAPISuccess('LineItem', 'create', $this->params);
$lineItem = $this->callAPISuccessGetSingle('LineItem', ['id' => $result['id']]);
$this->assertEquals(5, $lineItem['tax_amount']);
$this->assertEquals(50, $lineItem['line_total']);
}
/**
* Enable tax for the given financial type.
*
* @param string $type
*
* @throws \CRM_Core_Exception
* @todo move to a trait, share.
*
* @dataProvider versionThreeAndFour
*
*/
public function enableSalesTaxOnFinancialType($type): void {
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType(CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'financial_type_id', $type));
}
/**
* Test zero is valid for amount fields.
*
* https://github.com/civicrm/civicrm-core/pull/20342
*
* @param int $version
*
* @dataProvider versionThreeAndFour
*/
public function testCreateLineItemZero(int $version): void {
$this->_apiversion = $version;
$this->callAPISuccess('LineItem', 'create', array_merge($this->params, ['unit_price' => 0, 'line_total' => 0]));
$this->callAPISuccess('LineItem', 'create', array_merge($this->params, ['unit_price' => 0.0, 'line_total' => 0.0]));
}
/**
* Test getfields function.
*/
public function testGetFieldsLineItem(): void {
$result = $this->callAPISuccess('LineItem', 'getfields', ['action' => 'create']);
$this->assertEquals(1, $result['values']['entity_id']['api.required']);
}
}