3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
29 class api_v3_PriceFieldTest
extends CiviUnitTestCase
{
30 protected $_apiversion = 3;
33 protected $priceSetID = 0;
34 protected $_entity = 'price_field';
35 public $_eNoticeCompliant = TRUE;
36 public $DBResetRequired = TRUE;
38 public function setUp() {
40 // put stuff here that should happen before all tests in this unit
41 $priceSetparams = array(
43 'name' => 'default_goat_priceset',
44 'title' => 'Goat accomodation',
46 'help_pre' => "Where does your goat sleep",
47 'help_post' => "thank you for your time",
49 'financial_type_id' => 1,
50 'is_quick_config' => 1,
54 $price_set = $this->callAPISuccess('price_set', 'create',$priceSetparams);
55 $this->priceSetID
= $price_set['id'];
57 $this->_params
= array( 'price_set_id' => $this->priceSetID
,
58 'name' => 'grassvariety',
59 'label' => 'Grass Variety',
60 'html_type' => 'Text',
67 $tablesToTruncate = array(
69 'civicrm_contribution',
71 $this->quickCleanup($tablesToTruncate);
73 $delete = $this->callAPISuccess('PriceSet','delete', array(
74 'id' => $this->priceSetID
,
77 $this->assertAPISuccess($delete);
80 public function testCreatePriceField() {
81 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
82 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
83 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__
);
84 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
87 public function testGetBasicPriceField() {
88 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
89 $this->id
= $createResult['id'];
90 $this->assertAPISuccess($createResult);
92 'name' => 'contribution_amount',
94 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
95 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__
);
96 $this->callAPISuccess('price_field','delete', array('id' => $createResult['id']));
99 public function testDeletePriceField() {
100 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array( ));
101 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
102 $deleteParams = array('id' => $createResult['id']);
103 $deleteResult = $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
104 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__
);
105 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array( ));
106 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__
);
109 public function testGetFieldsPriceField() {
110 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
111 $this->assertEquals(1, $result['values']['options_per_line']['type']);