3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
31 class api_v3_PriceFieldTest
extends CiviUnitTestCase
{
32 protected $_apiversion = 3;
35 protected $priceSetID = 0;
36 protected $_entity = 'price_field';
38 public $DBResetRequired = TRUE;
40 public function setUp() {
42 // put stuff here that should happen before all tests in this unit
43 $priceSetparams = array(
45 'name' => 'default_goat_priceset',
46 'title' => 'Goat accomodation',
48 'help_pre' => "Where does your goat sleep",
49 'help_post' => "thank you for your time",
51 'financial_type_id' => 1,
52 'is_quick_config' => 1,
56 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
57 $this->priceSetID
= $price_set['id'];
59 $this->_params
= array(
60 'price_set_id' => $this->priceSetID
,
61 'name' => 'grassvariety',
62 'label' => 'Grass Variety',
63 'html_type' => 'Text',
69 public function tearDown() {
70 $tablesToTruncate = array(
72 'civicrm_contribution',
74 $this->quickCleanup($tablesToTruncate);
76 $delete = $this->callAPISuccess('PriceSet', 'delete', array(
77 'id' => $this->priceSetID
,
80 $this->assertAPISuccess($delete);
83 public function testCreatePriceField() {
84 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
85 $this->assertEquals(1, $result['count']);
86 $this->assertNotNull($result['values'][$result['id']]['id']);
87 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
90 public function testGetBasicPriceField() {
91 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
92 $this->id
= $createResult['id'];
93 $this->assertAPISuccess($createResult);
95 'name' => 'contribution_amount',
97 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
98 $this->assertEquals(1, $getResult['count']);
99 $this->callAPISuccess('price_field', 'delete', array('id' => $createResult['id']));
102 public function testDeletePriceField() {
103 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
104 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
105 $deleteParams = array('id' => $createResult['id']);
106 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
107 $this->assertAPISuccess($deleteResult);
108 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
109 $this->assertEquals($startCount, $endCount);
112 public function testGetFieldsPriceField() {
113 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
114 $this->assertEquals(1, $result['values']['options_per_line']['type']);