Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f TO |
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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 10 | */ |
6a488035 | 11 | |
e9479dcf EM |
12 | /** |
13 | * Class api_v3_LineItemTest | |
acb109b7 | 14 | * @group headless |
e9479dcf | 15 | */ |
6a488035 TO |
16 | class api_v3_LineItemTest extends CiviUnitTestCase { |
17 | protected $_apiversion = 3; | |
18 | protected $testAmount = 34567; | |
19 | protected $params; | |
20 | protected $id = 0; | |
9099cab3 | 21 | protected $contactIds = []; |
6a488035 | 22 | protected $_entity = 'line_item'; |
6c6e6187 | 23 | protected $contribution_result = NULL; |
b7c9bc4c | 24 | |
6a488035 | 25 | public $DBResetRequired = TRUE; |
609a7918 | 26 | protected $_financialTypeId = 1; |
27 | ||
6a488035 TO |
28 | public function setUp() { |
29 | parent::setUp(); | |
739ee24f | 30 | $this->useTransaction(TRUE); |
6a488035 | 31 | $this->_individualId = $this->individualCreate(); |
9099cab3 | 32 | $contributionParams = [ |
6a488035 TO |
33 | 'contact_id' => $this->_individualId, |
34 | 'receive_date' => '20120511', | |
35 | 'total_amount' => 100.00, | |
609a7918 | 36 | 'financial_type_id' => $this->_financialTypeId, |
6a488035 TO |
37 | 'non_deductible_amount' => 10.00, |
38 | 'fee_amount' => 51.00, | |
39 | 'net_amount' => 91.00, | |
40 | 'source' => 'SSF', | |
41 | 'contribution_status_id' => 1, | |
9099cab3 | 42 | ]; |
6c6e6187 | 43 | $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams); |
9099cab3 | 44 | $this->params = [ |
6a488035 TO |
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, | |
9099cab3 | 52 | ]; |
6a488035 TO |
53 | } |
54 | ||
6a488035 | 55 | public function testCreateLineItem() { |
9099cab3 | 56 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params + ['debug' => 1], __FUNCTION__, __FILE__); |
ba4a1892 TM |
57 | $this->assertEquals(1, $result['count']); |
58 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
59 | $this->getAndCheck($this->params, $result['id'], $this->_entity); |
60 | } | |
61 | ||
62 | public function testGetBasicLineItem() { | |
9099cab3 | 63 | $getParams = [ |
6a488035 | 64 | 'entity_table' => 'civicrm_contribution', |
9099cab3 | 65 | ]; |
609a7918 | 66 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
ba4a1892 | 67 | $this->assertEquals(1, $getResult['count']); |
6a488035 TO |
68 | } |
69 | ||
70 | public function testDeleteLineItem() { | |
9099cab3 | 71 | $getParams = [ |
5896d037 | 72 | 'entity_table' => 'civicrm_contribution', |
9099cab3 | 73 | ]; |
609a7918 | 74 | $getResult = $this->callAPISuccess($this->_entity, 'get', $getParams); |
9099cab3 | 75 | $deleteParams = ['id' => $getResult['id']]; |
609a7918 | 76 | $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); |
9099cab3 | 77 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); |
ba4a1892 | 78 | $this->assertEquals(0, $checkDeleted['count']); |
6a488035 TO |
79 | } |
80 | ||
81 | public function testGetFieldsLineItem() { | |
9099cab3 | 82 | $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); |
6a488035 TO |
83 | $this->assertEquals(1, $result['values']['entity_id']['api.required']); |
84 | } | |
85 | ||
6a488035 | 86 | } |