Add 'name' field to pseudoconstant schema CRM-12464
[civicrm-core.git] / tests / phpunit / api / v3 / LineItemTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
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. |
14 | |
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. |
19 | |
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 +--------------------------------------------------------------------+
27 */
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30 class api_v3_LineItemTest extends CiviUnitTestCase {
31 protected $_apiversion = 3;
32 protected $testAmount = 34567;
33 protected $params;
34 protected $id = 0;
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() {
41 parent::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,
52 'source' => 'SSF',
53 'contribution_status_id' => 1,
54 'version' => $this->_apiversion,
55 );
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'],
63 'qty' => 1,
64 'unit_price' => 50,
65 'line_total' => 50,
66 );
67 }
68
69 function tearDown() {
70
71 foreach ($this->contactIds as $id) {
72 civicrm_api('contact', 'delete', array('version' => $this->_apiversion, 'id' => $id));
73 }
74 $this->quickCleanup(
75 array(
76 'civicrm_contact',
77 'civicrm_contribution',
78 'civicrm_line_item',
79 )
80 );
81 $this->contributionTypeDelete();
82 }
83
84 public function testCreateLineItem() {
85 $this->quickCleanup(
86 array(
87 'civicrm_line_item',
88 )
89 );
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);
97 }
98
99 public function testGetBasicLineItem() {
100 $getParams = array(
101 'version' => $this->_apiversion,
102 'entity_table' => 'civicrm_contribution',
103 );
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__);
108 }
109
110 public function testDeleteLineItem() {
111 $getParams = array(
112 'version' => $this->_apiversion,
113 'entity_table' => 'civicrm_contribution',
114 );
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,
122 ));
123 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
124 }
125
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']);
130 }
131
132 public static function setUpBeforeClass() {
133 // put stuff here that should happen before all tests in this unit
134 }
135
136 public static function tearDownAfterClass(){
137 $tablesToTruncate = array(
138 'civicrm_contact',
139 'civicrm_financial_type',
140 'civicrm_contribution',
141 'civicrm_line_item',
142 );
143 $unitTest = new CiviUnitTestCase();
144 $unitTest->quickCleanup($tablesToTruncate);
145 }
146 }
147