3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Class api_v3_PriceFieldValueTest
33 class api_v3_PriceFieldValueTest
extends CiviUnitTestCase
{
34 protected $_apiversion = 3;
37 protected $priceSetID = 0;
38 protected $_entity = 'price_field_value';
40 public $DBResetRequired = TRUE;
45 protected $priceFieldID;
50 public function setUp() {
52 // Put stuff here that should happen before all tests in this unit.
53 $priceSetParams = array(
54 'name' => 'default_goat_priceset',
55 'title' => 'Goat accommodation',
57 'help_pre' => "Where does your goat sleep",
58 'help_post' => "thank you for your time",
60 'financial_type_id' => 1,
61 'is_quick_config' => 1,
65 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
66 $this->priceSetID
= $price_set['id'];
68 $priceFieldParams = array(
69 'price_set_id' => $this->priceSetID
,
70 'name' => 'grassvariety',
71 'label' => 'Grass Variety',
72 'html_type' => 'Text',
76 $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
77 $this->priceFieldID
= $priceField['id'];
78 $this->_params
= array(
79 'price_field_id' => $this->priceFieldID
,
80 'name' => 'rye grass',
81 'label' => 'juicy and healthy',
83 'financial_type_id' => 1,
86 $membershipOrgId = $this->organizationCreate(NULL);
87 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
88 $priceSetParams1 = array(
90 'title' => 'Priceset with Multiple Terms',
93 'financial_type_id' => 2,
94 'is_quick_config' => 1,
97 $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetParams1);
98 $this->priceSetID1
= $price_set1['id'];
99 $priceFieldParams1 = array(
100 'price_set_id' => $this->priceSetID1
,
102 'label' => 'memtype',
103 'html_type' => 'Radio',
107 $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldParams1);
108 $this->priceFieldID1
= $priceField1['id'];
112 * Tear down function.
116 public function tearDown() {
117 $tablesToTruncate = array(
119 'civicrm_contribution',
121 $this->quickCleanup($tablesToTruncate);
122 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
123 $this->callAPISuccess('PriceField', 'delete', array(
124 'id' => $this->priceFieldID1
,
126 $this->callAPISuccess('PriceSet', 'delete', array(
127 'id' => $this->priceSetID1
,
129 $this->callAPISuccess('PriceField', 'delete', array(
130 'id' => $this->priceFieldID
,
132 $delete = $this->callAPISuccess('PriceSet', 'delete', array(
133 'id' => $this->priceSetID
,
136 $this->assertAPISuccess($delete);
139 public function testCreatePriceFieldValue() {
140 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
141 $this->assertAPISuccess($result);
142 $this->assertEquals(1, $result['count']);
143 $this->assertNotNull($result['values'][$result['id']]['id']);
144 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
147 public function testGetBasicPriceFieldValue() {
148 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
149 $this->id
= $createResult['id'];
150 $this->assertAPISuccess($createResult);
152 'name' => 'contribution_amount',
154 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
155 $this->assertEquals(1, $getResult['count']);
156 $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id']));
159 public function testDeletePriceFieldValue() {
160 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
161 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
162 $deleteParams = array('id' => $createResult['id']);
163 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
165 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
166 $this->assertEquals($startCount, $endCount);
169 public function testGetFieldsPriceFieldValue() {
170 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
171 $this->assertEquals(1, $result['values']['max_value']['type']);
174 public function testCreatePriceFieldValuewithMultipleTerms() {
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,
185 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
186 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
187 $this->assertEquals(1, $result['count']);
188 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result['id']));
191 public function testGetPriceFieldValuewithMultipleTerms() {
193 'price_field_id' => $this->priceFieldID1
,
194 'membership_type_id' => $this->_membershipTypeID
,
195 'name' => 'memType1',
196 'label' => 'memType1',
198 'membership_num_terms' => 2,
200 'financial_type_id' => 2,
203 'price_field_id' => $this->priceFieldID1
,
204 'membership_type_id' => $this->_membershipTypeID
,
205 'name' => 'memType2',
206 'label' => 'memType2',
208 'membership_num_terms' => 3,
210 'financial_type_id' => 2,
212 $result1 = $this->callAPISuccess($this->_entity
, 'create', $params1);
213 $result2 = $this->callAPISuccess($this->_entity
, 'create', $params2);
214 $result = $this->callAPISuccess($this->_entity
, 'get', array('price_field_id' => $this->priceFieldID1
));
215 $this->assertEquals(2, $result['count']);
216 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result1['id']));
217 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result2['id']));