3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class api_v3_PriceSetTest
16 class api_v3_PriceSetTest
extends CiviUnitTestCase
{
17 protected $_apiversion = 3;
20 protected $contactIds = [];
21 protected $_entity = 'price_set';
23 public $DBResetRequired = TRUE;
28 public function setUp() {
31 'name' => 'default_goat_priceset',
32 'title' => 'Goat accessories',
34 'help_pre' => "Please describe your goat in detail",
35 'help_post' => "thank you for your time",
37 'financial_type_id' => 1,
38 'is_quick_config' => 1,
44 * Test create price set.
46 public function testCreatePriceSet() {
47 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
48 $this->assertEquals(1, $result['count']);
49 $this->assertNotNull($result['values'][$result['id']]['id']);
50 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
54 * Test for creating price sets used for both events and contributions.
56 public function testCreatePriceSetForEventAndContribution() {
57 // Create the price set
59 'name' => 'some_price_set',
60 'title' => 'Some Price Set',
62 'financial_type_id' => 1,
65 $createResult = $this->callAPIAndDocument($this->_entity
, 'create', $createParams, __FUNCTION__
, __FILE__
);
67 // Get priceset we just created.
68 $result = $this->callAPISuccess($this->_entity
, 'getSingle', [
69 'id' => $createResult['id'],
72 // Count the number of items in 'extends'.
73 $this->assertEquals(2, count($result['extends']));
77 * Check that no name doesn't cause failure.
79 public function testCreatePriceSetNoName() {
80 $params = $this->_params
;
81 unset($params['name']);
82 $this->callAPISuccess($this->_entity
, 'create', $params);
87 public function testGetBasicPriceSet() {
89 'name' => 'default_contribution_amount',
91 $getResult = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
92 $this->assertEquals(1, $getResult['count']);
95 public function testEventPriceSet() {
96 $event = $this->callAPISuccess('event', 'create', [
97 'title' => 'Event with Price Set',
100 'start_date' => 20151021,
101 'end_date' => 20151023,
105 'entity_table' => 'civicrm_event',
106 'entity_id' => $event['id'],
107 'name' => 'event price',
108 'title' => 'event price',
111 $createResult = $this->callAPIAndDocument($this->_entity
, 'create', $createParams, __FUNCTION__
, __FILE__
);
112 $result = $this->callAPISuccess($this->_entity
, 'get', [
113 'id' => $createResult['id'],
115 $this->assertEquals(['civicrm_event' => [$event['id']]], $result['values'][$createResult['id']]['entity']);
118 public function testDeletePriceSet() {
119 $startCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
120 $createResult = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
121 $deleteParams = ['id' => $createResult['id']];
122 $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
123 $endCount = $this->callAPISuccess($this->_entity
, 'getcount', []);
124 $this->assertEquals($startCount, $endCount);
127 public function testGetFieldsPriceSet() {
128 $result = $this->callAPISuccess($this->_entity
, 'getfields', ['action' => 'create']);
129 $this->assertEquals(16, $result['values']['is_quick_config']['type']);
132 public static function setUpBeforeClass() {
133 // put stuff here that should happen before all tests in this unit
136 public static function tearDownAfterClass() {
137 $tablesToTruncate = [
139 'civicrm_contribution',
141 $unitTest = new CiviUnitTestCase();
142 $unitTest->quickCleanup($tablesToTruncate);