Merge pull request #12337 from lcdservices/dev-core-190
[civicrm-core.git] / tests / phpunit / api / v3 / LineItemTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
2fe49090 4| CiviCRM version 5 |
b6708aeb 5+--------------------------------------------------------------------+
6b83d5bd 6| Copyright CiviCRM LLC (c) 2004-2019 |
b6708aeb 7+--------------------------------------------------------------------+
8| This file is a part of CiviCRM. |
9| |
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. |
13| |
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. |
18| |
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+--------------------------------------------------------------------+
e70a7fc0 26 */
6a488035 27
e9479dcf
EM
28/**
29 * Class api_v3_LineItemTest
acb109b7 30 * @group headless
e9479dcf 31 */
6a488035
TO
32class api_v3_LineItemTest extends CiviUnitTestCase {
33 protected $_apiversion = 3;
34 protected $testAmount = 34567;
35 protected $params;
36 protected $id = 0;
37 protected $contactIds = array();
38 protected $_entity = 'line_item';
6c6e6187 39 protected $contribution_result = NULL;
b7c9bc4c 40
6a488035 41 public $DBResetRequired = TRUE;
609a7918 42 protected $_financialTypeId = 1;
43
6a488035
TO
44 public function setUp() {
45 parent::setUp();
739ee24f 46 $this->useTransaction(TRUE);
6a488035
TO
47 $this->_individualId = $this->individualCreate();
48 $contributionParams = array(
49 'contact_id' => $this->_individualId,
50 'receive_date' => '20120511',
51 'total_amount' => 100.00,
609a7918 52 'financial_type_id' => $this->_financialTypeId,
6a488035
TO
53 'non_deductible_amount' => 10.00,
54 'fee_amount' => 51.00,
55 'net_amount' => 91.00,
56 'source' => 'SSF',
57 'contribution_status_id' => 1,
6a488035 58 );
6c6e6187 59 $contribution = $this->callAPISuccess('contribution', 'create', $contributionParams);
6a488035 60 $this->params = array(
6a488035
TO
61 'price_field_value_id' => 1,
62 'price_field_id' => 1,
63 'entity_table' => 'civicrm_contribution',
64 'entity_id' => $contribution['id'],
65 'qty' => 1,
66 'unit_price' => 50,
67 'line_total' => 50,
68 );
69 }
70
6a488035 71 public function testCreateLineItem() {
609a7918 72 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params + array('debug' => 1), __FUNCTION__, __FILE__);
ba4a1892
TM
73 $this->assertEquals(1, $result['count']);
74 $this->assertNotNull($result['values'][$result['id']]['id']);
6a488035
TO
75 $this->getAndCheck($this->params, $result['id'], $this->_entity);
76 }
77
78 public function testGetBasicLineItem() {
79 $getParams = array(
6a488035
TO
80 'entity_table' => 'civicrm_contribution',
81 );
609a7918 82 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
ba4a1892 83 $this->assertEquals(1, $getResult['count']);
6a488035
TO
84 }
85
86 public function testDeleteLineItem() {
5896d037
TO
87 $getParams = array(
88 'entity_table' => 'civicrm_contribution',
6a488035 89 );
609a7918 90 $getResult = $this->callAPISuccess($this->_entity, 'get', $getParams);
91 $deleteParams = array('id' => $getResult['id']);
92 $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
442bd3c1 93 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
ba4a1892 94 $this->assertEquals(0, $checkDeleted['count']);
6a488035
TO
95 }
96
97 public function testGetFieldsLineItem() {
6c6e6187 98 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
6a488035
TO
99 $this->assertEquals(1, $result['values']['entity_id']['api.required']);
100 }
101
6a488035 102}