3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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;
42 public function setUp() {
44 // put stuff here that should happen before all tests in this unit
45 $priceSetparams = array(
47 'name' => 'default_goat_priceset',
48 'title' => 'Goat accomodation',
50 'help_pre' => "Where does your goat sleep",
51 'help_post' => "thank you for your time",
53 'financial_type_id' => 1,
54 'is_quick_config' => 1,
58 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
59 $this->priceSetID
= $price_set['id'];
61 $priceFieldparams = array(
62 'price_set_id' => $this->priceSetID
,
63 'name' => 'grassvariety',
64 'label' => 'Grass Variety',
65 'html_type' => 'Text',
69 $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldparams);
70 $this->priceFieldID
= $priceField['id'];
71 $this->_params
= array(
72 'price_field_id' => $this->priceFieldID
,
74 'label' => 'juicy and healthy',
78 $membershipOrgId = $this->organizationCreate(NULL);
79 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
80 $priceSetparams1 = array(
82 'title' => 'Priceset with Multiple Terms',
85 'financial_type_id' => 2,
86 'is_quick_config' => 1,
89 $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetparams1);
90 $this->priceSetID1
= $price_set1['id'];
91 $priceFieldparams1 = array(
92 'price_set_id' => $this->priceSetID1
,
95 'html_type' => 'Radio',
99 $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldparams1);
100 $this->priceFieldID1
= $priceField1['id'];
103 public function tearDown() {
104 $tablesToTruncate = array(
106 'civicrm_contribution',
108 $this->quickCleanup($tablesToTruncate);
109 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
110 $this->callAPISuccess('PriceField', 'delete', array(
111 'id' => $this->priceFieldID1
,
113 $this->callAPISuccess('PriceSet', 'delete', array(
114 'id' => $this->priceSetID1
,
116 $this->callAPISuccess('PriceField', 'delete', array(
117 'id' => $this->priceFieldID
,
119 $delete = $this->callAPISuccess('PriceSet', 'delete', array(
120 'id' => $this->priceSetID
,
123 $this->assertAPISuccess($delete);
126 public function testCreatePriceFieldValue() {
127 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
128 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
129 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
130 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
131 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
134 public function testGetBasicPriceFieldValue() {
135 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
136 $this->id
= $createResult['id'];
137 $this->assertAPISuccess($createResult);
139 'name' => 'contribution_amount',
141 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
142 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
143 $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id']));
146 public function testDeletePriceFieldValue() {
147 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
148 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
149 $deleteParams = array('id' => $createResult['id']);
150 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
152 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
153 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__
);
156 public function testGetFieldsPriceFieldValue() {
157 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
158 $this->assertEquals(1, $result['values']['max_value']['type']);
161 public function testCreatePriceFieldValuewithMultipleTerms() {
163 'price_field_id' => $this->priceFieldID1
,
164 'membership_type_id' => $this->_membershipTypeID
,
165 'name' => 'memType1',
166 'label' => 'memType1',
168 'membership_num_terms' => 2,
170 'financial_type_id' => 2,
172 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
173 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
174 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
175 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result['id']));
178 public function testGetPriceFieldValuewithMultipleTerms() {
180 'price_field_id' => $this->priceFieldID1
,
181 'membership_type_id' => $this->_membershipTypeID
,
182 'name' => 'memType1',
183 'label' => 'memType1',
185 'membership_num_terms' => 2,
187 'financial_type_id' => 2,
190 'price_field_id' => $this->priceFieldID1
,
191 'membership_type_id' => $this->_membershipTypeID
,
192 'name' => 'memType2',
193 'label' => 'memType2',
195 'membership_num_terms' => 3,
197 'financial_type_id' => 2,
199 $result1 = $this->callAPISuccess($this->_entity
, 'create', $params1);
200 $result2 = $this->callAPISuccess($this->_entity
, 'create', $params2);
201 $result = $this->callAPISuccess($this->_entity
, 'get', array('price_field_id' => $this->priceFieldID1
));
202 $this->assertEquals(2, $result['count'], 'In line ' . __LINE__
);
203 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result1['id']));
204 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result2['id']));