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