Merge pull request #4771 from pratikshad/CRM-15409
[civicrm-core.git] / tests / phpunit / api / v3 / PriceSetTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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 */
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30
31 /**
32 * Class api_v3_PriceSetTest
33 */
34 class 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';
40
41 public $DBResetRequired = TRUE;
42 public function setUp() {
43 parent::setUp();
44 $this->_params = array(
45 # [domain_id] =>
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
58 function tearDown() {
59 }
60
61 /**
62 *
63 */
64 public function testCreatePriceSet() {
65 $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
66 $this->assertEquals(1, $result['count']);
67 $this->assertNotNull($result['values'][$result['id']]['id']);
68 $this->getAndCheck($this->_params, $result['id'], $this->_entity);
69 }
70
71 /**
72 * Check that no name doesn't cause failure
73 */
74 public function testCreatePriceSetNoName() {
75 $params = $this->_params;
76 unset($params['name']);
77 $result = $this->callAPISuccess($this->_entity, 'create', $params);
78 }
79
80 /**
81 *
82 */
83 public function testGetBasicPriceSet() {
84 $getParams = array(
85 'name' => 'default_contribution_amount',
86 );
87 $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
88 $this->assertEquals(1, $getResult['count']);
89 }
90
91 public function testEventPriceSet() {
92 $event = $this->callAPISuccess('event', 'create', array(
93 'title' => 'Event with Price Set',
94 'event_type_id' => 1,
95 'is_public' => 1,
96 'start_date' => 20151021,
97 'end_date' => 20151023,
98 'is_active' => 1,
99 ));
100 $createParams = array(
101 'entity_table' => 'civicrm_event',
102 'entity_id' => $event['id'],
103 'name' => 'event price',
104 'title' => 'event price',
105 'extends' => 1,
106 );
107 $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
108 $result = $this->callAPISuccess($this->_entity, 'get', array(
109 'id' => $createResult['id'],
110 ));
111 $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']);
112 }
113
114 public function testDeletePriceSet() {
115 $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
116 $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
117 $deleteParams = array('id' => $createResult['id']);
118 $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
119 $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
120 $this->assertEquals($startCount, $endCount);
121 }
122
123 public function testGetFieldsPriceSet() {
124 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
125 $this->assertEquals(16, $result['values']['is_quick_config']['type']);
126 }
127
128 public static function setUpBeforeClass() {
129 // put stuff here that should happen before all tests in this unit
130 }
131
132 public static function tearDownAfterClass(){
133 $tablesToTruncate = array(
134 'civicrm_contact',
135 'civicrm_contribution',
136 );
137 $unitTest = new CiviUnitTestCase();
138 $unitTest->quickCleanup($tablesToTruncate);
139 }
140 }
141