Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | */ | |
27 | ||
28 | require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
31 | * Class contains api test cases for "civicrm_note" | |
32 | * | |
33 | */ | |
34 | class api_v3_NoteTest extends CiviUnitTestCase { | |
35 | ||
36 | protected $_apiversion; | |
37 | protected $_contactID; | |
38 | protected $_params; | |
39 | protected $_noteID; | |
40 | protected $_note; | |
b7c9bc4c | 41 | |
6a488035 | 42 | |
4cbe18b8 EM |
43 | /** |
44 | * | |
45 | */ | |
6a488035 TO |
46 | function __construct() { |
47 | parent::__construct(); | |
48 | } | |
49 | ||
4cbe18b8 EM |
50 | /** |
51 | * @return array | |
52 | */ | |
6a488035 TO |
53 | function get_info() { |
54 | return array( | |
55 | 'name' => 'Note Create', | |
56 | 'description' => 'Test all Note Create API methods.', | |
57 | 'group' => 'CiviCRM API Tests', | |
58 | ); | |
59 | } | |
60 | ||
61 | function setUp() { | |
62 | ||
63 | $this->_apiversion = 3; | |
64 | // Connect to the database | |
65 | parent::setUp(); | |
66 | ||
67 | $this->_contactID = $this->organizationCreate(NULL); | |
68 | ||
69 | $this->_params = array( | |
70 | 'entity_table' => 'civicrm_contact', | |
71 | 'entity_id' => $this->_contactID, | |
72 | 'note' => 'Hello!!! m testing Note', | |
73 | 'contact_id' => $this->_contactID, | |
74 | 'modified_date' => '2011-01-31', | |
b5ee049f | 75 | 'subject' => 'Test Note', ); |
6a488035 TO |
76 | $this->_note = $this->noteCreate($this->_contactID); |
77 | $this->_noteID = $this->_note['id']; | |
78 | } | |
79 | ||
80 | function tearDown() { | |
81 | $tablesToTruncate = array( | |
82 | 'civicrm_note', 'civicrm_contact', | |
83 | ); | |
84 | $this->quickCleanup($tablesToTruncate); | |
85 | } | |
86 | ||
87 | ///////////////// civicrm_note_get methods | |
88 | ||
6a488035 | 89 | /** |
100fef9d | 90 | * Check retrieve note with empty parameter array |
6a488035 TO |
91 | * Error expected |
92 | */ | |
93 | function testGetWithEmptyParams() { | |
d0e1eff2 | 94 | $this->callAPISuccess('note', 'get', array()); |
6a488035 TO |
95 | } |
96 | ||
97 | /** | |
100fef9d | 98 | * Check retrieve note with missing patrameters |
6a488035 TO |
99 | * Error expected |
100 | */ | |
101 | function testGetWithoutEntityId() { | |
102 | $params = array( | |
103 | 'entity_table' => 'civicrm_contact', | |
6a488035 | 104 | ); |
b5ee049f | 105 | $note = $this->callAPISuccess('note', 'get', $params); |
6a488035 TO |
106 | } |
107 | ||
108 | /** | |
100fef9d | 109 | * Check civicrm_note_get |
6a488035 TO |
110 | */ |
111 | function testGet() { | |
112 | $entityId = $this->_noteID; | |
113 | $params = array( | |
114 | 'entity_table' => 'civicrm_contact', | |
115 | 'entity_id' => $entityId, | |
6a488035 | 116 | ); |
b5ee049f | 117 | $result = $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
118 | } |
119 | ||
120 | ||
121 | ///////////////// civicrm_note_create methods | |
122 | ||
6a488035 TO |
123 | /** |
124 | * Check create with empty parameter array | |
125 | * Error Expected | |
126 | */ | |
127 | function testCreateWithEmptyNoteField() { | |
128 | $this->_params['note'] = ""; | |
b5ee049f | 129 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
130 | 'Mandatory key(s) missing from params array: note'); | |
6a488035 TO |
131 | } |
132 | ||
133 | /** | |
134 | * Check create with partial params | |
135 | * Error expected | |
136 | */ | |
137 | function testCreateWithoutEntityId() { | |
138 | unset($this->_params['entity_id']); | |
b5ee049f | 139 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
140 | 'Mandatory key(s) missing from params array: entity_id'); | |
6a488035 TO |
141 | } |
142 | ||
143 | /** | |
144 | * Check create with partially empty params | |
145 | * Error expected | |
146 | */ | |
147 | function testCreateWithEmptyEntityId() { | |
148 | $this->_params['entity_id'] = ""; | |
b5ee049f | 149 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
150 | 'Mandatory key(s) missing from params array: entity_id'); | |
6a488035 TO |
151 | } |
152 | ||
153 | /** | |
154 | * Check civicrm_note_create | |
155 | */ | |
156 | function testCreate() { | |
157 | ||
b5ee049f | 158 | $result = $this->callAPIAndDocument('note', 'create', $this->_params, __FUNCTION__, __FILE__); |
6a488035 TO |
159 | $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note', 'in line ' . __LINE__); |
160 | $this->assertEquals(date('Y-m-d', strtotime($this->_params['modified_date'])), date('Y-m-d', strtotime($result['values'][$result['id']]['modified_date'])), 'in line ' . __LINE__); | |
161 | ||
61ef23bd | 162 | $this->assertArrayHasKey('id', $result); |
6a488035 | 163 | $note = array( |
b5ee049f | 164 | 'id' => $result['id'], ); |
6a488035 TO |
165 | $this->noteDelete($note); |
166 | } | |
167 | ||
168 | function testCreateWithApostropheInString() { | |
169 | $params = array( | |
170 | 'entity_table' => 'civicrm_contact', | |
171 | 'entity_id' => $this->_contactID, | |
172 | 'note' => "Hello!!! ' testing Note", | |
173 | 'contact_id' => $this->_contactID, | |
174 | 'modified_date' => '2011-01-31', | |
175 | 'subject' => "With a '", | |
b5ee049f | 176 | 'sequential' => 1, ); |
177 | $result = $this->callAPISuccess('Note', 'Create', $params); | |
791c263c | 178 | $this->assertAPISuccess($result, 'in line ' . __LINE__); |
6a488035 TO |
179 | $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note", 'in line ' . __LINE__); |
180 | $this->assertEquals($result['values'][0]['subject'], "With a '", 'in line ' . __LINE__); | |
181 | $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__); | |
182 | ||
183 | //CleanUP | |
184 | $note = array( | |
b5ee049f | 185 | 'id' => $result['id'], ); |
6a488035 TO |
186 | $this->noteDelete($note); |
187 | } | |
188 | ||
189 | /** | |
190 | * Check civicrm_note_create - tests used of default set to now | |
191 | */ | |
192 | function testCreateWithoutModifiedDate() { | |
193 | unset($this->_params['modified_date']); | |
b5ee049f | 194 | $apiResult = $this->callAPISuccess('note', 'create', $this->_params); |
6a488035 TO |
195 | $this->assertAPISuccess($apiResult); |
196 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date']))); | |
197 | $this->noteDelete(array( | |
b5ee049f | 198 | 'id' => $apiResult['id'], )); |
6a488035 TO |
199 | } |
200 | ||
201 | ||
202 | ///////////////// civicrm_note_update methods | |
203 | ||
6a488035 TO |
204 | /** |
205 | * Check update with empty parameter array | |
b5ee049f | 206 | * Please don't copy & paste this - is of marginal value |
207 | * better to put time into the function on Syntax Conformance class that tests this | |
6a488035 TO |
208 | */ |
209 | function testUpdateWithEmptyParams() { | |
b5ee049f | 210 | $note = $this->callAPIFailure('note', 'create', array()); |
6a488035 TO |
211 | } |
212 | ||
213 | /** | |
214 | * Check update with missing parameter (contact id) | |
215 | * Error expected | |
216 | */ | |
217 | function testUpdateWithoutContactId() { | |
218 | $params = array( | |
219 | 'entity_id' => $this->_contactID, | |
b5ee049f | 220 | 'entity_table' => 'civicrm_contact', ); |
221 | $note = $this->callAPIFailure('note', 'create', $params, | |
222 | 'Mandatory key(s) missing from params array: note' | |
6a488035 | 223 | ); |
6a488035 TO |
224 | } |
225 | ||
226 | /** | |
227 | * Check civicrm_note_update | |
228 | */ | |
229 | function testUpdate() { | |
230 | $params = array( | |
231 | 'id' => $this->_noteID, | |
232 | 'contact_id' => $this->_contactID, | |
233 | 'note' => 'Note1', | |
b5ee049f | 234 | 'subject' => 'Hello World', ); |
6a488035 TO |
235 | |
236 | //Update Note | |
b5ee049f | 237 | $this->callAPISuccess('note', 'create', $params); |
238 | $note = $this->callAPISuccess('Note', 'Get', array()); | |
6a488035 | 239 | $this->assertEquals($note['id'], $this->_noteID, 'in line ' . __LINE__); |
6a488035 TO |
240 | $this->assertEquals($note['values'][$this->_noteID]['entity_id'], $this->_contactID, 'in line ' . __LINE__); |
241 | $this->assertEquals($note['values'][$this->_noteID]['entity_table'], 'civicrm_contact', 'in line ' . __LINE__); | |
242 | $this->assertEquals('Hello World', $note['values'][$this->_noteID]['subject'], 'in line ' . __LINE__); | |
243 | $this->assertEquals('Note1', $note['values'][$this->_noteID]['note'], 'in line ' . __LINE__); | |
244 | } | |
245 | ||
246 | ///////////////// civicrm_note_delete methods | |
247 | ||
6a488035 TO |
248 | |
249 | /** | |
250 | * Check delete with empty parametes array | |
251 | * Error expected | |
252 | */ | |
253 | function testDeleteWithEmptyParams() { | |
b5ee049f | 254 | $deleteNote = $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
255 | } |
256 | ||
257 | /** | |
258 | * Check delete with wrong id | |
259 | * Error expected | |
260 | */ | |
261 | function testDeleteWithWrongID() { | |
262 | $params = array( | |
263 | 'id' => 0, | |
6a488035 | 264 | ); |
b5ee049f | 265 | $deleteNote = $this->callAPIFailure('note', 'delete', $params |
266 | , 'Mandatory key(s) missing from params array: id'); | |
6a488035 TO |
267 | } |
268 | ||
269 | /** | |
270 | * Check civicrm_note_delete | |
271 | */ | |
272 | function testDelete() { | |
273 | $additionalNote = $this->noteCreate($this->_contactID); | |
274 | ||
275 | $params = array( | |
276 | 'id' => $additionalNote['id'], | |
6a488035 TO |
277 | ); |
278 | ||
b5ee049f | 279 | $result = $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
280 | } |
281 | } | |
282 | ||
283 | /** | |
284 | * Test civicrm_activity_create() using example code | |
285 | */ | |
286 | function testNoteCreateExample() { | |
3ec6e38d | 287 | require_once 'api/v3/examples/Note/Create.php'; |
6a488035 TO |
288 | $result = UF_match_get_example(); |
289 | $expectedResult = UF_match_get_expectedresult(); | |
290 | $this->assertEquals($result, $expectedResult); | |
291 | } | |
292 |