3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class api_v3_PriceFieldTest
16 class api_v3_PriceFieldTest
extends CiviUnitTestCase
{
17 protected $_apiversion = 3;
20 protected $priceSetID = 0;
21 protected $_entity = 'price_field';
23 public $DBResetRequired = TRUE;
25 public function setUp() {
27 // put stuff here that should happen before all tests in this unit
30 'name' => 'default_goat_priceset',
31 'title' => 'Goat accomodation',
33 'help_pre' => "Where does your goat sleep",
34 'help_post' => "thank you for your time",
36 'financial_type_id' => 1,
37 'is_quick_config' => 1,
41 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
42 $this->priceSetID
= $price_set['id'];
45 'price_set_id' => $this->priceSetID
,
46 'name' => 'grassvariety',
47 'label' => 'Grass Variety',
48 'html_type' => 'Text',
54 public function tearDown() {
57 'civicrm_contribution',
59 $this->quickCleanup($tablesToTruncate);
61 $delete = $this->callAPISuccess('PriceSet', 'delete', [
62 'id' => $this->priceSetID
,
65 $this->assertAPISuccess($delete);
69 public function testCreatePriceField() {
70 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
71 $this->assertEquals(1, $result['count']);
72 $this->assertNotNull($result['values'][$result['id']]['id']);
73 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
76 public function testGetBasicPriceField() {
77 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
78 $this->id
= $createResult['id'];
79 $this->assertAPISuccess($createResult);
81 'name' => 'contribution_amount',
83 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
84 $this->assertEquals(1, $getResult['count']);
85 $this->callAPISuccess('price_field', 'delete', ['id' => $createResult['id']]);
88 public function testDeletePriceField() {
89 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
90 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
91 $deleteParams = ['id' => $createResult['id']];
92 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
93 $this->assertAPISuccess($deleteResult);
94 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
95 $this->assertEquals($startCount, $endCount);
98 public function testGetFieldsPriceField() {
99 $result = $this->callAPISuccess($this->_entity
, 'getfields', ['action' => 'create']);
100 $this->assertEquals(1, $result['values']['options_per_line']['type']);
105 * Test updating the label of a texte price field and ensure price field value label is also updated
107 public function testUpdatePriceFieldLabel() {
108 $field = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
109 $this->callAPISuccess('price_field_value', 'create', [
110 'price_field_id' => $field['id'],
111 'name' => 'rye grass',
112 'label' => 'juicy and healthy',
114 'financial_type_id' => 1,
116 $priceField = $this->callAPISuccess($this->_entity
, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']);
117 $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]);
118 $this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']);
119 $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]);
120 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $field['id']]);
125 * Confirm value label only updates if fiedl type is html.
127 public function testUpdatePriceFieldLabelNotUpdateField() {
128 $field = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, ['html_type' => 'Radio']));
129 $this->callAPISuccess('price_field_value', 'create', [
130 'price_field_id' => $field['id'],
131 'name' => 'rye grass',
132 'label' => 'juicy and healthy',
134 'financial_type_id' => 1,
136 $priceField = $this->callAPISuccess($this->_entity
, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']);
137 $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]);
138 $this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']);
139 $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]);
140 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $field['id']]);