tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / api / v3 / PriceFieldTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
81621fee 4| CiviCRM version 4.7 |
b6708aeb 5+--------------------------------------------------------------------+
e7112fa7 6| Copyright CiviCRM LLC (c) 2004-2015 |
b6708aeb 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+--------------------------------------------------------------------+
e70a7fc0 26 */
6a488035 27
e9479dcf
EM
28/**
29 * Class api_v3_PriceFieldTest
30 */
6a488035
TO
31class 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';
b7c9bc4c 37
6a488035
TO
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(
92915c55 44 # [domain_id] =>
6a488035
TO
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
6c6e6187 56 $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
6a488035
TO
57 $this->priceSetID = $price_set['id'];
58
6c6e6187 59 $this->_params = array(
92915c55 60 'price_set_id' => $this->priceSetID,
6a488035
TO
61 'name' => 'grassvariety',
62 'label' => 'Grass Variety',
63 'html_type' => 'Text',
64 'is_enter_qty' => 1,
65 'is_active' => 1,
66 );
67 }
68
00be9182 69 public function tearDown() {
6a488035 70 $tablesToTruncate = array(
92915c55
TO
71 'civicrm_contact',
72 'civicrm_contribution',
6a488035
TO
73 );
74 $this->quickCleanup($tablesToTruncate);
75
6c6e6187 76 $delete = $this->callAPISuccess('PriceSet', 'delete', array(
92915c55 77 'id' => $this->priceSetID,
6a488035
TO
78 ));
79
80 $this->assertAPISuccess($delete);
81 }
82
83 public function testCreatePriceField() {
7fbb4198 84 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
ba4a1892
TM
85 $this->assertEquals(1, $result['count']);
86 $this->assertNotNull($result['values'][$result['id']]['id']);
6a488035
TO
87 $this->getAndCheck($this->_params, $result['id'], $this->_entity);
88 }
89
90 public function testGetBasicPriceField() {
7fbb4198 91 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
6a488035
TO
92 $this->id = $createResult['id'];
93 $this->assertAPISuccess($createResult);
94 $getParams = array(
6a488035
TO
95 'name' => 'contribution_amount',
96 );
7fbb4198 97 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
ba4a1892 98 $this->assertEquals(1, $getResult['count']);
6c6e6187 99 $this->callAPISuccess('price_field', 'delete', array('id' => $createResult['id']));
6a488035
TO
100 }
101
102 public function testDeletePriceField() {
6c6e6187 103 $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
7fbb4198 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__);
a15773db 107 $this->assertAPISuccess($deleteResult);
6c6e6187 108 $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
a15773db 109 $this->assertEquals($startCount, $endCount);
6a488035
TO
110 }
111
112 public function testGetFieldsPriceField() {
7fbb4198 113 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
6a488035
TO
114 $this->assertEquals(1, $result['values']['options_per_line']['type']);
115 }
116
117}