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