INFRA-132 - @param type fixes
[civicrm-core.git] / tests / phpunit / api / v3 / PriceSetTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2
3/*
4 +--------------------------------------------------------------------+
39de6fd5 5| CiviCRM version 4.6 |
b6708aeb 6+--------------------------------------------------------------------+
06a1bc01 7| Copyright CiviCRM LLC (c) 2004-2014 |
b6708aeb 8+--------------------------------------------------------------------+
9| This file is a part of CiviCRM. |
10| |
11| CiviCRM is free software; you can copy, modify, and distribute it |
12| under the terms of the GNU Affero General Public License |
13| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14| |
15| CiviCRM is distributed in the hope that it will be useful, but |
16| WITHOUT ANY WARRANTY; without even the implied warranty of |
17| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18| See the GNU Affero General Public License for more details. |
19| |
20| You should have received a copy of the GNU Affero General Public |
21| License and the CiviCRM Licensing Exception along |
22| with this program; if not, contact CiviCRM LLC |
23| at info[AT]civicrm[DOT]org. If you have questions about the |
24| GNU Affero General Public License or the licensing of CiviCRM, |
25| see the CiviCRM license FAQ at http://civicrm.org/licensing |
26+--------------------------------------------------------------------+
27*/
6a488035
TO
28
29require_once 'CiviTest/CiviUnitTestCase.php';
e9479dcf
EM
30
31/**
32 * Class api_v3_PriceSetTest
33 */
6a488035
TO
34class api_v3_PriceSetTest extends CiviUnitTestCase {
35 protected $_apiversion = 3;
36 protected $_params;
37 protected $id = 0;
38 protected $contactIds = array();
39 protected $_entity = 'price_set';
b7c9bc4c 40
6a488035
TO
41 public $DBResetRequired = TRUE;
42 public function setUp() {
43 parent::setUp();
44 $this->_params = array(
6c6e6187 45 # [domain_id] =>
6a488035
TO
46 'name' => 'default_goat_priceset',
47 'title' => 'Goat accessories',
48 'is_active' => 1,
49 'help_pre' => "Please describe your goat in detail",
50 'help_post' => "thank you for your time",
51 'extends' => 2,
52 'financial_type_id' => 1,
53 'is_quick_config' => 1,
54 'is_reserved' => 1,
55 );
56 }
57
00be9182 58 public function tearDown() {
6a488035
TO
59 }
60
e0c1764e
EM
61 /**
62 *
63 */
6a488035 64 public function testCreatePriceSet() {
ca985406 65 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
7aed59c0
EM
66 $this->assertEquals(1, $result['count']);
67 $this->assertNotNull($result['values'][$result['id']]['id']);
6a488035
TO
68 $this->getAndCheck($this->_params, $result['id'], $this->_entity);
69 }
70
a72f0e58
JV
71 /**
72 * Test for creating price sets used for both events and contributions.
73 */
74 public function testCreatePriceSetForEventAndContribution() {
75 // Create the price set
76 $createParams = array(
77 'name' => 'some_price_set',
78 'title' => 'Some Price Set',
79 'is_active' => 1,
80 'financial_type_id' => 1,
6c6e6187 81 'extends' => array(1, 2),
a72f0e58
JV
82 );
83 $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
84
85 // Get priceset we just created.
86 $result = $this->callAPISuccess($this->_entity, 'getSingle', array(
87 'id' => $createResult['id'],
88 ));
89
90 // Count the number of items in 'extends'.
91 $this->assertEquals(2, count($result['extends']));
92 }
93
e0c1764e
EM
94 /**
95 * Check that no name doesn't cause failure
96 */
97 public function testCreatePriceSetNoName() {
98 $params = $this->_params;
99 unset($params['name']);
100 $result = $this->callAPISuccess($this->_entity, 'create', $params);
101 }
102
103 /**
104 *
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 }
163}