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