5d451a6f506f8f3091aeca7074a4ae3a0f87e18e
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() {
104 $note = civicrm_api('note', 'get', $params);
105 $this->assertEquals($note['is_error'], 1);
109 * check retrieve note with missing patrameters
112 function testGetWithoutEntityId() {
114 'entity_table' => 'civicrm_contact',
117 $note = civicrm_api('note', 'get', $params);
118 $this->assertEquals($note['is_error'], 0);
122 * check civicrm_note_get
125 $entityId = $this->_noteID
;
127 'entity_table' => 'civicrm_contact',
128 'entity_id' => $entityId,
129 'version' => $this->_apiversion
,
131 $result = civicrm_api3_note_get($params);
132 $this->documentMe($this->_params
, $result, __FUNCTION__
, __FILE__
);
133 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
137 ///////////////// civicrm_note_create methods
140 * Check create with wrong parameter
143 function testCreateWithWrongParamsType() {
144 $params = 'a string';
145 $result = civicrm_api('note', 'create', $params);
146 $this->assertAPIFailure($result,
147 "In line " . __LINE__
149 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
153 * Check create with empty parameter array
156 function testCreateWithEmptyNoteField() {
157 $this->_params
['note'] = "";
158 $result = civicrm_api('note', 'create', $this->_params
);
159 $this->assertAPIFailure($result);
160 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: note');
164 * Check create with partial params
167 function testCreateWithoutEntityId() {
168 unset($this->_params
['entity_id']);
169 $result = civicrm_api('note', 'create', $this->_params
);
170 $this->assertAPIFailure($result);
171 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: entity_id');
175 * Check create with partially empty params
178 function testCreateWithEmptyEntityId() {
179 $this->_params
['entity_id'] = "";
180 $result = civicrm_api('note', 'create', $this->_params
);
181 $this->assertAPIFailure($result);
182 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: entity_id');
186 * Check civicrm_note_create
188 function testCreate() {
190 $result = civicrm_api('note', 'create', $this->_params
);
191 $this->documentMe($this->_params
, $result, __FUNCTION__
, __FILE__
);
192 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note', 'in line ' . __LINE__
);
193 $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__
);
195 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
196 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
198 'id' => $result['id'],
199 'version' => $this->_apiversion
,
201 $this->noteDelete($note);
204 function testCreateWithApostropheInString() {
206 'entity_table' => 'civicrm_contact',
207 'entity_id' => $this->_contactID
,
208 'note' => "Hello!!! ' testing Note",
209 'contact_id' => $this->_contactID
,
210 'modified_date' => '2011-01-31',
211 'subject' => "With a '",
213 'version' => $this->_apiversion
,
215 $result = civicrm_api('Note', 'Create', $params);
216 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
217 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note", 'in line ' . __LINE__
);
218 $this->assertEquals($result['values'][0]['subject'], "With a '", 'in line ' . __LINE__
);
219 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
223 'id' => $result['id'],
224 'version' => $this->_apiversion
,
226 $this->noteDelete($note);
230 * Check civicrm_note_create - tests used of default set to now
232 function testCreateWithoutModifiedDate() {
233 unset($this->_params
['modified_date']);
234 $apiResult = civicrm_api('note', 'create', $this->_params
);
235 $this->assertAPISuccess($apiResult);
236 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
237 $this->noteDelete(array(
238 'id' => $apiResult['id'],
239 'version' => $this->_apiversion
,
244 ///////////////// civicrm_note_update methods
247 * Check update note with wrong params type
250 function testUpdateWithWrongParamsType() {
251 $params = 'a string';
252 $result = civicrm_api('note', 'create', $params);
253 $this->assertAPIFailure($result,
254 "In line " . __LINE__
259 * Check update with empty parameter array
262 function testUpdateWithEmptyParams() {
264 $note = civicrm_api('note', 'create', $params);
265 $this->assertEquals($note['is_error'], 1);
269 * Check update with missing parameter (contact id)
272 function testUpdateWithoutContactId() {
274 'entity_id' => $this->_contactID
,
275 'entity_table' => 'civicrm_contact',
276 'version' => $this->_apiversion
,
278 $note = civicrm_api('note', 'create', $params);
279 $this->assertEquals($note['is_error'], 1);
280 $this->assertEquals($note['error_message'], 'Mandatory key(s) missing from params array: note');
284 * Check civicrm_note_update
286 function testUpdate() {
288 'id' => $this->_noteID
,
289 'contact_id' => $this->_contactID
,
291 'subject' => 'Hello World',
292 'version' => $this->_apiversion
,
296 civicrm_api('note', 'create', $params);
297 $note = civicrm_api('Note', 'Get', array('version' => 3));
298 $this->assertEquals($note['id'], $this->_noteID
, 'in line ' . __LINE__
);
299 $this->assertEquals($note['is_error'], 0, 'in line ' . __LINE__
);
300 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
, 'in line ' . __LINE__
);
301 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact', 'in line ' . __LINE__
);
302 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject'], 'in line ' . __LINE__
);
303 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note'], 'in line ' . __LINE__
);
306 ///////////////// civicrm_note_delete methods
309 * Check delete note with wrong params type
312 function testDeleteWithWrongParamsType() {
313 $params = 'a string';
314 $result = civicrm_api('note', 'delete', $params);
315 $this->assertAPIFailure($result,
316 "In line " . __LINE__
321 * Check delete with empty parametes array
324 function testDeleteWithEmptyParams() {
326 $deleteNote = civicrm_api('note', 'delete', $params);
327 $this->assertEquals($deleteNote['is_error'], 1);
328 $this->assertEquals($deleteNote['error_message'], 'Mandatory key(s) missing from params array: version, id');
332 * Check delete with wrong id
335 function testDeleteWithWrongID() {
338 'version' => $this->_apiversion
,
340 $deleteNote = civicrm_api('note', 'delete', $params);
341 $this->assertEquals($deleteNote['is_error'], 1);
342 $this->assertEquals($deleteNote['error_message'], 'Mandatory key(s) missing from params array: id');
346 * Check civicrm_note_delete
348 function testDelete() {
349 $additionalNote = $this->noteCreate($this->_contactID
);
352 'id' => $additionalNote['id'],
353 'version' => $this->_apiversion
,
356 $result = civicrm_api('note', 'delete', $params);
358 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
359 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
364 * Test civicrm_activity_create() using example code
366 function testNoteCreateExample() {
367 require_once 'api/v3/examples/NoteCreate.php';
368 $result = UF_match_get_example();
369 $expectedResult = UF_match_get_expectedresult();
370 $this->assertEquals($result, $expectedResult);