4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
32 * Class contains api test cases for "civicrm_note"
35 class api_v3_NoteTest
extends CiviUnitTestCase
{
37 protected $_apiversion;
38 protected $_contactID;
42 public $_eNoticeCompliant = TRUE;
44 function __construct() {
45 parent
::__construct();
50 'name' => 'Note Create',
51 'description' => 'Test all Note Create API methods.',
52 'group' => 'CiviCRM API Tests',
58 $this->_apiversion
= 3;
59 // Connect to the database
62 $this->_contactID
= $this->organizationCreate(NULL);
64 $this->_params
= array(
65 'entity_table' => 'civicrm_contact',
66 'entity_id' => $this->_contactID
,
67 'note' => 'Hello!!! m testing Note',
68 'contact_id' => $this->_contactID
,
69 'modified_date' => '2011-01-31',
70 'subject' => 'Test Note',
71 'version' => $this->_apiversion
,
73 $this->_note
= $this->noteCreate($this->_contactID
);
74 $this->_noteID
= $this->_note
['id'];
78 $tablesToTruncate = array(
79 'civicrm_note', 'civicrm_contact',
81 $this->quickCleanup($tablesToTruncate);
84 ///////////////// civicrm_note_get methods
87 * check retrieve note with wrong params type
90 function testGetWithWrongParamsType() {
92 $result = civicrm_api('note', 'get', $params);
93 $this->assertAPIFailure($result,
99 * check retrieve note with empty parameter array
102 function testGetWithEmptyParams() {
103 $this->callAPISuccess('note', 'get', array());
107 * check retrieve note with missing patrameters
110 function testGetWithoutEntityId() {
112 'entity_table' => 'civicrm_contact',
115 $note = civicrm_api('note', 'get', $params);
116 $this->assertEquals($note['is_error'], 0);
120 * check civicrm_note_get
123 $entityId = $this->_noteID
;
125 'entity_table' => 'civicrm_contact',
126 'entity_id' => $entityId,
127 'version' => $this->_apiversion
,
129 $result = civicrm_api3_note_get($params);
130 $this->documentMe($this->_params
, $result, __FUNCTION__
, __FILE__
);
131 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
135 ///////////////// civicrm_note_create methods
138 * Check create with wrong parameter
141 function testCreateWithWrongParamsType() {
142 $params = 'a string';
143 $result = civicrm_api('note', 'create', $params);
144 $this->assertAPIFailure($result,
145 "In line " . __LINE__
147 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
151 * Check create with empty parameter array
154 function testCreateWithEmptyNoteField() {
155 $this->_params
['note'] = "";
156 $result = civicrm_api('note', 'create', $this->_params
);
157 $this->assertAPIFailure($result);
158 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: note');
162 * Check create with partial params
165 function testCreateWithoutEntityId() {
166 unset($this->_params
['entity_id']);
167 $result = civicrm_api('note', 'create', $this->_params
);
168 $this->assertAPIFailure($result);
169 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: entity_id');
173 * Check create with partially empty params
176 function testCreateWithEmptyEntityId() {
177 $this->_params
['entity_id'] = "";
178 $result = civicrm_api('note', 'create', $this->_params
);
179 $this->assertAPIFailure($result);
180 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: entity_id');
184 * Check civicrm_note_create
186 function testCreate() {
188 $result = civicrm_api('note', 'create', $this->_params
);
189 $this->documentMe($this->_params
, $result, __FUNCTION__
, __FILE__
);
190 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note', 'in line ' . __LINE__
);
191 $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__
);
193 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
194 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
196 'id' => $result['id'],
197 'version' => $this->_apiversion
,
199 $this->noteDelete($note);
202 function testCreateWithApostropheInString() {
204 'entity_table' => 'civicrm_contact',
205 'entity_id' => $this->_contactID
,
206 'note' => "Hello!!! ' testing Note",
207 'contact_id' => $this->_contactID
,
208 'modified_date' => '2011-01-31',
209 'subject' => "With a '",
211 'version' => $this->_apiversion
,
213 $result = civicrm_api('Note', 'Create', $params);
214 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
215 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note", 'in line ' . __LINE__
);
216 $this->assertEquals($result['values'][0]['subject'], "With a '", 'in line ' . __LINE__
);
217 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
221 'id' => $result['id'],
222 'version' => $this->_apiversion
,
224 $this->noteDelete($note);
228 * Check civicrm_note_create - tests used of default set to now
230 function testCreateWithoutModifiedDate() {
231 unset($this->_params
['modified_date']);
232 $apiResult = civicrm_api('note', 'create', $this->_params
);
233 $this->assertAPISuccess($apiResult);
234 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
235 $this->noteDelete(array(
236 'id' => $apiResult['id'],
237 'version' => $this->_apiversion
,
242 ///////////////// civicrm_note_update methods
245 * Check update note with wrong params type
248 function testUpdateWithWrongParamsType() {
249 $params = 'a string';
250 $result = civicrm_api('note', 'create', $params);
251 $this->assertAPIFailure($result,
252 "In line " . __LINE__
257 * Check update with empty parameter array
260 function testUpdateWithEmptyParams() {
262 $note = $this->callAPIFailure('note', 'create', $params);
266 * Check update with missing parameter (contact id)
269 function testUpdateWithoutContactId() {
271 'entity_id' => $this->_contactID
,
272 'entity_table' => 'civicrm_contact',
273 'version' => $this->_apiversion
,
275 $note = $this->callAPIFailure('note', 'create', $params);
276 $this->assertEquals($note['error_message'], 'Mandatory key(s) missing from params array: note');
280 * Check civicrm_note_update
282 function testUpdate() {
284 'id' => $this->_noteID
,
285 'contact_id' => $this->_contactID
,
287 'subject' => 'Hello World',
288 'version' => $this->_apiversion
,
292 civicrm_api('note', 'create', $params);
293 $note = civicrm_api('Note', 'Get', array('version' => 3));
294 $this->assertEquals($note['id'], $this->_noteID
, 'in line ' . __LINE__
);
295 $this->assertEquals($note['is_error'], 0, 'in line ' . __LINE__
);
296 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
, 'in line ' . __LINE__
);
297 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact', 'in line ' . __LINE__
);
298 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject'], 'in line ' . __LINE__
);
299 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note'], 'in line ' . __LINE__
);
302 ///////////////// civicrm_note_delete methods
305 * Check delete note with wrong params type
308 function testDeleteWithWrongParamsType() {
309 $params = 'a string';
310 $result = civicrm_api('note', 'delete', $params);
311 $this->assertAPIFailure($result,
312 "In line " . __LINE__
317 * Check delete with empty parametes array
320 function testDeleteWithEmptyParams() {
322 $deleteNote = $this->callAPIFailure('note', 'delete', $params);
323 $this->assertEquals($deleteNote['error_message'], 'Mandatory key(s) missing from params array: id');
327 * Check delete with wrong id
330 function testDeleteWithWrongID() {
333 'version' => $this->_apiversion
,
335 $deleteNote = $this->callAPIFailure('note', 'delete', $params);
336 $this->assertEquals($deleteNote['error_message'], 'Mandatory key(s) missing from params array: id');
340 * Check civicrm_note_delete
342 function testDelete() {
343 $additionalNote = $this->noteCreate($this->_contactID
);
346 'id' => $additionalNote['id'],
347 'version' => $this->_apiversion
,
350 $result = civicrm_api('note', 'delete', $params);
352 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
353 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
358 * Test civicrm_activity_create() using example code
360 function testNoteCreateExample() {
361 require_once 'api/v3/examples/NoteCreate.php';
362 $result = UF_match_get_example();
363 $expectedResult = UF_match_get_expectedresult();
364 $this->assertEquals($result, $expectedResult);