3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class contains api test cases for "civicrm_note"
16 class api_v3_NoteTest
extends CiviUnitTestCase
{
18 protected $_contactID;
23 public function setUp() {
25 // Connect to the database.
27 $this->useTransaction(TRUE);
29 $this->_contactID
= $this->organizationCreate(NULL);
32 'entity_table' => 'civicrm_contact',
33 'entity_id' => $this->_contactID
,
34 'note' => 'Hello!!! m testing Note',
35 'contact_id' => $this->_contactID
,
36 'modified_date' => '2011-01-31',
37 'subject' => 'Test Note',
39 $this->_note
= $this->noteCreate($this->_contactID
);
40 $this->_noteID
= $this->_note
['id'];
43 ///////////////// civicrm_note_get methods
46 * Check retrieve note with empty parameter array.
50 * @dataProvider versionThreeAndFour
52 public function testGetWithEmptyParams($version) {
53 $this->_apiversion
= $version;
54 $this->callAPISuccess('note', 'get', []);
58 * Check retrieve note with missing parameters.
62 * @dataProvider versionThreeAndFour
64 public function testGetWithoutEntityId($version) {
65 $this->_apiversion
= $version;
67 'entity_table' => 'civicrm_contact',
69 $this->callAPISuccess('note', 'get', $params);
73 * Check civicrm_note get.
75 * @dataProvider versionThreeAndFour
77 public function testGet($version) {
78 $this->_apiversion
= $version;
79 $entityId = $this->_noteID
;
81 'entity_table' => 'civicrm_contact',
82 'entity_id' => $entityId,
84 $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
88 * Check create with empty parameter array.
92 * @dataProvider versionThreeAndFour
94 public function testCreateWithEmptyNoteField($version) {
95 $this->_apiversion
= $version;
96 $this->_params
['note'] = "";
97 $this->callAPIFailure('note', 'create', $this->_params
,
103 * Check create with partial params.
106 * @param int $version
107 * @dataProvider versionThreeAndFour
109 public function testCreateWithoutEntityId($version) {
110 $this->_apiversion
= $version;
111 unset($this->_params
['entity_id']);
112 $this->callAPIFailure('note', 'create', $this->_params
,
117 * Check create with partially empty params.
120 * @param int $version
121 * @dataProvider versionThreeAndFour
123 public function testCreateWithEmptyEntityId($version) {
124 $this->_apiversion
= $version;
125 $this->_params
['entity_id'] = "";
126 $this->callAPIFailure('note', 'create', $this->_params
,
131 * Check civicrm note create.
132 * @param int $version
133 * @dataProvider versionThreeAndFour
135 public function testCreate($version) {
136 $this->_apiversion
= $version;
138 $result = $this->callAPIAndDocument('note', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
139 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note');
140 $this->assertEquals(date('Y-m-d', strtotime($this->_params
['modified_date'])), date('Y-m-d', strtotime($result['values'][$result['id']]['modified_date'])));
142 $this->assertArrayHasKey('id', $result);
146 * @param int $version
147 * @dataProvider versionThreeAndFour
149 public function testCreateWithApostropheInString($version) {
150 $this->_apiversion
= $version;
152 'entity_table' => 'civicrm_contact',
153 'entity_id' => $this->_contactID
,
154 'note' => "Hello!!! ' testing Note",
155 'contact_id' => $this->_contactID
,
156 'modified_date' => '2011-01-31',
157 'subject' => "With a '",
160 $result = $this->callAPISuccess('Note', 'Create', $params);
161 $this->assertAPISuccess($result);
162 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note");
163 $this->assertEquals($result['values'][0]['subject'], "With a '");
164 $this->assertArrayHasKey('id', $result);
168 * Check civicrm_note_create - tests used of default set to .
169 * @param int $version
170 * @dataProvider versionThreeAndFour
172 public function testCreateWithoutModifiedDate($version) {
173 $this->_apiversion
= $version;
174 unset($this->_params
['modified_date']);
175 $apiResult = $this->callAPISuccess('note', 'create', $this->_params
);
176 $this->assertAPISuccess($apiResult);
177 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
181 * Check update with empty parameter array.
183 * Please don't copy & paste this - is of marginal value
184 * better to put time into the function on Syntax Conformance class that tests this
185 * @param int $version
186 * @dataProvider versionThreeAndFour
188 public function testUpdateWithEmptyParams($version) {
189 $this->_apiversion
= $version;
190 $this->callAPIFailure('note', 'create', []);
194 * Check update with missing parameter (contact id).
197 * @param int $version
198 * @dataProvider versionThreeAndFour
200 public function testUpdateWithoutContactId($version) {
201 $this->_apiversion
= $version;
203 'entity_id' => $this->_contactID
,
204 'entity_table' => 'civicrm_contact',
206 $this->callAPIFailure('note', 'create', $params,
212 * Check civicrm_note update.
213 * @param int $version
214 * @dataProvider versionThreeAndFour
216 public function testUpdate($version) {
217 $this->_apiversion
= $version;
219 'id' => $this->_noteID
,
220 'contact_id' => $this->_contactID
,
222 'subject' => 'Hello World',
226 $this->callAPISuccess('note', 'create', $params);
227 $note = $this->callAPISuccess('Note', 'Get', []);
228 $this->assertEquals($note['id'], $this->_noteID
);
229 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
);
230 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact');
231 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject']);
232 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note']);
236 * Check delete with empty parameters array.
240 public function testDeleteWithEmptyParams() {
241 $this->callAPIFailure('note', 'delete', [], 'Mandatory key(s) missing from params array: id');
245 * Check delete with wrong id.
248 * @param int $version
249 * @dataProvider versionThreeAndFour
251 public function testDeleteWithWrongID($version) {
252 $this->_apiversion
= $version;
256 $this->callAPIFailure('note', 'delete', $params, 'Note');
260 * Check civicrm_note delete.
261 * @param int $version
262 * @dataProvider versionThreeAndFour
264 public function testDelete($version) {
265 $this->_apiversion
= $version;
266 $additionalNote = $this->noteCreate($this->_contactID
);
269 'id' => $additionalNote['id'],
272 $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
275 public function testNoteJoin() {
276 $org = $this->callAPISuccess('Contact', 'create', [
277 'contact_type' => 'Organization',
278 'organization_name' => 'Org123',
279 'api.Note.create' => [
280 'note' => 'Hello join',
283 // Fetch contact info via join
284 $result = $this->callAPISuccessGetSingle('Note', [
285 'return' => ["entity_id.organization_name", "note"],
286 'entity_id' => $org['id'],
287 'entity_table' => "civicrm_contact",
289 $this->assertEquals('Org123', $result['entity_id.organization_name']);
290 $this->assertEquals('Hello join', $result['note']);
291 // This should return no results by restricting contact_type
292 $result = $this->callAPISuccess('Note', 'get', [
293 'return' => ["entity_id.organization_name"],
294 'entity_id' => $org['id'],
295 'entity_table' => "civicrm_contact",
296 'entity_id.contact_type' => "Individual",
298 $this->assertEquals(0, $result['count']);
304 * Test civicrm note create() using example code.
306 function testNoteCreateExample() {
307 require_once 'api/v3/examples/Note/Create.ex.php';
308 $result = Note_get_example();
309 $expectedResult = Note_get_expectedresult();
310 $this->assertEquals($result, $expectedResult);