3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
31 class api_v3_PriceSetTest
extends CiviUnitTestCase
{
32 protected $_apiversion = 3;
35 protected $contactIds = array();
36 protected $_entity = 'price_set';
38 public $DBResetRequired = TRUE;
43 public function setUp() {
45 $this->_params
= array(
46 'name' => 'default_goat_priceset',
47 'title' => 'Goat accessories',
49 'help_pre' => "Please describe your goat in detail",
50 'help_post' => "thank you for your time",
52 'financial_type_id' => 1,
53 'is_quick_config' => 1,
58 public function tearDown() {
62 * Test create price set.
64 public function testCreatePriceSet() {
65 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
66 $this->assertEquals(1, $result['count']);
67 $this->assertNotNull($result['values'][$result['id']]['id']);
68 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
72 * Test for creating price sets used for both events and contributions.
74 public function testCreatePriceSetForEventAndContribution() {
75 // Create the price set
76 $createParams = array(
77 'name' => 'some_price_set',
78 'title' => 'Some Price Set',
80 'financial_type_id' => 1,
81 'extends' => array(1, 2),
83 $createResult = $this->callAPIAndDocument($this->_entity
, 'create', $createParams, __FUNCTION__
, __FILE__
);
85 // Get priceset we just created.
86 $result = $this->callAPISuccess($this->_entity
, 'getSingle', array(
87 'id' => $createResult['id'],
90 // Count the number of items in 'extends'.
91 $this->assertEquals(2, count($result['extends']));
95 * Check that no name doesn't cause failure.
97 public function testCreatePriceSetNoName() {
98 $params = $this->_params
;
99 unset($params['name']);
100 $this->callAPISuccess($this->_entity
, 'create', $params);
105 public function testGetBasicPriceSet() {
107 'name' => 'default_contribution_amount',
109 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
110 $this->assertEquals(1, $getResult['count']);
113 public function testEventPriceSet() {
114 $event = $this->callAPISuccess('event', 'create', array(
115 'title' => 'Event with Price Set',
116 'event_type_id' => 1,
118 'start_date' => 20151021,
119 'end_date' => 20151023,
122 $createParams = array(
123 'entity_table' => 'civicrm_event',
124 'entity_id' => $event['id'],
125 'name' => 'event price',
126 'title' => 'event price',
129 $createResult = $this->callAPIAndDocument($this->_entity
, 'create', $createParams, __FUNCTION__
, __FILE__
);
130 $result = $this->callAPISuccess($this->_entity
, 'get', array(
131 'id' => $createResult['id'],
133 $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']);
136 public function testDeletePriceSet() {
137 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
138 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
139 $deleteParams = array('id' => $createResult['id']);
140 $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
141 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', array());
142 $this->assertEquals($startCount, $endCount);
145 public function testGetFieldsPriceSet() {
146 $result = $this->callAPISuccess($this->_entity
, 'getfields', array('action' => 'create'));
147 $this->assertEquals(16, $result['values']['is_quick_config']['type']);
150 public static function setUpBeforeClass() {
151 // put stuff here that should happen before all tests in this unit
154 public static function tearDownAfterClass() {
155 $tablesToTruncate = array(
157 'civicrm_contribution',
159 $unitTest = new CiviUnitTestCase();
160 $unitTest->quickCleanup($tablesToTruncate);