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 | +--------------------------------------------------------------------+ | |
26 | */ | |
6a488035 TO |
27 | |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
e9479dcf EM |
29 | |
30 | /** | |
31 | * Class api_v3_PriceFieldValueTest | |
32 | */ | |
6a488035 TO |
33 | class api_v3_PriceFieldValueTest extends CiviUnitTestCase { |
34 | protected $_apiversion = 3; | |
35 | protected $_params; | |
36 | protected $id = 0; | |
37 | protected $priceSetID = 0; | |
38 | protected $_entity = 'price_field_value'; | |
b7c9bc4c | 39 | |
6a488035 TO |
40 | public $DBResetRequired = TRUE; |
41 | ||
42 | public function setUp() { | |
43 | parent::setUp(); | |
44 | // put stuff here that should happen before all tests in this unit | |
45 | $priceSetparams = array( | |
6a488035 TO |
46 | # [domain_id] => |
47 | 'name' => 'default_goat_priceset', | |
48 | 'title' => 'Goat accomodation', | |
49 | 'is_active' => 1, | |
50 | 'help_pre' => "Where does your goat sleep", | |
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 | ||
6c6e6187 | 58 | $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams); |
6a488035 TO |
59 | $this->priceSetID = $price_set['id']; |
60 | ||
61 | $priceFieldparams = array( | |
6a488035 TO |
62 | 'price_set_id' => $this->priceSetID, |
63 | 'name' => 'grassvariety', | |
64 | 'label' => 'Grass Variety', | |
65 | 'html_type' => 'Text', | |
66 | 'is_enter_qty' => 1, | |
67 | 'is_active' => 1, | |
68 | ); | |
6c6e6187 | 69 | $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldparams); |
6a488035 TO |
70 | $this->priceFieldID = $priceField['id']; |
71 | $this->_params = array( | |
6a488035 TO |
72 | 'price_field_id' => $this->priceFieldID, |
73 | 'name' => 'ryegrass', | |
74 | 'label' => 'juicy and healthy', | |
21dfd5f5 | 75 | 'amount' => 1, |
92915c55 | 76 | ); |
b6708aeb | 77 | |
6a488035 | 78 | $membershipOrgId = $this->organizationCreate(NULL); |
75638074 | 79 | $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId)); |
6a488035 | 80 | $priceSetparams1 = array( |
6a488035 TO |
81 | 'name' => 'priceset', |
82 | 'title' => 'Priceset with Multiple Terms', | |
83 | 'is_active' => 1, | |
84 | 'extends' => 3, | |
85 | 'financial_type_id' => 2, | |
86 | 'is_quick_config' => 1, | |
87 | 'is_reserved' => 1, | |
88 | ); | |
6c6e6187 | 89 | $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetparams1); |
6a488035 TO |
90 | $this->priceSetID1 = $price_set1['id']; |
91 | $priceFieldparams1 = array( | |
6a488035 TO |
92 | 'price_set_id' => $this->priceSetID1, |
93 | 'name' => 'memtype', | |
94 | 'label' => 'memtype', | |
95 | 'html_type' => 'Radio', | |
96 | 'is_enter_qty' => 1, | |
97 | 'is_active' => 1, | |
98 | ); | |
6c6e6187 | 99 | $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldparams1); |
6a488035 TO |
100 | $this->priceFieldID1 = $priceField1['id']; |
101 | } | |
102 | ||
00be9182 | 103 | public function tearDown() { |
6a488035 | 104 | $tablesToTruncate = array( |
92915c55 TO |
105 | 'civicrm_contact', |
106 | 'civicrm_contribution', | |
6a488035 TO |
107 | ); |
108 | $this->quickCleanup($tablesToTruncate); | |
109 | $this->membershipTypeDelete(array('id' => $this->_membershipTypeID)); | |
6c6e6187 | 110 | $this->callAPISuccess('PriceField', 'delete', array( |
92915c55 | 111 | 'id' => $this->priceFieldID1, |
6a488035 | 112 | )); |
6c6e6187 | 113 | $this->callAPISuccess('PriceSet', 'delete', array( |
6a488035 TO |
114 | 'id' => $this->priceSetID1, |
115 | )); | |
6c6e6187 | 116 | $this->callAPISuccess('PriceField', 'delete', array( |
92915c55 | 117 | 'id' => $this->priceFieldID, |
6a488035 | 118 | )); |
6c6e6187 | 119 | $delete = $this->callAPISuccess('PriceSet', 'delete', array( |
6a488035 TO |
120 | 'id' => $this->priceSetID, |
121 | )); | |
122 | ||
123 | $this->assertAPISuccess($delete); | |
124 | } | |
125 | ||
126 | public function testCreatePriceFieldValue() { | |
ca985406 | 127 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
6a488035 TO |
128 | $this->assertAPISuccess($result, 'In line ' . __LINE__); |
129 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); | |
130 | $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); | |
131 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); | |
132 | } | |
133 | ||
134 | public function testGetBasicPriceFieldValue() { | |
ca985406 | 135 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
6a488035 TO |
136 | $this->id = $createResult['id']; |
137 | $this->assertAPISuccess($createResult); | |
138 | $getParams = array( | |
6a488035 TO |
139 | 'name' => 'contribution_amount', |
140 | ); | |
ca985406 | 141 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
6a488035 | 142 | $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__); |
6c6e6187 | 143 | $this->callAPISuccess('price_field_value', 'delete', array('id' => $createResult['id'])); |
6a488035 TO |
144 | } |
145 | ||
146 | public function testDeletePriceFieldValue() { | |
ca985406 | 147 | $startCount = $this->callAPISuccess($this->_entity, 'getcount', array()); |
148 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); | |
149 | $deleteParams = array('id' => $createResult['id']); | |
150 | $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); | |
151 | ||
152 | $endCount = $this->callAPISuccess($this->_entity, 'getcount', array()); | |
6a488035 TO |
153 | $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__); |
154 | } | |
155 | ||
156 | public function testGetFieldsPriceFieldValue() { | |
ca985406 | 157 | $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); |
6a488035 TO |
158 | $this->assertEquals(1, $result['values']['max_value']['type']); |
159 | } | |
160 | ||
161 | public function testCreatePriceFieldValuewithMultipleTerms() { | |
162 | $params = array( | |
6a488035 | 163 | 'price_field_id' => $this->priceFieldID1, |
6c6e6187 | 164 | 'membership_type_id' => $this->_membershipTypeID, |
6a488035 TO |
165 | 'name' => 'memType1', |
166 | 'label' => 'memType1', | |
167 | 'amount' => 90, | |
168 | 'membership_num_terms' => 2, | |
169 | 'is_active' => 1, | |
170 | 'financial_type_id' => 2, | |
92915c55 | 171 | ); |
ca985406 | 172 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
173 | $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2); |
174 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); | |
ca985406 | 175 | $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); |
6a488035 | 176 | } |
92915c55 | 177 | |
6a488035 TO |
178 | public function testGetPriceFieldValuewithMultipleTerms() { |
179 | $params1 = array( | |
6a488035 | 180 | 'price_field_id' => $this->priceFieldID1, |
6c6e6187 | 181 | 'membership_type_id' => $this->_membershipTypeID, |
6a488035 TO |
182 | 'name' => 'memType1', |
183 | 'label' => 'memType1', | |
184 | 'amount' => 90, | |
185 | 'membership_num_terms' => 2, | |
186 | 'is_active' => 1, | |
187 | 'financial_type_id' => 2, | |
92915c55 | 188 | ); |
6a488035 | 189 | $params2 = array( |
6a488035 | 190 | 'price_field_id' => $this->priceFieldID1, |
6c6e6187 | 191 | 'membership_type_id' => $this->_membershipTypeID, |
6a488035 TO |
192 | 'name' => 'memType2', |
193 | 'label' => 'memType2', | |
194 | 'amount' => 120, | |
195 | 'membership_num_terms' => 3, | |
196 | 'is_active' => 1, | |
197 | 'financial_type_id' => 2, | |
92915c55 | 198 | ); |
ca985406 | 199 | $result1 = $this->callAPISuccess($this->_entity, 'create', $params1); |
200 | $result2 = $this->callAPISuccess($this->_entity, 'create', $params2); | |
481a74f4 | 201 | $result = $this->callAPISuccess($this->_entity, 'get', array('price_field_id' => $this->priceFieldID1)); |
6a488035 | 202 | $this->assertEquals(2, $result['count'], 'In line ' . __LINE__); |
6c6e6187 TO |
203 | $this->callAPISuccess($this->_entity, 'delete', array('id' => $result1['id'])); |
204 | $this->callAPISuccess($this->_entity, 'delete', array('id' => $result2['id'])); | |
6a488035 TO |
205 | } |
206 | } |