4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
30 class api_v3_LineItemTest
extends CiviUnitTestCase
{
31 protected $_apiversion = 3;
32 protected $testAmount = 34567;
35 protected $contactIds = array();
36 protected $_entity = 'line_item';
37 protected $contribution_result = null;
38 public $_eNoticeCompliant = TRUE;
39 public $DBResetRequired = TRUE;
40 public function setUp() {
42 $this->_contributionTypeId
= $this->contributionTypeCreate();
43 $this->_individualId
= $this->individualCreate();
44 $contributionParams = array(
45 'contact_id' => $this->_individualId
,
46 'receive_date' => '20120511',
47 'total_amount' => 100.00,
48 'financial_type_id' => $this->_contributionTypeId
,
49 'non_deductible_amount' => 10.00,
50 'fee_amount' => 51.00,
51 'net_amount' => 91.00,
53 'contribution_status_id' => 1,
54 'version' => $this->_apiversion
,
56 $contribution = civicrm_api('contribution','create', $contributionParams);
57 $this->params
= array(
58 'version' => $this->_apiversion
,
59 'price_field_value_id' => 1,
60 'price_field_id' => 1,
61 'entity_table' => 'civicrm_contribution',
62 'entity_id' => $contribution['id'],
71 foreach ($this->contactIds
as $id) {
72 civicrm_api('contact', 'delete', array('version' => $this->_apiversion
, 'id' => $id));
77 'civicrm_contribution',
81 $this->contributionTypeDelete();
84 public function testCreateLineItem() {
90 $result = civicrm_api($this->_entity
, 'create', $this->params +
array('debug' => 1));
91 $this->id
= $result['id'];
92 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
93 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
94 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
95 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
96 $this->getAndCheck($this->params
, $result['id'], $this->_entity
);
99 public function testGetBasicLineItem() {
101 'version' => $this->_apiversion
,
102 'entity_table' => 'civicrm_contribution',
104 $getResult = civicrm_api($this->_entity
, 'get', $getParams);
105 $this->documentMe($getParams, $getResult, __FUNCTION__
, __FILE__
);
106 $this->assertAPISuccess($getResult, 'In line ' . __LINE__
);
107 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
110 public function testDeleteLineItem() {
112 'version' => $this->_apiversion
,
113 'entity_table' => 'civicrm_contribution',
115 $getResult = civicrm_api($this->_entity
, 'get', $getParams);
116 $deleteParams = array('version' => $this->_apiversion
, 'id' => $getResult['id']);
117 $deleteResult = civicrm_api($this->_entity
, 'delete', $deleteParams);
118 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__
, __FILE__
);
119 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__
);
120 $checkDeleted = civicrm_api($this->_entity
, 'get', array(
121 'version' => $this->_apiversion
,
123 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__
);
126 public function testGetFieldsLineItem() {
127 $result = civicrm_api($this->_entity
, 'getfields', array('action' => 'create', 'version' => $this->_apiversion
, 'action' => 'create'));
128 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
129 $this->assertEquals(1, $result['values']['entity_id']['api.required']);
132 public static function setUpBeforeClass() {
133 // put stuff here that should happen before all tests in this unit
136 public static function tearDownAfterClass(){
137 $tablesToTruncate = array(
139 'civicrm_financial_type',
140 'civicrm_contribution',
143 $unitTest = new CiviUnitTestCase();
144 $unitTest->quickCleanup($tablesToTruncate);