Fix token subscriber to format the display of the custom tokens
[civicrm-core.git] / tests / phpunit / api / v3 / PriceSetTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class api_v3_PriceSetTest
14 * @group headless
15 */
16 class api_v3_PriceSetTest extends CiviUnitTestCase {
17 protected $_apiversion = 3;
18 protected $_params;
19 protected $id = 0;
20 protected $contactIds = [];
21 protected $_entity = 'price_set';
22
23 public $DBResetRequired = TRUE;
24
25 /**
26 * Set up for class.
27 */
28 public function setUp() {
29 parent::setUp();
30 $this->_params = [
31 'name' => 'default_goat_priceset',
32 'title' => 'Goat accessories',
33 'is_active' => 1,
34 'help_pre' => "Please describe your goat in detail",
35 'help_post' => "thank you for your time",
36 'extends' => 2,
37 'financial_type_id' => 1,
38 'is_quick_config' => 1,
39 'is_reserved' => 1,
40 ];
41 }
42
43 /**
44 * Test create price set.
45 */
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);
51 }
52
53 /**
54 * Test for creating price sets used for both events and contributions.
55 */
56 public function testCreatePriceSetForEventAndContribution() {
57 // Create the price set
58 $createParams = [
59 'name' => 'some_price_set',
60 'title' => 'Some Price Set',
61 'is_active' => 1,
62 'financial_type_id' => 1,
63 'extends' => [1, 2],
64 ];
65 $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
66
67 // Get priceset we just created.
68 $result = $this->callAPISuccess($this->_entity, 'getSingle', [
69 'id' => $createResult['id'],
70 ]);
71
72 // Count the number of items in 'extends'.
73 $this->assertEquals(2, count($result['extends']));
74 }
75
76 /**
77 * Check that no name doesn't cause failure.
78 */
79 public function testCreatePriceSetNoName() {
80 $params = $this->_params;
81 unset($params['name']);
82 $this->callAPISuccess($this->_entity, 'create', $params);
83 }
84
85 /**
86 */
87 public function testGetBasicPriceSet() {
88 $getParams = [
89 'name' => 'default_contribution_amount',
90 ];
91 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
92 $this->assertEquals(1, $getResult['count']);
93 }
94
95 public function testEventPriceSet() {
96 $event = $this->callAPISuccess('event', 'create', [
97 'title' => 'Event with Price Set',
98 'event_type_id' => 1,
99 'is_public' => 1,
100 'start_date' => 20151021,
101 'end_date' => 20151023,
102 'is_active' => 1,
103 ]);
104 $createParams = [
105 'entity_table' => 'civicrm_event',
106 'entity_id' => $event['id'],
107 'name' => 'event price',
108 'title' => 'event price',
109 'extends' => 1,
110 ];
111 $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
112 $result = $this->callAPISuccess($this->_entity, 'get', [
113 'id' => $createResult['id'],
114 ]);
115 $this->assertEquals(['civicrm_event' => [$event['id']]], $result['values'][$createResult['id']]['entity']);
116 }
117
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);
125 }
126
127 public function testGetFieldsPriceSet() {
128 $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
129 $this->assertEquals(16, $result['values']['is_quick_config']['type']);
130 }
131
132 public static function setUpBeforeClass() {
133 // put stuff here that should happen before all tests in this unit
134 }
135
136 public static function tearDownAfterClass() {
137 $tablesToTruncate = [
138 'civicrm_contact',
139 'civicrm_contribution',
140 ];
141 $unitTest = new CiviUnitTestCase();
142 $unitTest->quickCleanup($tablesToTruncate);
143 }
144
145 }