4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Class api_v3_PriceFieldValueTest
34 class api_v3_PriceFieldValueTest
extends CiviUnitTestCase
{
35 protected $_apiversion = 3;
38 protected $priceSetID = 0;
39 protected $_entity = 'price_field_value';
41 public $DBResetRequired = TRUE;
43 public function setUp() {
45 // put stuff here that should happen before all tests in this unit
46 $priceSetparams = array(
48 'name' => 'default_goat_priceset',
49 'title' => 'Goat accomodation',
51 'help_pre' => "Where does your goat sleep",
52 'help_post' => "thank you for your time",
54 'financial_type_id' => 1,
55 'is_quick_config' => 1,
59 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
60 $this->priceSetID
= $price_set['id'];
62 $priceFieldparams = array(
63 'price_set_id' => $this->priceSetID
,
64 'name' => 'grassvariety',
65 'label' => 'Grass Variety',
66 'html_type' => 'Text',
70 $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldparams);
71 $this->priceFieldID
= $priceField['id'];
72 $this->_params
= array(
73 'price_field_id' => $this->priceFieldID
,
75 'label' => 'juicy and healthy',
79 $membershipOrgId = $this->organizationCreate(NULL);
80 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
81 $priceSetparams1 = array(
83 'title' => 'Priceset with Multiple Terms',
86 'financial_type_id' => 2,
87 'is_quick_config' => 1,
90 $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetparams1);
91 $this->priceSetID1
= $price_set1['id'];
92 $priceFieldparams1 = array(
93 'price_set_id' => $this->priceSetID1
,
96 'html_type' => 'Radio',
100 $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldparams1);
101 $this->priceFieldID1
= $priceField1['id'];
104 public function tearDown() {
105 $tablesToTruncate = array(
107 'civicrm_contribution',
109 $this->quickCleanup($tablesToTruncate);
110 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
111 $this->callAPISuccess('PriceField', 'delete', array(
112 'id' => $this->priceFieldID1
,
114 $this->callAPISuccess('PriceSet', 'delete', array(
115 'id' => $this->priceSetID1
,
117 $this->callAPISuccess('PriceField', 'delete', array(
118 'id' => $this->priceFieldID
,
120 $delete = $this->callAPISuccess('PriceSet', 'delete', array(
121 'id' => $this->priceSetID
,
124 $this->assertAPISuccess($delete);
127 public function testCreatePriceFieldValue() {
128 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
129 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
130 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
131 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
132 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
135 public function testGetBasicPriceFieldValue() {
136 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
137 $this->id
= $createResult['id'];
138 $this->assertAPISuccess($createResult);
140 'name' => 'contribution_amount',
142 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
143 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
144 $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id']));
147 public function testDeletePriceFieldValue() {
148 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
149 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
150 $deleteParams = array('id' => $createResult['id']);
151 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
153 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
154 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__
);
157 public function testGetFieldsPriceFieldValue() {
158 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
159 $this->assertEquals(1, $result['values']['max_value']['type']);
162 public function testCreatePriceFieldValuewithMultipleTerms() {
164 'price_field_id' => $this->priceFieldID1
,
165 'membership_type_id' => $this->_membershipTypeID
,
166 'name' => 'memType1',
167 'label' => 'memType1',
169 'membership_num_terms' => 2,
171 'financial_type_id' => 2,
173 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
174 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
175 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
176 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result['id']));
179 public function testGetPriceFieldValuewithMultipleTerms() {
181 'price_field_id' => $this->priceFieldID1
,
182 'membership_type_id' => $this->_membershipTypeID
,
183 'name' => 'memType1',
184 'label' => 'memType1',
186 'membership_num_terms' => 2,
188 'financial_type_id' => 2,
191 'price_field_id' => $this->priceFieldID1
,
192 'membership_type_id' => $this->_membershipTypeID
,
193 'name' => 'memType2',
194 'label' => 'memType2',
196 'membership_num_terms' => 3,
198 'financial_type_id' => 2,
200 $result1 = $this->callAPISuccess($this->_entity
, 'create', $params1);
201 $result2 = $this->callAPISuccess($this->_entity
, 'create', $params2);
202 $result = $this->callAPISuccess($this->_entity
, 'get', array('price_field_id' => $this->priceFieldID1
));
203 $this->assertEquals(2, $result['count'], 'In line ' . __LINE__
);
204 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result1['id']));
205 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result2['id']));