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