Merge pull request #13926 from pradpnayak/NoticeErrorProfile
[civicrm-core.git] / tests / phpunit / api / v3 / PriceSetTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2/*
3 +--------------------------------------------------------------------+
2fe49090 4| CiviCRM version 5 |
b6708aeb 5+--------------------------------------------------------------------+
6b83d5bd 6| Copyright CiviCRM LLC (c) 2004-2019 |
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_PriceSetTest
acb109b7 30 * @group headless
e9479dcf 31 */
6a488035
TO
32class api_v3_PriceSetTest extends CiviUnitTestCase {
33 protected $_apiversion = 3;
34 protected $_params;
35 protected $id = 0;
36 protected $contactIds = array();
37 protected $_entity = 'price_set';
b7c9bc4c 38
6a488035 39 public $DBResetRequired = TRUE;
92915c55 40
fe482240
EM
41 /**
42 * Set up for class.
43 */
6a488035
TO
44 public function setUp() {
45 parent::setUp();
46 $this->_params = array(
6a488035
TO
47 'name' => 'default_goat_priceset',
48 'title' => 'Goat accessories',
49 'is_active' => 1,
50 'help_pre' => "Please describe your goat in detail",
51 'help_post' => "thank you for your time",
52 'extends' => 2,
53 'financial_type_id' => 1,
54 'is_quick_config' => 1,
55 'is_reserved' => 1,
56 );
57 }
58
00be9182 59 public function tearDown() {
6a488035
TO
60 }
61
e0c1764e 62 /**
fe482240 63 * Test create price set.
e0c1764e 64 */
6a488035 65 public function testCreatePriceSet() {
ca985406 66 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
7aed59c0
EM
67 $this->assertEquals(1, $result['count']);
68 $this->assertNotNull($result['values'][$result['id']]['id']);
6a488035
TO
69 $this->getAndCheck($this->_params, $result['id'], $this->_entity);
70 }
71
a72f0e58
JV
72 /**
73 * Test for creating price sets used for both events and contributions.
74 */
75 public function testCreatePriceSetForEventAndContribution() {
76 // Create the price set
77 $createParams = array(
78 'name' => 'some_price_set',
79 'title' => 'Some Price Set',
80 'is_active' => 1,
81 'financial_type_id' => 1,
6c6e6187 82 'extends' => array(1, 2),
a72f0e58
JV
83 );
84 $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
85
86 // Get priceset we just created.
87 $result = $this->callAPISuccess($this->_entity, 'getSingle', array(
88 'id' => $createResult['id'],
89 ));
90
91 // Count the number of items in 'extends'.
92 $this->assertEquals(2, count($result['extends']));
93 }
94
e0c1764e 95 /**
fe482240 96 * Check that no name doesn't cause failure.
e0c1764e
EM
97 */
98 public function testCreatePriceSetNoName() {
99 $params = $this->_params;
100 unset($params['name']);
fe482240 101 $this->callAPISuccess($this->_entity, 'create', $params);
e0c1764e
EM
102 }
103
104 /**
e0c1764e 105 */
6a488035
TO
106 public function testGetBasicPriceSet() {
107 $getParams = array(
6a488035
TO
108 'name' => 'default_contribution_amount',
109 );
ca985406 110 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
7aed59c0 111 $this->assertEquals(1, $getResult['count']);
6a488035
TO
112 }
113
114 public function testEventPriceSet() {
ca985406 115 $event = $this->callAPISuccess('event', 'create', array(
6a488035
TO
116 'title' => 'Event with Price Set',
117 'event_type_id' => 1,
118 'is_public' => 1,
119 'start_date' => 20151021,
120 'end_date' => 20151023,
121 'is_active' => 1,
122 ));
6a488035 123 $createParams = array(
6a488035
TO
124 'entity_table' => 'civicrm_event',
125 'entity_id' => $event['id'],
126 'name' => 'event price',
127 'title' => 'event price',
128 'extends' => 1,
129 );
ca985406 130 $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
131 $result = $this->callAPISuccess($this->_entity, 'get', array(
132 'id' => $createResult['id'],
6a488035 133 ));
7aed59c0 134 $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']);
6a488035
TO
135 }
136
137 public function testDeletePriceSet() {
ca985406 138 $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
139 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
140 $deleteParams = array('id' => $createResult['id']);
7aed59c0 141 $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
ca985406 142 $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
7aed59c0 143 $this->assertEquals($startCount, $endCount);
6a488035
TO
144 }
145
146 public function testGetFieldsPriceSet() {
ca985406 147 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
6a488035
TO
148 $this->assertEquals(16, $result['values']['is_quick_config']['type']);
149 }
150
151 public static function setUpBeforeClass() {
6c6e6187 152 // put stuff here that should happen before all tests in this unit
6a488035
TO
153 }
154
9b873358 155 public static function tearDownAfterClass() {
6a488035
TO
156 $tablesToTruncate = array(
157 'civicrm_contact',
158 'civicrm_contribution',
159 );
160 $unitTest = new CiviUnitTestCase();
161 $unitTest->quickCleanup($tablesToTruncate);
162 }
96025800 163
6a488035 164}