Merge pull request #2006 from civicrm/4.3
[civicrm-core.git] / tests / phpunit / api / v3 / PriceFieldTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 require_once 'CiviTest/CiviUnitTestCase.php';
29 class api_v3_PriceFieldTest extends CiviUnitTestCase {
30 protected $_apiversion = 3;
31 protected $_params;
32 protected $id = 0;
33 protected $priceSetID = 0;
34 protected $_entity = 'price_field';
35 public $_eNoticeCompliant = TRUE;
36 public $DBResetRequired = TRUE;
37
38 public function setUp() {
39 parent::setUp();
40 // put stuff here that should happen before all tests in this unit
41 $priceSetparams = array(
42 # [domain_id] =>
43 'name' => 'default_goat_priceset',
44 'title' => 'Goat accomodation',
45 'is_active' => 1,
46 'help_pre' => "Where does your goat sleep",
47 'help_post' => "thank you for your time",
48 'extends' => 2,
49 'financial_type_id' => 1,
50 'is_quick_config' => 1,
51 'is_reserved' => 1,
52 );
53
54 $price_set = $this->callAPISuccess('price_set', 'create',$priceSetparams);
55 $this->priceSetID = $price_set['id'];
56
57 $this->_params = array( 'price_set_id' => $this->priceSetID,
58 'name' => 'grassvariety',
59 'label' => 'Grass Variety',
60 'html_type' => 'Text',
61 'is_enter_qty' => 1,
62 'is_active' => 1,
63 );
64 }
65
66 function tearDown() {
67 $tablesToTruncate = array(
68 'civicrm_contact',
69 'civicrm_contribution',
70 );
71 $this->quickCleanup($tablesToTruncate);
72
73 $delete = $this->callAPISuccess('PriceSet','delete', array(
74 'id' => $this->priceSetID,
75 ));
76
77 $this->assertAPISuccess($delete);
78 }
79
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);
85 }
86
87 public function testGetBasicPriceField() {
88 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
89 $this->id = $createResult['id'];
90 $this->assertAPISuccess($createResult);
91 $getParams = array(
92 'name' => 'contribution_amount',
93 );
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']));
97 }
98
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__);
107 }
108
109 public function testGetFieldsPriceField() {
110 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
111 $this->assertEquals(1, $result['values']['options_per_line']['type']);
112 }
113
114 }
115