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