4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
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_PriceFieldTest
extends CiviUnitTestCase
{
31 protected $_apiversion = 3;
34 protected $priceSetID = 0;
35 protected $_entity = 'price_field';
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(
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 = civicrm_api('price_set', 'create',$priceSetparams);
57 $this->priceSetID
= $price_set['id'];
59 $this->_params
= array(
60 'version' => $this->_apiversion
,
61 'price_set_id' => $this->priceSetID
,
62 'name' => 'grassvariety',
63 'label' => 'Grass Variety',
64 'html_type' => 'Text',
71 $tablesToTruncate = array(
73 'civicrm_contribution',
75 $this->quickCleanup($tablesToTruncate);
77 $delete = civicrm_api('PriceSet','delete', array(
79 'id' => $this->priceSetID
,
82 $this->assertAPISuccess($delete);
85 public function testCreatePriceField() {
86 $result = civicrm_api($this->_entity
, 'create', $this->_params
);
87 $this->id
= $result['id'];
88 $this->documentMe($this->_params
, $result, __FUNCTION__
, __FILE__
);
89 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
90 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
91 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
92 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
95 public function testGetBasicPriceField() {
96 $createResult = civicrm_api($this->_entity
, 'create', $this->_params
);
97 $this->id
= $createResult['id'];
98 $this->assertAPISuccess($createResult);
100 'version' => $this->_apiversion
,
101 'name' => 'contribution_amount',
103 $getResult = civicrm_api($this->_entity
, 'get', $getParams);
104 $this->documentMe($getParams, $getResult, __FUNCTION__
, __FILE__
);
105 $this->assertAPISuccess($getResult, 'In line ' . __LINE__
);
106 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
107 civicrm_api('price_field','delete', array('version' => 3, 'id' => $createResult['id']));
110 public function testDeletePriceField() {
111 $startCount = civicrm_api($this->_entity
, 'getcount', array(
112 'version' => $this->_apiversion
,
114 $createResult = civicrm_api($this->_entity
, 'create', $this->_params
);
115 $deleteParams = array('version' => $this->_apiversion
, 'id' => $createResult['id']);
116 $deleteResult = civicrm_api($this->_entity
, 'delete', $deleteParams);
117 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__
, __FILE__
);
118 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__
);
119 $endCount = civicrm_api($this->_entity
, 'getcount', array(
120 'version' => $this->_apiversion
,
122 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__
);
125 public function testGetFieldsPriceField() {
126 $result = civicrm_api($this->_entity
, 'getfields', array('version' => $this->_apiversion
, 'action' => 'create'));
127 $this->assertAPISuccess($result, 'In line ' . __LINE__
);
128 $this->assertEquals(1, $result['values']['options_per_line']['type']);