tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / api / v3 / PriceFieldValueTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
81621fee 4| CiviCRM version 4.7 |
b6708aeb 5+--------------------------------------------------------------------+
e7112fa7 6| Copyright CiviCRM LLC (c) 2004-2015 |
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+--------------------------------------------------------------------+
e70a7fc0 26 */
6a488035 27
e9479dcf
EM
28/**
29 * Class api_v3_PriceFieldValueTest
30 */
6a488035
TO
31class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
32 protected $_apiversion = 3;
33 protected $_params;
34 protected $id = 0;
35 protected $priceSetID = 0;
36 protected $_entity = 'price_field_value';
b7c9bc4c 37
6a488035
TO
38 public $DBResetRequired = TRUE;
39
78373706
EM
40 /**
41 * @var int
42 */
43 protected $priceFieldID;
44
45 /**
46 * Setup function.
47 */
6a488035
TO
48 public function setUp() {
49 parent::setUp();
78373706
EM
50 // Put stuff here that should happen before all tests in this unit.
51 $priceSetParams = array(
6a488035 52 'name' => 'default_goat_priceset',
78373706 53 'title' => 'Goat accommodation',
6a488035
TO
54 'is_active' => 1,
55 'help_pre' => "Where does your goat sleep",
56 'help_post' => "thank you for your time",
57 'extends' => 2,
58 'financial_type_id' => 1,
59 'is_quick_config' => 1,
60 'is_reserved' => 1,
61 );
62
78373706 63 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
6a488035
TO
64 $this->priceSetID = $price_set['id'];
65
78373706 66 $priceFieldParams = array(
6a488035
TO
67 'price_set_id' => $this->priceSetID,
68 'name' => 'grassvariety',
69 'label' => 'Grass Variety',
70 'html_type' => 'Text',
71 'is_enter_qty' => 1,
72 'is_active' => 1,
73 );
78373706 74 $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
6a488035
TO
75 $this->priceFieldID = $priceField['id'];
76 $this->_params = array(
6a488035 77 'price_field_id' => $this->priceFieldID,
78373706 78 'name' => 'rye grass',
6a488035 79 'label' => 'juicy and healthy',
21dfd5f5 80 'amount' => 1,
43dbd988 81 'financial_type_id' => 1,
92915c55 82 );
b6708aeb 83
6a488035 84 $membershipOrgId = $this->organizationCreate(NULL);
75638074 85 $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
78373706 86 $priceSetParams1 = array(
6a488035
TO
87 'name' => 'priceset',
88 'title' => 'Priceset with Multiple Terms',
89 'is_active' => 1,
90 'extends' => 3,
91 'financial_type_id' => 2,
92 'is_quick_config' => 1,
93 'is_reserved' => 1,
94 );
78373706 95 $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetParams1);
6a488035 96 $this->priceSetID1 = $price_set1['id'];
78373706 97 $priceFieldParams1 = array(
6a488035
TO
98 'price_set_id' => $this->priceSetID1,
99 'name' => 'memtype',
100 'label' => 'memtype',
101 'html_type' => 'Radio',
102 'is_enter_qty' => 1,
103 'is_active' => 1,
104 );
78373706 105 $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldParams1);
6a488035
TO
106 $this->priceFieldID1 = $priceField1['id'];
107 }
108
78373706
EM
109 /**
110 * Tear down function.
111 *
112 * @throws \Exception
113 */
00be9182 114 public function tearDown() {
6a488035 115 $tablesToTruncate = array(
92915c55
TO
116 'civicrm_contact',
117 'civicrm_contribution',
6a488035
TO
118 );
119 $this->quickCleanup($tablesToTruncate);
120 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
6c6e6187 121 $this->callAPISuccess('PriceField', 'delete', array(
92915c55 122 'id' => $this->priceFieldID1,
6a488035 123 ));
6c6e6187 124 $this->callAPISuccess('PriceSet', 'delete', array(
6a488035
TO
125 'id' => $this->priceSetID1,
126 ));
6c6e6187 127 $this->callAPISuccess('PriceField', 'delete', array(
92915c55 128 'id' => $this->priceFieldID,
6a488035 129 ));
6c6e6187 130 $delete = $this->callAPISuccess('PriceSet', 'delete', array(
6a488035
TO
131 'id' => $this->priceSetID,
132 ));
133
134 $this->assertAPISuccess($delete);
135 }
136
137 public function testCreatePriceFieldValue() {
ca985406 138 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
a15773db 139 $this->assertAPISuccess($result);
ba4a1892
TM
140 $this->assertEquals(1, $result['count']);
141 $this->assertNotNull($result['values'][$result['id']]['id']);
6a488035
TO
142 $this->getAndCheck($this->_params, $result['id'], $this->_entity);
143 }
144
145 public function testGetBasicPriceFieldValue() {
ca985406 146 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
6a488035
TO
147 $this->id = $createResult['id'];
148 $this->assertAPISuccess($createResult);
149 $getParams = array(
6a488035
TO
150 'name' => 'contribution_amount',
151 );
ca985406 152 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
ba4a1892 153 $this->assertEquals(1, $getResult['count']);
6c6e6187 154 $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id']));
6a488035
TO
155 }
156
157 public function testDeletePriceFieldValue() {
ca985406 158 $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
159 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
160 $deleteParams = array('id' => $createResult['id']);
161 $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
162
163 $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
a15773db 164 $this->assertEquals($startCount, $endCount);
6a488035
TO
165 }
166
167 public function testGetFieldsPriceFieldValue() {
ca985406 168 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
6a488035
TO
169 $this->assertEquals(1, $result['values']['max_value']['type']);
170 }
171
172 public function testCreatePriceFieldValuewithMultipleTerms() {
173 $params = array(
6a488035 174 'price_field_id' => $this->priceFieldID1,
6c6e6187 175 'membership_type_id' => $this->_membershipTypeID,
6a488035
TO
176 'name' => 'memType1',
177 'label' => 'memType1',
178 'amount' => 90,
179 'membership_num_terms' => 2,
180 'is_active' => 1,
181 'financial_type_id' => 2,
92915c55 182 );
ca985406 183 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
6a488035 184 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
ba4a1892 185 $this->assertEquals(1, $result['count']);
ca985406 186 $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
6a488035 187 }
92915c55 188
6a488035
TO
189 public function testGetPriceFieldValuewithMultipleTerms() {
190 $params1 = array(
6a488035 191 'price_field_id' => $this->priceFieldID1,
6c6e6187 192 'membership_type_id' => $this->_membershipTypeID,
6a488035
TO
193 'name' => 'memType1',
194 'label' => 'memType1',
195 'amount' => 90,
196 'membership_num_terms' => 2,
197 'is_active' => 1,
198 'financial_type_id' => 2,
92915c55 199 );
6a488035 200 $params2 = array(
6a488035 201 'price_field_id' => $this->priceFieldID1,
6c6e6187 202 'membership_type_id' => $this->_membershipTypeID,
6a488035
TO
203 'name' => 'memType2',
204 'label' => 'memType2',
205 'amount' => 120,
206 'membership_num_terms' => 3,
207 'is_active' => 1,
208 'financial_type_id' => 2,
92915c55 209 );
ca985406 210 $result1 = $this->callAPISuccess($this->_entity, 'create', $params1);
211 $result2 = $this->callAPISuccess($this->_entity, 'create', $params2);
481a74f4 212 $result = $this->callAPISuccess($this->_entity, 'get', array('price_field_id' => $this->priceFieldID1));
ba4a1892 213 $this->assertEquals(2, $result['count']);
6c6e6187
TO
214 $this->callAPISuccess($this->_entity, 'delete', array('id' => $result1['id']));
215 $this->callAPISuccess($this->_entity, 'delete', array('id' => $result2['id']));
6a488035 216 }
96025800 217
6a488035 218}