3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class api_v3_PriceFieldValueTest
16 class api_v3_PriceFieldValueTest
extends CiviUnitTestCase
{
17 protected $_apiversion = 3;
20 protected $priceSetID = 0;
21 protected $_entity = 'price_field_value';
23 public $DBResetRequired = TRUE;
28 protected $priceFieldID;
33 public function setUp() {
35 // Put stuff here that should happen before all tests in this unit.
37 'name' => 'default_goat_priceset',
38 'title' => 'Goat accommodation',
40 'help_pre' => "Where does your goat sleep",
41 'help_post' => "thank you for your time",
43 'financial_type_id' => 1,
44 'is_quick_config' => 1,
48 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
49 $this->priceSetID
= $price_set['id'];
52 'price_set_id' => $this->priceSetID
,
53 'name' => 'grassvariety',
54 'label' => 'Grass Variety',
55 'html_type' => 'Text',
59 $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
60 $this->priceFieldID
= $priceField['id'];
62 'price_field_id' => $this->priceFieldID
,
63 'name' => 'rye grass',
64 'label' => 'juicy and healthy',
66 'financial_type_id' => 1,
69 $membershipOrgId = $this->organizationCreate(NULL);
70 $this->_membershipTypeID
= $this->membershipTypeCreate(['member_of_contact_id' => $membershipOrgId]);
73 'title' => 'Priceset with Multiple Terms',
76 'financial_type_id' => 2,
77 'is_quick_config' => 1,
80 $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetParams1);
81 $this->priceSetID1
= $price_set1['id'];
82 $priceFieldParams1 = [
83 'price_set_id' => $this->priceSetID1
,
86 'html_type' => 'Radio',
90 $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldParams1);
91 $this->priceFieldID1
= $priceField1['id'];
99 public function tearDown() {
100 $tablesToTruncate = [
102 'civicrm_contribution',
104 $this->quickCleanup($tablesToTruncate);
105 $this->membershipTypeDelete(['id' => $this->_membershipTypeID
]);
106 $this->callAPISuccess('PriceField', 'delete', [
107 'id' => $this->priceFieldID1
,
109 $this->callAPISuccess('PriceSet', 'delete', [
110 'id' => $this->priceSetID1
,
112 $this->callAPISuccess('PriceField', 'delete', [
113 'id' => $this->priceFieldID
,
115 $delete = $this->callAPISuccess('PriceSet', 'delete', [
116 'id' => $this->priceSetID
,
119 $this->assertAPISuccess($delete);
122 public function testCreatePriceFieldValue() {
123 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
124 $this->assertAPISuccess($result);
125 $this->assertEquals(1, $result['count']);
126 $this->assertNotNull($result['values'][$result['id']]['id']);
127 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
130 public function testGetBasicPriceFieldValue() {
131 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
132 $this->id
= $createResult['id'];
133 $this->assertAPISuccess($createResult);
135 'name' => 'contribution_amount',
137 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
138 $this->assertEquals(1, $getResult['count']);
139 $this->callAPISuccess('price_field_value', 'delete', ['id' => $createResult['id']]);
142 public function testDeletePriceFieldValue() {
143 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
144 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
145 $deleteParams = ['id' => $createResult['id']];
146 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
148 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
149 $this->assertEquals($startCount, $endCount);
152 public function testGetFieldsPriceFieldValue() {
153 $result = $this->callAPISuccess($this->_entity
, 'getfields', ['action' => 'create']);
154 $this->assertEquals(1, $result['values']['max_value']['type']);
157 public function testCreatePriceFieldValuewithMultipleTerms() {
159 'price_field_id' => $this->priceFieldID1
,
160 'membership_type_id' => $this->_membershipTypeID
,
161 'name' => 'memType1',
162 'label' => 'memType1',
164 'membership_num_terms' => 2,
166 'financial_type_id' => 2,
168 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
169 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
170 $this->assertEquals(1, $result['count']);
171 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
174 public function testGetPriceFieldValuewithMultipleTerms() {
176 'price_field_id' => $this->priceFieldID1
,
177 'membership_type_id' => $this->_membershipTypeID
,
178 'name' => 'memType1',
179 'label' => 'memType1',
181 'membership_num_terms' => 2,
183 'financial_type_id' => 2,
186 'price_field_id' => $this->priceFieldID1
,
187 'membership_type_id' => $this->_membershipTypeID
,
188 'name' => 'memType2',
189 'label' => 'memType2',
191 'membership_num_terms' => 3,
193 'financial_type_id' => 2,
195 $result1 = $this->callAPISuccess($this->_entity
, 'create', $params1);
196 $result2 = $this->callAPISuccess($this->_entity
, 'create', $params2);
197 $result = $this->callAPISuccess($this->_entity
, 'get', ['price_field_id' => $this->priceFieldID1
]);
198 $this->assertEquals(2, $result['count']);
199 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result1['id']]);
200 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result2['id']]);
203 public function testCreatePriceFieldValueWithDisabledFinancialType() {
204 $financialTypeParams = [
206 'name' => 'Disabled Donations',
208 $financialType = $this->callAPISuccess('financial_type', 'create', $financialTypeParams);
210 'price_field_id' => $this->priceFieldID
,
211 'name' => 'DonType1',
212 'label' => 'DonType1',
215 'financial_type_id' => $financialType['id'],
217 $this->callAPIFailure($this->_entity
, 'create', $params);