3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
29 * Class api_v3_PriceFieldTest
32 class api_v3_PriceFieldTest
extends CiviUnitTestCase
{
33 protected $_apiversion = 3;
36 protected $priceSetID = 0;
37 protected $_entity = 'price_field';
39 public $DBResetRequired = TRUE;
41 public function setUp() {
43 // put stuff here that should happen before all tests in this unit
46 'name' => 'default_goat_priceset',
47 'title' => 'Goat accomodation',
49 'help_pre' => "Where does your goat sleep",
50 'help_post' => "thank you for your time",
52 'financial_type_id' => 1,
53 'is_quick_config' => 1,
57 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
58 $this->priceSetID
= $price_set['id'];
61 'price_set_id' => $this->priceSetID
,
62 'name' => 'grassvariety',
63 'label' => 'Grass Variety',
64 'html_type' => 'Text',
70 public function tearDown() {
73 'civicrm_contribution',
75 $this->quickCleanup($tablesToTruncate);
77 $delete = $this->callAPISuccess('PriceSet', 'delete', [
78 'id' => $this->priceSetID
,
81 $this->assertAPISuccess($delete);
85 public function testCreatePriceField() {
86 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
87 $this->assertEquals(1, $result['count']);
88 $this->assertNotNull($result['values'][$result['id']]['id']);
89 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
92 public function testGetBasicPriceField() {
93 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
94 $this->id
= $createResult['id'];
95 $this->assertAPISuccess($createResult);
97 'name' => 'contribution_amount',
99 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
100 $this->assertEquals(1, $getResult['count']);
101 $this->callAPISuccess('price_field', 'delete', ['id' => $createResult['id']]);
104 public function testDeletePriceField() {
105 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
106 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
107 $deleteParams = ['id' => $createResult['id']];
108 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
109 $this->assertAPISuccess($deleteResult);
110 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
111 $this->assertEquals($startCount, $endCount);
114 public function testGetFieldsPriceField() {
115 $result = $this->callAPISuccess($this->_entity
, 'getfields', ['action' => 'create']);
116 $this->assertEquals(1, $result['values']['options_per_line']['type']);
121 * Test updating the label of a texte price field and ensure price field value label is also updated
123 public function testUpdatePriceFieldLabel() {
124 $field = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
125 $this->callAPISuccess('price_field_value', 'create', [
126 'price_field_id' => $field['id'],
127 'name' => 'rye grass',
128 'label' => 'juicy and healthy',
130 'financial_type_id' => 1,
132 $priceField = $this->callAPISuccess($this->_entity
, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']);
133 $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]);
134 $this->assertEquals($priceField['values'][$priceField['id']]['label'], $priceFieldValue['values'][$priceFieldValue['id']]['label']);
135 $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]);
136 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $field['id']]);
141 * Confirm value label only updates if fiedl type is html.
143 public function testUpdatePriceFieldLabelNotUpdateField() {
144 $field = $this->callAPISuccess($this->_entity
, 'create', array_merge($this->_params
, ['html_type' => 'Radio']));
145 $this->callAPISuccess('price_field_value', 'create', [
146 'price_field_id' => $field['id'],
147 'name' => 'rye grass',
148 'label' => 'juicy and healthy',
150 'financial_type_id' => 1,
152 $priceField = $this->callAPISuccess($this->_entity
, 'create', ['id' => $field['id'], 'label' => 'Rose Variety']);
153 $priceFieldValue = $this->callAPISuccess('price_field_value', 'get', ['price_field_id' => $field['id']]);
154 $this->assertEquals('juicy and healthy', $priceFieldValue['values'][$priceFieldValue['id']]['label']);
155 $this->callAPISuccess('price_field_value', 'delete', ['id' => $priceFieldValue['id']]);
156 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $field['id']]);