4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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';
30 class api_v3_PriceFieldValueTest
extends CiviUnitTestCase
{
31 protected $_apiversion = 3;
34 protected $priceSetID = 0;
35 protected $_entity = 'price_field_value';
36 public $_eNoticeCompliant = TRUE;
37 public $DBResetRequired = TRUE;
39 public function setUp() {
41 // put stuff here that should happen before all tests in this unit
42 $priceSetparams = array(
45 'name' => 'default_goat_priceset',
46 'title' => 'Goat accomodation',
48 'help_pre' => "Where does your goat sleep",
49 'help_post' => "thank you for your time",
51 'financial_type_id' => 1,
52 'is_quick_config' => 1,
56 $price_set = civicrm_api('price_set', 'create',$priceSetparams);
57 $this->priceSetID
= $price_set['id'];
59 $priceFieldparams = array(
60 'version' => $this->_apiversion
,
61 'price_set_id' => $this->priceSetID
,
62 'name' => 'grassvariety',
63 'label' => 'Grass Variety',
64 'html_type' => 'Text',
68 $priceField = civicrm_api('price_field','create', $priceFieldparams);
69 $this->priceFieldID
= $priceField['id'];
70 $this->_params
= array(
72 'price_field_id' => $this->priceFieldID
,
74 'label' => 'juicy and healthy',
78 $membershipOrgId = $this->organizationCreate(NULL);
79 $this->_membershipTypeID
= $this->membershipTypeCreate($membershipOrgId);
80 $priceSetparams1 = array(
81 'version' => $this->_apiversion
,
83 'title' => 'Priceset with Multiple Terms',
86 'financial_type_id' => 2,
87 'is_quick_config' => 1,
90 $price_set1 = civicrm_api('price_set', 'create',$priceSetparams1);
91 $this->priceSetID1
= $price_set1['id'];
92 $priceFieldparams1 = array(
93 'version' => $this->_apiversion
,
94 'price_set_id' => $this->priceSetID1
,
97 'html_type' => 'Radio',
101 $priceField1 = civicrm_api('price_field','create', $priceFieldparams1);
102 $this->priceFieldID1
= $priceField1['id'];
105 function tearDown() {
106 $tablesToTruncate = array(
108 'civicrm_contribution',
110 $this->quickCleanup($tablesToTruncate);
111 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
112 civicrm_api('PriceField','delete', array(
114 'id' => $this->priceFieldID1
,
116 civicrm_api('PriceSet','delete', array(
118 'id' => $this->priceSetID1
,
120 civicrm_api('PriceField','delete', array(
122 'id' => $this->priceFieldID
,
124 $delete = civicrm_api('PriceSet','delete', array(
126 'id' => $this->priceSetID
,
129 $this->assertAPISuccess($delete);
132 public function testCreatePriceFieldValue() {
133 $result = civicrm_api($this->_entity
, 'create', $this->_params
);
134 $this->id
= $result['id'];
135 $this->documentMe($this->_params
, $result, __FUNCTION__
, __FILE__
);
136 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
137 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
138 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
139 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
142 public function testGetBasicPriceFieldValue() {
143 $createResult = civicrm_api($this->_entity
, 'create', $this->_params
);
144 $this->id
= $createResult['id'];
145 $this->assertAPISuccess($createResult);
147 'version' => $this->_apiversion
,
148 'name' => 'contribution_amount',
150 $getResult = civicrm_api($this->_entity
, 'get', $getParams);
151 $this->documentMe($getParams, $getResult, __FUNCTION__
, __FILE__
);
152 $this->assertAPISuccess($getResult, 'In line ' . __LINE__
);
153 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
154 civicrm_api('price_field_value','delete', array('version' => 3, 'id' => $createResult['id']));
157 public function testDeletePriceFieldValue() {
158 $startCount = civicrm_api($this->_entity
, 'getcount', array(
159 'version' => $this->_apiversion
,
161 $createResult = civicrm_api($this->_entity
, 'create', $this->_params
);
162 $deleteParams = array('version' => $this->_apiversion
, 'id' => $createResult['id']);
163 $deleteResult = civicrm_api($this->_entity
, 'delete', $deleteParams);
164 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__
, __FILE__
);
165 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__
);
166 $endCount = civicrm_api($this->_entity
, 'getcount', array(
167 'version' => $this->_apiversion
,
169 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__
);
172 public function testGetFieldsPriceFieldValue() {
173 $result = civicrm_api($this->_entity
, 'getfields', array('version' => $this->_apiversion
, 'action' => 'create'));
174 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
175 $this->assertEquals(1, $result['values']['max_value']['type']);
178 public function testCreatePriceFieldValuewithMultipleTerms() {
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,
190 $result = civicrm_api($this->_entity
, 'create', $params);
191 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
192 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
193 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
194 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
195 civicrm_api($this->_entity
, 'delete', array('version' => 3, 'id' => $result['id']));
197 public function testGetPriceFieldValuewithMultipleTerms() {
200 'price_field_id' => $this->priceFieldID1
,
201 'membership_type_id' => $this->_membershipTypeID
,
202 'name' => 'memType1',
203 'label' => 'memType1',
205 'membership_num_terms' => 2,
207 'financial_type_id' => 2,
211 'price_field_id' => $this->priceFieldID1
,
212 'membership_type_id' => $this->_membershipTypeID
,
213 'name' => 'memType2',
214 'label' => 'memType2',
216 'membership_num_terms' => 3,
218 'financial_type_id' => 2,
220 $result1 = civicrm_api($this->_entity
, 'create', $params1);
221 $result2 = civicrm_api($this->_entity
, 'create', $params2);
222 $result = civicrm_api($this->_entity
, 'get', array( 'version' => 3, 'price_field_id' =>$this->priceFieldID1
));
223 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
224 $this->assertEquals(2, $result['count'], 'In line ' . __LINE__
);
225 civicrm_api($this->_entity
,'delete', array('version' => 3, 'id' => $result1['id']));
226 civicrm_api($this->_entity
,'delete', array('version' => 3, 'id' => $result2['id']));