3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class api_v3_PriceFieldValueTest
32 class api_v3_PriceFieldValueTest
extends CiviUnitTestCase
{
33 protected $_apiversion = 3;
36 protected $priceSetID = 0;
37 protected $_entity = 'price_field_value';
39 public $DBResetRequired = TRUE;
44 protected $priceFieldID;
49 public function setUp() {
51 // Put stuff here that should happen before all tests in this unit.
52 $priceSetParams = array(
53 'name' => 'default_goat_priceset',
54 'title' => 'Goat accommodation',
56 'help_pre' => "Where does your goat sleep",
57 'help_post' => "thank you for your time",
59 'financial_type_id' => 1,
60 'is_quick_config' => 1,
64 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
65 $this->priceSetID
= $price_set['id'];
67 $priceFieldParams = array(
68 'price_set_id' => $this->priceSetID
,
69 'name' => 'grassvariety',
70 'label' => 'Grass Variety',
71 'html_type' => 'Text',
75 $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
76 $this->priceFieldID
= $priceField['id'];
77 $this->_params
= array(
78 'price_field_id' => $this->priceFieldID
,
79 'name' => 'rye grass',
80 'label' => 'juicy and healthy',
82 'financial_type_id' => 1,
85 $membershipOrgId = $this->organizationCreate(NULL);
86 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
87 $priceSetParams1 = array(
89 'title' => 'Priceset with Multiple Terms',
92 'financial_type_id' => 2,
93 'is_quick_config' => 1,
96 $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetParams1);
97 $this->priceSetID1
= $price_set1['id'];
98 $priceFieldParams1 = array(
99 'price_set_id' => $this->priceSetID1
,
101 'label' => 'memtype',
102 'html_type' => 'Radio',
106 $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldParams1);
107 $this->priceFieldID1
= $priceField1['id'];
111 * Tear down function.
115 public function tearDown() {
116 $tablesToTruncate = array(
118 'civicrm_contribution',
120 $this->quickCleanup($tablesToTruncate);
121 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
122 $this->callAPISuccess('PriceField', 'delete', array(
123 'id' => $this->priceFieldID1
,
125 $this->callAPISuccess('PriceSet', 'delete', array(
126 'id' => $this->priceSetID1
,
128 $this->callAPISuccess('PriceField', 'delete', array(
129 'id' => $this->priceFieldID
,
131 $delete = $this->callAPISuccess('PriceSet', 'delete', array(
132 'id' => $this->priceSetID
,
135 $this->assertAPISuccess($delete);
138 public function testCreatePriceFieldValue() {
139 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
140 $this->assertAPISuccess($result);
141 $this->assertEquals(1, $result['count']);
142 $this->assertNotNull($result['values'][$result['id']]['id']);
143 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
146 public function testGetBasicPriceFieldValue() {
147 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
148 $this->id
= $createResult['id'];
149 $this->assertAPISuccess($createResult);
151 'name' => 'contribution_amount',
153 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
154 $this->assertEquals(1, $getResult['count']);
155 $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id']));
158 public function testDeletePriceFieldValue() {
159 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
160 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
161 $deleteParams = array('id' => $createResult['id']);
162 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
164 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
165 $this->assertEquals($startCount, $endCount);
168 public function testGetFieldsPriceFieldValue() {
169 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
170 $this->assertEquals(1, $result['values']['max_value']['type']);
173 public function testCreatePriceFieldValuewithMultipleTerms() {
175 'price_field_id' => $this->priceFieldID1
,
176 'membership_type_id' => $this->_membershipTypeID
,
177 'name' => 'memType1',
178 'label' => 'memType1',
180 'membership_num_terms' => 2,
182 'financial_type_id' => 2,
184 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
185 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
186 $this->assertEquals(1, $result['count']);
187 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result['id']));
190 public function testGetPriceFieldValuewithMultipleTerms() {
192 'price_field_id' => $this->priceFieldID1
,
193 'membership_type_id' => $this->_membershipTypeID
,
194 'name' => 'memType1',
195 'label' => 'memType1',
197 'membership_num_terms' => 2,
199 'financial_type_id' => 2,
202 'price_field_id' => $this->priceFieldID1
,
203 'membership_type_id' => $this->_membershipTypeID
,
204 'name' => 'memType2',
205 'label' => 'memType2',
207 'membership_num_terms' => 3,
209 'financial_type_id' => 2,
211 $result1 = $this->callAPISuccess($this->_entity
, 'create', $params1);
212 $result2 = $this->callAPISuccess($this->_entity
, 'create', $params2);
213 $result = $this->callAPISuccess($this->_entity
, 'get', array('price_field_id' => $this->priceFieldID1
));
214 $this->assertEquals(2, $result['count']);
215 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result1['id']));
216 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result2['id']));