4 require_once 'CiviTest/CiviUnitTestCase.php';
5 class api_v3_LineItemTest
extends CiviUnitTestCase
{
6 protected $_apiversion = 3;
7 protected $testAmount = 34567;
10 protected $contactIds = array();
11 protected $_entity = 'line_item';
12 protected $contribution_result = null;
13 public $_eNoticeCompliant = TRUE;
14 public $DBResetRequired = TRUE;
15 public function setUp() {
17 $this->_contributionTypeId
= $this->contributionTypeCreate();
18 $this->_individualId
= $this->individualCreate();
19 $contributionParams = array(
20 'contact_id' => $this->_individualId
,
21 'receive_date' => '20120511',
22 'total_amount' => 100.00,
23 'financial_type_id' => $this->_contributionTypeId
,
24 'non_deductible_amount' => 10.00,
25 'fee_amount' => 51.00,
26 'net_amount' => 91.00,
28 'contribution_status_id' => 1,
29 'version' => $this->_apiversion
,
31 $contribution = civicrm_api('contribution','create', $contributionParams);
32 $this->params
= array(
33 'version' => $this->_apiversion
,
34 'price_field_value_id' => 1,
35 'price_field_id' => 1,
36 'entity_table' => 'civicrm_contribution',
37 'entity_id' => $contribution['id'],
46 foreach ($this->contactIds
as $id) {
47 civicrm_api('contact', 'delete', array('version' => $this->_apiversion
, 'id' => $id));
52 'civicrm_contribution',
56 $this->contributionTypeDelete();
59 public function testCreateLineItem() {
65 $result = civicrm_api($this->_entity
, 'create', $this->params +
array('debug' => 1));
66 $this->id
= $result['id'];
67 $this->documentMe($this->params
, $result, __FUNCTION__
, __FILE__
);
68 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
69 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
70 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
71 $this->getAndCheck($this->params
, $result['id'], $this->_entity
);
74 public function testGetBasicLineItem() {
76 'version' => $this->_apiversion
,
77 'entity_table' => 'civicrm_contribution',
79 $getResult = civicrm_api($this->_entity
, 'get', $getParams);
80 $this->documentMe($getParams, $getResult, __FUNCTION__
, __FILE__
);
81 $this->assertAPISuccess($getResult, 'In line ' . __LINE__
);
82 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
85 public function testDeleteLineItem() {
87 'version' => $this->_apiversion
,
88 'entity_table' => 'civicrm_contribution',
90 $getResult = civicrm_api($this->_entity
, 'get', $getParams);
91 $deleteParams = array('version' => $this->_apiversion
, 'id' => $getResult['id']);
92 $deleteResult = civicrm_api($this->_entity
, 'delete', $deleteParams);
93 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__
, __FILE__
);
94 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__
);
95 $checkDeleted = civicrm_api($this->_entity
, 'get', array(
96 'version' => $this->_apiversion
,
98 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__
);
101 public function testGetFieldsLineItem() {
102 $result = civicrm_api($this->_entity
, 'getfields', array('action' => 'create', 'version' => $this->_apiversion
, 'action' => 'create'));
103 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
104 $this->assertEquals(1, $result['values']['entity_id']['api.required']);
107 public static function setUpBeforeClass() {
108 // put stuff here that should happen before all tests in this unit
111 public static function tearDownAfterClass(){
112 $tablesToTruncate = array(
114 'civicrm_financial_type',
115 'civicrm_contribution',
118 $unitTest = new CiviUnitTestCase();
119 $unitTest->quickCleanup($tablesToTruncate);