3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
29 * Class api_v3_PriceSetTest
32 class api_v3_PriceSetTest
extends CiviUnitTestCase
{
33 protected $_apiversion = 3;
36 protected $contactIds = array();
37 protected $_entity = 'price_set';
39 public $DBResetRequired = TRUE;
44 public function setUp() {
46 $this->_params
= array(
47 'name' => 'default_goat_priceset',
48 'title' => 'Goat accessories',
50 'help_pre' => "Please describe your goat in detail",
51 'help_post' => "thank you for your time",
53 'financial_type_id' => 1,
54 'is_quick_config' => 1,
60 * Test create price set.
62 public function testCreatePriceSet() {
63 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
64 $this->assertEquals(1, $result['count']);
65 $this->assertNotNull($result['values'][$result['id']]['id']);
66 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
70 * Test for creating price sets used for both events and contributions.
72 public function testCreatePriceSetForEventAndContribution() {
73 // Create the price set
74 $createParams = array(
75 'name' => 'some_price_set',
76 'title' => 'Some Price Set',
78 'financial_type_id' => 1,
79 'extends' => array(1, 2),
81 $createResult = $this->callAPIAndDocument($this->_entity
, 'create', $createParams, __FUNCTION__
, __FILE__
);
83 // Get priceset we just created.
84 $result = $this->callAPISuccess($this->_entity
, 'getSingle', array(
85 'id' => $createResult['id'],
88 // Count the number of items in 'extends'.
89 $this->assertEquals(2, count($result['extends']));
93 * Check that no name doesn't cause failure.
95 public function testCreatePriceSetNoName() {
96 $params = $this->_params
;
97 unset($params['name']);
98 $this->callAPISuccess($this->_entity
, 'create', $params);
103 public function testGetBasicPriceSet() {
105 'name' => 'default_contribution_amount',
107 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
108 $this->assertEquals(1, $getResult['count']);
111 public function testEventPriceSet() {
112 $event = $this->callAPISuccess('event', 'create', array(
113 'title' => 'Event with Price Set',
114 'event_type_id' => 1,
116 'start_date' => 20151021,
117 'end_date' => 20151023,
120 $createParams = array(
121 'entity_table' => 'civicrm_event',
122 'entity_id' => $event['id'],
123 'name' => 'event price',
124 'title' => 'event price',
127 $createResult = $this->callAPIAndDocument($this->_entity
, 'create', $createParams, __FUNCTION__
, __FILE__
);
128 $result = $this->callAPISuccess($this->_entity
, 'get', array(
129 'id' => $createResult['id'],
131 $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']);
134 public function testDeletePriceSet() {
135 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
136 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
137 $deleteParams = array('id' => $createResult['id']);
138 $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
139 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
140 $this->assertEquals($startCount, $endCount);
143 public function testGetFieldsPriceSet() {
144 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
145 $this->assertEquals(16, $result['values']['is_quick_config']['type']);
148 public static function setUpBeforeClass() {
149 // put stuff here that should happen before all tests in this unit
152 public static function tearDownAfterClass() {
153 $tablesToTruncate = array(
155 'civicrm_contribution',
157 $unitTest = new CiviUnitTestCase();
158 $unitTest->quickCleanup($tablesToTruncate);