3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
29 * Class contains api test cases for "civicrm_note"
31 class api_v3_NoteTest
extends CiviUnitTestCase
{
33 protected $_apiversion;
34 protected $_contactID;
39 public function setUp() {
41 $this->_apiversion
= 3;
42 // Connect to the database.
44 $this->useTransaction(TRUE);
46 $this->_contactID
= $this->organizationCreate(NULL);
48 $this->_params
= array(
49 'entity_table' => 'civicrm_contact',
50 'entity_id' => $this->_contactID
,
51 'note' => 'Hello!!! m testing Note',
52 'contact_id' => $this->_contactID
,
53 'modified_date' => '2011-01-31',
54 'subject' => 'Test Note',
56 $this->_note
= $this->noteCreate($this->_contactID
);
57 $this->_noteID
= $this->_note
['id'];
60 ///////////////// civicrm_note_get methods
63 * Check retrieve note with empty parameter array.
67 public function testGetWithEmptyParams() {
68 $this->callAPISuccess('note', 'get', array());
72 * Check retrieve note with missing parameters.
76 public function testGetWithoutEntityId() {
78 'entity_table' => 'civicrm_contact',
80 $this->callAPISuccess('note', 'get', $params);
84 * Check civicrm_note get.
86 public function testGet() {
87 $entityId = $this->_noteID
;
89 'entity_table' => 'civicrm_contact',
90 'entity_id' => $entityId,
92 $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
96 * Check create with empty parameter array.
100 public function testCreateWithEmptyNoteField() {
101 $this->_params
['note'] = "";
102 $this->callAPIFailure('note', 'create', $this->_params
,
103 'Mandatory key(s) missing from params array: note'
108 * Check create with partial params.
112 public function testCreateWithoutEntityId() {
113 unset($this->_params
['entity_id']);
114 $this->callAPIFailure('note', 'create', $this->_params
,
115 'Mandatory key(s) missing from params array: entity_id');
119 * Check create with partially empty params.
123 public function testCreateWithEmptyEntityId() {
124 $this->_params
['entity_id'] = "";
125 $this->callAPIFailure('note', 'create', $this->_params
,
126 'Mandatory key(s) missing from params array: entity_id');
130 * Check civicrm note create.
132 public function testCreate() {
134 $result = $this->callAPIAndDocument('note', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
135 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note');
136 $this->assertEquals(date('Y-m-d', strtotime($this->_params
['modified_date'])), date('Y-m-d', strtotime($result['values'][$result['id']]['modified_date'])));
138 $this->assertArrayHasKey('id', $result);
140 'id' => $result['id'],
142 $this->noteDelete($note);
145 public function testCreateWithApostropheInString() {
147 'entity_table' => 'civicrm_contact',
148 'entity_id' => $this->_contactID
,
149 'note' => "Hello!!! ' testing Note",
150 'contact_id' => $this->_contactID
,
151 'modified_date' => '2011-01-31',
152 'subject' => "With a '",
155 $result = $this->callAPISuccess('Note', 'Create', $params);
156 $this->assertAPISuccess($result);
157 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note");
158 $this->assertEquals($result['values'][0]['subject'], "With a '");
159 $this->assertArrayHasKey('id', $result);
163 'id' => $result['id'],
165 $this->noteDelete($note);
169 * Check civicrm_note_create - tests used of default set to .
171 public function testCreateWithoutModifiedDate() {
172 unset($this->_params
['modified_date']);
173 $apiResult = $this->callAPISuccess('note', 'create', $this->_params
);
174 $this->assertAPISuccess($apiResult);
175 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
176 $this->noteDelete(array(
177 'id' => $apiResult['id'],
182 * Check update with empty parameter array.
184 * Please don't copy & paste this - is of marginal value
185 * better to put time into the function on Syntax Conformance class that tests this
187 public function testUpdateWithEmptyParams() {
188 $this->callAPIFailure('note', 'create', array());
192 * Check update with missing parameter (contact id).
196 public function testUpdateWithoutContactId() {
198 'entity_id' => $this->_contactID
,
199 'entity_table' => 'civicrm_contact',
201 $this->callAPIFailure('note', 'create', $params,
202 'Mandatory key(s) missing from params array: note'
207 * Check civicrm_note update.
209 public function testUpdate() {
211 'id' => $this->_noteID
,
212 'contact_id' => $this->_contactID
,
214 'subject' => 'Hello World',
218 $this->callAPISuccess('note', 'create', $params);
219 $note = $this->callAPISuccess('Note', 'Get', array());
220 $this->assertEquals($note['id'], $this->_noteID
);
221 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
);
222 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact');
223 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject']);
224 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note']);
228 * Check delete with empty parameters array.
232 public function testDeleteWithEmptyParams() {
233 $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id');
237 * Check delete with wrong id.
241 public function testDeleteWithWrongID() {
245 $this->callAPIFailure('note', 'delete', $params, 'Mandatory key(s) missing from params array: id');
249 * Check civicrm_note delete.
251 public function testDelete() {
252 $additionalNote = $this->noteCreate($this->_contactID
);
255 'id' => $additionalNote['id'],
258 $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
264 * Test civicrm note create() using example code.
266 function testNoteCreateExample() {
267 require_once 'api/v3/examples/Note/Create.php';
268 $result = Note_get_example();
269 $expectedResult = Note_get_expectedresult();
270 $this->assertEquals($result, $expectedResult);