3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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;
46 function __construct() {
47 parent
::__construct();
55 'name' => 'Note Create',
56 'description' => 'Test all Note Create API methods.',
57 'group' => 'CiviCRM API Tests',
63 $this->_apiversion
= 3;
64 // Connect to the database
67 $this->_contactID
= $this->organizationCreate(NULL);
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',
75 'subject' => 'Test Note', );
76 $this->_note
= $this->noteCreate($this->_contactID
);
77 $this->_noteID
= $this->_note
['id'];
81 $tablesToTruncate = array(
82 'civicrm_note', 'civicrm_contact',
84 $this->quickCleanup($tablesToTruncate);
87 ///////////////// civicrm_note_get methods
90 * check retrieve note with empty parameter array
93 function testGetWithEmptyParams() {
94 $this->callAPISuccess('note', 'get', array());
98 * check retrieve note with missing patrameters
101 function testGetWithoutEntityId() {
103 'entity_table' => 'civicrm_contact',
105 $note = $this->callAPISuccess('note', 'get', $params);
109 * check civicrm_note_get
112 $entityId = $this->_noteID
;
114 'entity_table' => 'civicrm_contact',
115 'entity_id' => $entityId,
117 $result = $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
121 ///////////////// civicrm_note_create methods
124 * Check create with empty parameter array
127 function testCreateWithEmptyNoteField() {
128 $this->_params
['note'] = "";
129 $result = $this->callAPIFailure('note', 'create', $this->_params
,
130 'Mandatory key(s) missing from params array: note');
134 * Check create with partial params
137 function testCreateWithoutEntityId() {
138 unset($this->_params
['entity_id']);
139 $result = $this->callAPIFailure('note', 'create', $this->_params
,
140 'Mandatory key(s) missing from params array: entity_id');
144 * Check create with partially empty params
147 function testCreateWithEmptyEntityId() {
148 $this->_params
['entity_id'] = "";
149 $result = $this->callAPIFailure('note', 'create', $this->_params
,
150 'Mandatory key(s) missing from params array: entity_id');
154 * Check civicrm_note_create
156 function testCreate() {
158 $result = $this->callAPIAndDocument('note', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
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__
);
162 $this->assertArrayHasKey('id', $result);
164 'id' => $result['id'], );
165 $this->noteDelete($note);
168 function testCreateWithApostropheInString() {
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 '",
176 'sequential' => 1, );
177 $result = $this->callAPISuccess('Note', 'Create', $params);
178 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
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__
);
185 'id' => $result['id'], );
186 $this->noteDelete($note);
190 * Check civicrm_note_create - tests used of default set to now
192 function testCreateWithoutModifiedDate() {
193 unset($this->_params
['modified_date']);
194 $apiResult = $this->callAPISuccess('note', 'create', $this->_params
);
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(
198 'id' => $apiResult['id'], ));
202 ///////////////// civicrm_note_update methods
205 * Check update with empty parameter array
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
209 function testUpdateWithEmptyParams() {
210 $note = $this->callAPIFailure('note', 'create', array());
214 * Check update with missing parameter (contact id)
217 function testUpdateWithoutContactId() {
219 'entity_id' => $this->_contactID
,
220 'entity_table' => 'civicrm_contact', );
221 $note = $this->callAPIFailure('note', 'create', $params,
222 'Mandatory key(s) missing from params array: note'
227 * Check civicrm_note_update
229 function testUpdate() {
231 'id' => $this->_noteID
,
232 'contact_id' => $this->_contactID
,
234 'subject' => 'Hello World', );
237 $this->callAPISuccess('note', 'create', $params);
238 $note = $this->callAPISuccess('Note', 'Get', array());
239 $this->assertEquals($note['id'], $this->_noteID
, 'in line ' . __LINE__
);
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__
);
246 ///////////////// civicrm_note_delete methods
250 * Check delete with empty parametes array
253 function testDeleteWithEmptyParams() {
254 $deleteNote = $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id');
258 * Check delete with wrong id
261 function testDeleteWithWrongID() {
265 $deleteNote = $this->callAPIFailure('note', 'delete', $params
266 , 'Mandatory key(s) missing from params array: id');
270 * Check civicrm_note_delete
272 function testDelete() {
273 $additionalNote = $this->noteCreate($this->_contactID
);
276 'id' => $additionalNote['id'],
279 $result = $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
284 * Test civicrm_activity_create() using example code
286 function testNoteCreateExample() {
287 require_once 'api/v3/examples/Note/Create.php';
288 $result = UF_match_get_example();
289 $expectedResult = UF_match_get_expectedresult();
290 $this->assertEquals($result, $expectedResult);