CRM-13014 support userLoginFinalize() for UF classes (fix civimobile)
[civicrm-core.git] / tests / phpunit / api / v3 / LineItemTest.php
1 <?php
2 // $Id$
3
4 require_once 'CiviTest/CiviUnitTestCase.php';
5 class api_v3_LineItemTest extends CiviUnitTestCase {
6 protected $_apiversion = 3;
7 protected $testAmount = 34567;
8 protected $params;
9 protected $id = 0;
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() {
16 parent::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,
27 'source' => 'SSF',
28 'contribution_status_id' => 1,
29 'version' => $this->_apiversion,
30 );
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'],
38 'qty' => 1,
39 'unit_price' => 50,
40 'line_total' => 50,
41 );
42 }
43
44 function tearDown() {
45
46 foreach ($this->contactIds as $id) {
47 civicrm_api('contact', 'delete', array('version' => $this->_apiversion, 'id' => $id));
48 }
49 $this->quickCleanup(
50 array(
51 'civicrm_contact',
52 'civicrm_contribution',
53 'civicrm_line_item',
54 )
55 );
56 $this->contributionTypeDelete();
57 }
58
59 public function testCreateLineItem() {
60 $this->quickCleanup(
61 array(
62 'civicrm_line_item',
63 )
64 );
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);
72 }
73
74 public function testGetBasicLineItem() {
75 $getParams = array(
76 'version' => $this->_apiversion,
77 'entity_table' => 'civicrm_contribution',
78 );
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__);
83 }
84
85 public function testDeleteLineItem() {
86 $getParams = array(
87 'version' => $this->_apiversion,
88 'entity_table' => 'civicrm_contribution',
89 );
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,
97 ));
98 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
99 }
100
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']);
105 }
106
107 public static function setUpBeforeClass() {
108 // put stuff here that should happen before all tests in this unit
109 }
110
111 public static function tearDownAfterClass(){
112 $tablesToTruncate = array(
113 'civicrm_contact',
114 'civicrm_financial_type',
115 'civicrm_contribution',
116 'civicrm_line_item',
117 );
118 $unitTest = new CiviUnitTestCase();
119 $unitTest->quickCleanup($tablesToTruncate);
120 }
121 }
122