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