fix e-Notice on deprecated utils
[civicrm-core.git] / tests / phpunit / api / v3 / LineItemTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
232624b1 4| CiviCRM version 4.4 |
b6708aeb 5+--------------------------------------------------------------------+
6| Copyright CiviCRM LLC (c) 2004-2013 |
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*/
6a488035
TO
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29class api_v3_LineItemTest extends CiviUnitTestCase {
30 protected $_apiversion = 3;
31 protected $testAmount = 34567;
32 protected $params;
33 protected $id = 0;
34 protected $contactIds = array();
35 protected $_entity = 'line_item';
36 protected $contribution_result = null;
37 public $_eNoticeCompliant = TRUE;
38 public $DBResetRequired = TRUE;
609a7918 39 protected $_financialTypeId = 1;
40
6a488035
TO
41 public function setUp() {
42 parent::setUp();
6a488035
TO
43 $this->_individualId = $this->individualCreate();
44 $contributionParams = array(
45 'contact_id' => $this->_individualId,
46 'receive_date' => '20120511',
47 'total_amount' => 100.00,
609a7918 48 'financial_type_id' => $this->_financialTypeId,
6a488035
TO
49 'non_deductible_amount' => 10.00,
50 'fee_amount' => 51.00,
51 'net_amount' => 91.00,
52 'source' => 'SSF',
53 'contribution_status_id' => 1,
6a488035 54 );
609a7918 55 $contribution = $this->callAPISuccess('contribution','create', $contributionParams);
6a488035 56 $this->params = array(
6a488035
TO
57 'price_field_value_id' => 1,
58 'price_field_id' => 1,
59 'entity_table' => 'civicrm_contribution',
60 'entity_id' => $contribution['id'],
61 'qty' => 1,
62 'unit_price' => 50,
63 'line_total' => 50,
64 );
65 }
66
67 function tearDown() {
68
69 foreach ($this->contactIds as $id) {
609a7918 70 $this->callAPISuccess('contact', 'delete', array('id' => $id));
6a488035
TO
71 }
72 $this->quickCleanup(
73 array(
74 'civicrm_contact',
75 'civicrm_contribution',
76 'civicrm_line_item',
77 )
78 );
6a488035
TO
79 }
80
81 public function testCreateLineItem() {
82 $this->quickCleanup(
83 array(
84 'civicrm_line_item',
85 )
86 );
609a7918 87 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->params + array('debug' => 1), __FUNCTION__, __FILE__);
6a488035
TO
88 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
89 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
90 $this->getAndCheck($this->params, $result['id'], $this->_entity);
91 }
92
93 public function testGetBasicLineItem() {
94 $getParams = array(
6a488035
TO
95 'entity_table' => 'civicrm_contribution',
96 );
609a7918 97 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
6a488035
TO
98 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
99 }
100
101 public function testDeleteLineItem() {
609a7918 102 $getParams = array( 'entity_table' => 'civicrm_contribution',
6a488035 103 );
609a7918 104 $getResult = $this->callAPISuccess($this->_entity, 'get', $getParams);
105 $deleteParams = array('id' => $getResult['id']);
106 $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
442bd3c1 107 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
6a488035
TO
108 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
109 }
110
111 public function testGetFieldsLineItem() {
609a7918 112 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create', 'action' => 'create'));
6a488035
TO
113 $this->assertEquals(1, $result['values']['entity_id']['api.required']);
114 }
115
116 public static function setUpBeforeClass() {
117 // put stuff here that should happen before all tests in this unit
118 }
119
120 public static function tearDownAfterClass(){
121 $tablesToTruncate = array(
122 'civicrm_contact',
123 'civicrm_financial_type',
124 'civicrm_contribution',
125 'civicrm_line_item',
126 );
127 $unitTest = new CiviUnitTestCase();
128 $unitTest->quickCleanup($tablesToTruncate);
129 }
130}
131