4 require_once 'CiviTest/CiviUnitTestCase.php';
5 class api_v3_PriceFieldValueTest
extends CiviUnitTestCase
{
6 protected $_apiversion = 3;
9 protected $priceSetID = 0;
10 protected $_entity = 'price_field_value';
11 public $_eNoticeCompliant = TRUE;
12 public $DBResetRequired = TRUE;
14 public function setUp() {
16 // put stuff here that should happen before all tests in this unit
17 $priceSetparams = array(
20 'name' => 'default_goat_priceset',
21 'title' => 'Goat accomodation',
23 'help_pre' => "Where does your goat sleep",
24 'help_post' => "thank you for your time",
26 'financial_type_id' => 1,
27 'is_quick_config' => 1,
31 $price_set = civicrm_api('price_set', 'create',$priceSetparams);
32 $this->priceSetID
= $price_set['id'];
34 $priceFieldparams = array(
35 'version' => $this->_apiversion
,
36 'price_set_id' => $this->priceSetID
,
37 'name' => 'grassvariety',
38 'label' => 'Grass Variety',
39 'html_type' => 'Text',
43 $priceField = civicrm_api('price_field','create', $priceFieldparams);
44 $this->priceFieldID
= $priceField['id'];
45 $this->_params
= array(
47 'price_field_id' => $this->priceFieldID
,
49 'label' => 'juicy and healthy',
53 $membershipOrgId = $this->organizationCreate(NULL);
54 $this->_membershipTypeID
= $this->membershipTypeCreate($membershipOrgId);
55 $priceSetparams1 = array(
56 'version' => $this->_apiversion
,
58 'title' => 'Priceset with Multiple Terms',
61 'financial_type_id' => 2,
62 'is_quick_config' => 1,
65 $price_set1 = civicrm_api('price_set', 'create',$priceSetparams1);
66 $this->priceSetID1
= $price_set1['id'];
67 $priceFieldparams1 = array(
68 'version' => $this->_apiversion
,
69 'price_set_id' => $this->priceSetID1
,
72 'html_type' => 'Radio',
76 $priceField1 = civicrm_api('price_field','create', $priceFieldparams1);
77 $this->priceFieldID1
= $priceField1['id'];
81 $tablesToTruncate = array(
83 'civicrm_contribution',
85 $this->quickCleanup($tablesToTruncate);
86 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID
));
87 civicrm_api('PriceField','delete', array(
89 'id' => $this->priceFieldID1
,
91 civicrm_api('PriceSet','delete', array(
93 'id' => $this->priceSetID1
,
95 civicrm_api('PriceField','delete', array(
97 'id' => $this->priceFieldID
,
99 $delete = civicrm_api('PriceSet','delete', array(
101 'id' => $this->priceSetID
,
104 $this->assertAPISuccess($delete);
107 public function testCreatePriceFieldValue() {
108 $result = civicrm_api($this->_entity
, 'create', $this->_params
);
109 $this->id
= $result['id'];
110 $this->documentMe($this->_params
, $result, __FUNCTION__
, __FILE__
);
111 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
112 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
113 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
114 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
117 public function testGetBasicPriceFieldValue() {
118 $createResult = civicrm_api($this->_entity
, 'create', $this->_params
);
119 $this->id
= $createResult['id'];
120 $this->assertAPISuccess($createResult);
122 'version' => $this->_apiversion
,
123 'name' => 'contribution_amount',
125 $getResult = civicrm_api($this->_entity
, 'get', $getParams);
126 $this->documentMe($getParams, $getResult, __FUNCTION__
, __FILE__
);
127 $this->assertAPISuccess($getResult, 'In line ' . __LINE__
);
128 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
129 civicrm_api('price_field_value','delete', array('version' => 3, 'id' => $createResult['id']));
132 public function testDeletePriceFieldValue() {
133 $startCount = civicrm_api($this->_entity
, 'getcount', array(
134 'version' => $this->_apiversion
,
136 $createResult = civicrm_api($this->_entity
, 'create', $this->_params
);
137 $deleteParams = array('version' => $this->_apiversion
, 'id' => $createResult['id']);
138 $deleteResult = civicrm_api($this->_entity
, 'delete', $deleteParams);
139 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__
, __FILE__
);
140 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__
);
141 $endCount = civicrm_api($this->_entity
, 'getcount', array(
142 'version' => $this->_apiversion
,
144 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__
);
147 public function testGetFieldsPriceFieldValue() {
148 $result = civicrm_api($this->_entity
, 'getfields', array('version' => $this->_apiversion
, 'action' => 'create'));
149 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
150 $this->assertEquals(1, $result['values']['max_value']['type']);
153 public function testCreatePriceFieldValuewithMultipleTerms() {
156 'price_field_id' => $this->priceFieldID1
,
157 'membership_type_id' => $this->_membershipTypeID
,
158 'name' => 'memType1',
159 'label' => 'memType1',
161 'membership_num_terms' => 2,
163 'financial_type_id' => 2,
165 $result = civicrm_api($this->_entity
, 'create', $params);
166 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
167 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
168 $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
169 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
170 civicrm_api($this->_entity
, 'delete', array('version' => 3, 'id' => $result['id']));
172 public function testGetPriceFieldValuewithMultipleTerms() {
175 'price_field_id' => $this->priceFieldID1
,
176 'membership_type_id' => $this->_membershipTypeID
,
177 'name' => 'memType1',
178 'label' => 'memType1',
180 'membership_num_terms' => 2,
182 '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 = civicrm_api($this->_entity
, 'create', $params1);
196 $result2 = civicrm_api($this->_entity
, 'create', $params2);
197 $result = civicrm_api($this->_entity
, 'get', array( 'version' => 3, 'price_field_id' =>$this->priceFieldID1
));
198 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
199 $this->assertEquals(2, $result['count'], 'In line ' . __LINE__
);
200 civicrm_api($this->_entity
,'delete', array('version' => 3, 'id' => $result1['id']));
201 civicrm_api($this->_entity
,'delete', array('version' => 3, 'id' => $result2['id']));