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