4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
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(
44 'name' => 'default_goat_priceset',
45 'title' => 'Goat accomodation',
47 'help_pre' => "Where does your goat sleep",
48 'help_post' => "thank you for your time",
50 'financial_type_id' => 1,
51 'is_quick_config' => 1,
55 $price_set = $this->callAPISuccess('price_set', 'create',$priceSetparams);
56 $this->priceSetID
= $price_set['id'];
58 $priceFieldparams = array(
59 'price_set_id' => $this->priceSetID
,
60 'name' => 'grassvariety',
61 'label' => 'Grass Variety',
62 'html_type' => 'Text',
66 $priceField = $this->callAPISuccess('price_field','create', $priceFieldparams);
67 $this->priceFieldID
= $priceField['id'];
68 $this->_params
= array(
69 'price_field_id' => $this->priceFieldID
,
71 'label' => 'juicy and healthy',
75 $membershipOrgId = $this->organizationCreate(NULL);
76 $this->_membershipTypeID
= $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
77 $priceSetparams1 = array(
79 'title' => 'Priceset with Multiple Terms',
82 'financial_type_id' => 2,
83 'is_quick_config' => 1,
86 $price_set1 = $this->callAPISuccess('price_set', 'create',$priceSetparams1);
87 $this->priceSetID1
= $price_set1['id'];
88 $priceFieldparams1 = array(
89 'price_set_id' => $this->priceSetID1
,
92 'html_type' => 'Radio',
96 $priceField1 = $this->callAPISuccess('price_field','create', $priceFieldparams1);
97 $this->priceFieldID1
= $priceField1['id'];
100 function tearDown() {
101 $tablesToTruncate = array(
103 'civicrm_contribution',
105 $this->quickCleanup($tablesToTruncate);
106 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
107 $this->callAPISuccess('PriceField','delete', array(
108 'id' => $this->priceFieldID1
,
110 $this->callAPISuccess('PriceSet','delete', array(
111 'id' => $this->priceSetID1
,
113 $this->callAPISuccess('PriceField','delete', array(
114 'id' => $this->priceFieldID
,
116 $delete = $this->callAPISuccess('PriceSet','delete', array(
117 'id' => $this->priceSetID
,
120 $this->assertAPISuccess($delete);
123 public function testCreatePriceFieldValue() {
124 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
125 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
126 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
127 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
128 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
131 public function testGetBasicPriceFieldValue() {
132 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
133 $this->id
= $createResult['id'];
134 $this->assertAPISuccess($createResult);
136 'name' => 'contribution_amount',
138 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
139 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
140 $this->callAPISuccess('price_field_value','delete', array('id' => $createResult['id']));
143 public function testDeletePriceFieldValue() {
144 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
145 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
146 $deleteParams = array('id' => $createResult['id']);
147 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
149 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
150 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__
);
153 public function testGetFieldsPriceFieldValue() {
154 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
155 $this->assertEquals(1, $result['values']['max_value']['type']);
158 public function testCreatePriceFieldValuewithMultipleTerms() {
160 'price_field_id' => $this->priceFieldID1
,
161 'membership_type_id' => $this->_membershipTypeID
,
162 'name' => 'memType1',
163 'label' => 'memType1',
165 'membership_num_terms' => 2,
167 'financial_type_id' => 2,
169 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
170 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
171 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
172 $this->callAPISuccess($this->_entity
, 'delete', array('id' => $result['id']));
174 public function testGetPriceFieldValuewithMultipleTerms() {
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,
186 'price_field_id' => $this->priceFieldID1
,
187 'membership_type_id' => $this->_membershipTypeID
,
188 'name' => 'memType2',
189 'label' => 'memType2',
191 'membership_num_terms' => 3,
193 'financial_type_id' => 2,
195 $result1 = $this->callAPISuccess($this->_entity
, 'create', $params1);
196 $result2 = $this->callAPISuccess($this->_entity
, 'create', $params2);
197 $result = $this->callAPISuccess($this->_entity
, 'get', array('price_field_id' =>$this->priceFieldID1
));
198 $this->assertEquals(2, $result['count'], 'In line ' . __LINE__
);
199 $this->callAPISuccess($this->_entity
,'delete', array('id' => $result1['id']));
200 $this->callAPISuccess($this->_entity
,'delete', array('id' => $result2['id']));