Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
e9479dcf EM |
29 | |
30 | /** | |
31 | * Class api_v3_PriceSetTest | |
32 | */ | |
6a488035 TO |
33 | class 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 | |
6a488035 TO |
42 | public function setUp() { |
43 | parent::setUp(); | |
44 | $this->_params = array( | |
92915c55 | 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 | 61 | /** |
e0c1764e | 62 | */ |
6a488035 | 63 | public function testCreatePriceSet() { |
ca985406 | 64 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
7aed59c0 EM |
65 | $this->assertEquals(1, $result['count']); |
66 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
67 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); |
68 | } | |
69 | ||
a72f0e58 JV |
70 | /** |
71 | * Test for creating price sets used for both events and contributions. | |
72 | */ | |
73 | public function testCreatePriceSetForEventAndContribution() { | |
74 | // Create the price set | |
75 | $createParams = array( | |
76 | 'name' => 'some_price_set', | |
77 | 'title' => 'Some Price Set', | |
78 | 'is_active' => 1, | |
79 | 'financial_type_id' => 1, | |
6c6e6187 | 80 | 'extends' => array(1, 2), |
a72f0e58 JV |
81 | ); |
82 | $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__); | |
83 | ||
84 | // Get priceset we just created. | |
85 | $result = $this->callAPISuccess($this->_entity, 'getSingle', array( | |
86 | 'id' => $createResult['id'], | |
87 | )); | |
88 | ||
89 | // Count the number of items in 'extends'. | |
90 | $this->assertEquals(2, count($result['extends'])); | |
91 | } | |
92 | ||
e0c1764e EM |
93 | /** |
94 | * Check that no name doesn't cause failure | |
95 | */ | |
96 | public function testCreatePriceSetNoName() { | |
97 | $params = $this->_params; | |
98 | unset($params['name']); | |
99 | $result = $this->callAPISuccess($this->_entity, 'create', $params); | |
100 | } | |
101 | ||
102 | /** | |
e0c1764e | 103 | */ |
6a488035 TO |
104 | public function testGetBasicPriceSet() { |
105 | $getParams = array( | |
6a488035 TO |
106 | 'name' => 'default_contribution_amount', |
107 | ); | |
ca985406 | 108 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
7aed59c0 | 109 | $this->assertEquals(1, $getResult['count']); |
6a488035 TO |
110 | } |
111 | ||
112 | public function testEventPriceSet() { | |
ca985406 | 113 | $event = $this->callAPISuccess('event', 'create', array( |
6a488035 TO |
114 | 'title' => 'Event with Price Set', |
115 | 'event_type_id' => 1, | |
116 | 'is_public' => 1, | |
117 | 'start_date' => 20151021, | |
118 | 'end_date' => 20151023, | |
119 | 'is_active' => 1, | |
120 | )); | |
6a488035 | 121 | $createParams = array( |
6a488035 TO |
122 | 'entity_table' => 'civicrm_event', |
123 | 'entity_id' => $event['id'], | |
124 | 'name' => 'event price', | |
125 | 'title' => 'event price', | |
126 | 'extends' => 1, | |
127 | ); | |
ca985406 | 128 | $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__); |
129 | $result = $this->callAPISuccess($this->_entity, 'get', array( | |
130 | 'id' => $createResult['id'], | |
6a488035 | 131 | )); |
7aed59c0 | 132 | $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']); |
6a488035 TO |
133 | } |
134 | ||
135 | public function testDeletePriceSet() { | |
ca985406 | 136 | $startCount = $this->callAPISuccess($this->_entity, 'getcount', array()); |
137 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); | |
138 | $deleteParams = array('id' => $createResult['id']); | |
7aed59c0 | 139 | $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); |
ca985406 | 140 | $endCount = $this->callAPISuccess($this->_entity, 'getcount', array()); |
7aed59c0 | 141 | $this->assertEquals($startCount, $endCount); |
6a488035 TO |
142 | } |
143 | ||
144 | public function testGetFieldsPriceSet() { | |
ca985406 | 145 | $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); |
6a488035 TO |
146 | $this->assertEquals(16, $result['values']['is_quick_config']['type']); |
147 | } | |
148 | ||
149 | public static function setUpBeforeClass() { | |
6c6e6187 | 150 | // put stuff here that should happen before all tests in this unit |
6a488035 TO |
151 | } |
152 | ||
9b873358 | 153 | public static function tearDownAfterClass() { |
6a488035 TO |
154 | $tablesToTruncate = array( |
155 | 'civicrm_contact', | |
156 | 'civicrm_contribution', | |
157 | ); | |
158 | $unitTest = new CiviUnitTestCase(); | |
159 | $unitTest->quickCleanup($tablesToTruncate); | |
160 | } | |
96025800 | 161 | |
6a488035 | 162 | } |