3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
31 * Class contains api test cases for "civicrm_note"
34 class api_v3_NoteTest
extends CiviUnitTestCase
{
36 protected $_apiversion;
37 protected $_contactID;
41 public $_eNoticeCompliant = TRUE;
43 function __construct() {
44 parent
::__construct();
49 'name' => 'Note Create',
50 'description' => 'Test all Note Create API methods.',
51 'group' => 'CiviCRM API Tests',
57 $this->_apiversion
= 3;
58 // Connect to the database
61 $this->_contactID
= $this->organizationCreate(NULL);
63 $this->_params
= array(
64 'entity_table' => 'civicrm_contact',
65 'entity_id' => $this->_contactID
,
66 'note' => 'Hello!!! m testing Note',
67 'contact_id' => $this->_contactID
,
68 'modified_date' => '2011-01-31',
69 'subject' => 'Test Note', );
70 $this->_note
= $this->noteCreate($this->_contactID
);
71 $this->_noteID
= $this->_note
['id'];
75 $tablesToTruncate = array(
76 'civicrm_note', 'civicrm_contact',
78 $this->quickCleanup($tablesToTruncate);
81 ///////////////// civicrm_note_get methods
84 * check retrieve note with empty parameter array
87 function testGetWithEmptyParams() {
88 $this->callAPISuccess('note', 'get', array());
92 * check retrieve note with missing patrameters
95 function testGetWithoutEntityId() {
97 'entity_table' => 'civicrm_contact',
99 $note = $this->callAPISuccess('note', 'get', $params);
103 * check civicrm_note_get
106 $entityId = $this->_noteID
;
108 'entity_table' => 'civicrm_contact',
109 'entity_id' => $entityId,
111 $result = $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
115 ///////////////// civicrm_note_create methods
118 * Check create with empty parameter array
121 function testCreateWithEmptyNoteField() {
122 $this->_params
['note'] = "";
123 $result = $this->callAPIFailure('note', 'create', $this->_params
,
124 'Mandatory key(s) missing from params array: note');
128 * Check create with partial params
131 function testCreateWithoutEntityId() {
132 unset($this->_params
['entity_id']);
133 $result = $this->callAPIFailure('note', 'create', $this->_params
,
134 'Mandatory key(s) missing from params array: entity_id');
138 * Check create with partially empty params
141 function testCreateWithEmptyEntityId() {
142 $this->_params
['entity_id'] = "";
143 $result = $this->callAPIFailure('note', 'create', $this->_params
,
144 'Mandatory key(s) missing from params array: entity_id');
148 * Check civicrm_note_create
150 function testCreate() {
152 $result = $this->callAPIAndDocument('note', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
153 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note', 'in line ' . __LINE__
);
154 $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__
);
156 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
157 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
159 'id' => $result['id'], );
160 $this->noteDelete($note);
163 function testCreateWithApostropheInString() {
165 'entity_table' => 'civicrm_contact',
166 'entity_id' => $this->_contactID
,
167 'note' => "Hello!!! ' testing Note",
168 'contact_id' => $this->_contactID
,
169 'modified_date' => '2011-01-31',
170 'subject' => "With a '",
171 'sequential' => 1, );
172 $result = $this->callAPISuccess('Note', 'Create', $params);
173 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
174 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note", 'in line ' . __LINE__
);
175 $this->assertEquals($result['values'][0]['subject'], "With a '", 'in line ' . __LINE__
);
176 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
180 'id' => $result['id'], );
181 $this->noteDelete($note);
185 * Check civicrm_note_create - tests used of default set to now
187 function testCreateWithoutModifiedDate() {
188 unset($this->_params
['modified_date']);
189 $apiResult = $this->callAPISuccess('note', 'create', $this->_params
);
190 $this->assertAPISuccess($apiResult);
191 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
192 $this->noteDelete(array(
193 'id' => $apiResult['id'], ));
197 ///////////////// civicrm_note_update methods
200 * Check update with empty parameter array
201 * Please don't copy & paste this - is of marginal value
202 * better to put time into the function on Syntax Conformance class that tests this
204 function testUpdateWithEmptyParams() {
205 $note = $this->callAPIFailure('note', 'create', array());
209 * Check update with missing parameter (contact id)
212 function testUpdateWithoutContactId() {
214 'entity_id' => $this->_contactID
,
215 'entity_table' => 'civicrm_contact', );
216 $note = $this->callAPIFailure('note', 'create', $params,
217 'Mandatory key(s) missing from params array: note'
222 * Check civicrm_note_update
224 function testUpdate() {
226 'id' => $this->_noteID
,
227 'contact_id' => $this->_contactID
,
229 'subject' => 'Hello World', );
232 $this->callAPISuccess('note', 'create', $params);
233 $note = $this->callAPISuccess('Note', 'Get', array());
234 $this->assertEquals($note['id'], $this->_noteID
, 'in line ' . __LINE__
);
235 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
, 'in line ' . __LINE__
);
236 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact', 'in line ' . __LINE__
);
237 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject'], 'in line ' . __LINE__
);
238 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note'], 'in line ' . __LINE__
);
241 ///////////////// civicrm_note_delete methods
245 * Check delete with empty parametes array
248 function testDeleteWithEmptyParams() {
249 $deleteNote = $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id');
253 * Check delete with wrong id
256 function testDeleteWithWrongID() {
260 $deleteNote = $this->callAPIFailure('note', 'delete', $params
261 , 'Mandatory key(s) missing from params array: id');
265 * Check civicrm_note_delete
267 function testDelete() {
268 $additionalNote = $this->noteCreate($this->_contactID
);
271 'id' => $additionalNote['id'],
274 $result = $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
279 * Test civicrm_activity_create() using example code
281 function testNoteCreateExample() {
282 require_once 'api/v3/examples/NoteCreate.php';
283 $result = UF_match_get_example();
284 $expectedResult = UF_match_get_expectedresult();
285 $this->assertEquals($result, $expectedResult);