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