3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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"
32 class api_v3_NoteTest
extends CiviUnitTestCase
{
34 protected $_contactID;
39 public function setUp() {
41 // Connect to the database.
43 $this->useTransaction(TRUE);
45 $this->_contactID
= $this->organizationCreate(NULL);
48 'entity_table' => 'civicrm_contact',
49 'entity_id' => $this->_contactID
,
50 'note' => 'Hello!!! m testing Note',
51 'contact_id' => $this->_contactID
,
52 'modified_date' => '2011-01-31',
53 'subject' => 'Test Note',
55 $this->_note
= $this->noteCreate($this->_contactID
);
56 $this->_noteID
= $this->_note
['id'];
59 ///////////////// civicrm_note_get methods
62 * Check retrieve note with empty parameter array.
66 * @dataProvider versionThreeAndFour
68 public function testGetWithEmptyParams($version) {
69 $this->_apiversion
= $version;
70 $this->callAPISuccess('note', 'get', []);
74 * Check retrieve note with missing parameters.
78 * @dataProvider versionThreeAndFour
80 public function testGetWithoutEntityId($version) {
81 $this->_apiversion
= $version;
83 'entity_table' => 'civicrm_contact',
85 $this->callAPISuccess('note', 'get', $params);
89 * Check civicrm_note get.
91 * @dataProvider versionThreeAndFour
93 public function testGet($version) {
94 $this->_apiversion
= $version;
95 $entityId = $this->_noteID
;
97 'entity_table' => 'civicrm_contact',
98 'entity_id' => $entityId,
100 $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
104 * Check create with empty parameter array.
107 * @param int $version
108 * @dataProvider versionThreeAndFour
110 public function testCreateWithEmptyNoteField($version) {
111 $this->_apiversion
= $version;
112 $this->_params
['note'] = "";
113 $this->callAPIFailure('note', 'create', $this->_params
,
119 * Check create with partial params.
122 * @param int $version
123 * @dataProvider versionThreeAndFour
125 public function testCreateWithoutEntityId($version) {
126 $this->_apiversion
= $version;
127 unset($this->_params
['entity_id']);
128 $this->callAPIFailure('note', 'create', $this->_params
,
133 * Check create with partially empty params.
136 * @param int $version
137 * @dataProvider versionThreeAndFour
139 public function testCreateWithEmptyEntityId($version) {
140 $this->_apiversion
= $version;
141 $this->_params
['entity_id'] = "";
142 $this->callAPIFailure('note', 'create', $this->_params
,
147 * Check civicrm note create.
148 * @param int $version
149 * @dataProvider versionThreeAndFour
151 public function testCreate($version) {
152 $this->_apiversion
= $version;
154 $result = $this->callAPIAndDocument('note', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
155 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note');
156 $this->assertEquals(date('Y-m-d', strtotime($this->_params
['modified_date'])), date('Y-m-d', strtotime($result['values'][$result['id']]['modified_date'])));
158 $this->assertArrayHasKey('id', $result);
162 * @param int $version
163 * @dataProvider versionThreeAndFour
165 public function testCreateWithApostropheInString($version) {
166 $this->_apiversion
= $version;
168 'entity_table' => 'civicrm_contact',
169 'entity_id' => $this->_contactID
,
170 'note' => "Hello!!! ' testing Note",
171 'contact_id' => $this->_contactID
,
172 'modified_date' => '2011-01-31',
173 'subject' => "With a '",
176 $result = $this->callAPISuccess('Note', 'Create', $params);
177 $this->assertAPISuccess($result);
178 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note");
179 $this->assertEquals($result['values'][0]['subject'], "With a '");
180 $this->assertArrayHasKey('id', $result);
184 * Check civicrm_note_create - tests used of default set to .
185 * @param int $version
186 * @dataProvider versionThreeAndFour
188 public function testCreateWithoutModifiedDate($version) {
189 $this->_apiversion
= $version;
190 unset($this->_params
['modified_date']);
191 $apiResult = $this->callAPISuccess('note', 'create', $this->_params
);
192 $this->assertAPISuccess($apiResult);
193 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
197 * Check update with empty parameter array.
199 * Please don't copy & paste this - is of marginal value
200 * better to put time into the function on Syntax Conformance class that tests this
201 * @param int $version
202 * @dataProvider versionThreeAndFour
204 public function testUpdateWithEmptyParams($version) {
205 $this->_apiversion
= $version;
206 $this->callAPIFailure('note', 'create', []);
210 * Check update with missing parameter (contact id).
213 * @param int $version
214 * @dataProvider versionThreeAndFour
216 public function testUpdateWithoutContactId($version) {
217 $this->_apiversion
= $version;
219 'entity_id' => $this->_contactID
,
220 'entity_table' => 'civicrm_contact',
222 $this->callAPIFailure('note', 'create', $params,
228 * Check civicrm_note update.
229 * @param int $version
230 * @dataProvider versionThreeAndFour
232 public function testUpdate($version) {
233 $this->_apiversion
= $version;
235 'id' => $this->_noteID
,
236 'contact_id' => $this->_contactID
,
238 'subject' => 'Hello World',
242 $this->callAPISuccess('note', 'create', $params);
243 $note = $this->callAPISuccess('Note', 'Get', []);
244 $this->assertEquals($note['id'], $this->_noteID
);
245 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
);
246 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact');
247 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject']);
248 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note']);
252 * Check delete with empty parameters array.
256 public function testDeleteWithEmptyParams() {
257 $this->callAPIFailure('note', 'delete', [], 'Mandatory key(s) missing from params array: id');
261 * Check delete with wrong id.
264 * @param int $version
265 * @dataProvider versionThreeAndFour
267 public function testDeleteWithWrongID($version) {
268 $this->_apiversion
= $version;
272 $this->callAPIFailure('note', 'delete', $params, 'Note');
276 * Check civicrm_note delete.
277 * @param int $version
278 * @dataProvider versionThreeAndFour
280 public function testDelete($version) {
281 $this->_apiversion
= $version;
282 $additionalNote = $this->noteCreate($this->_contactID
);
285 'id' => $additionalNote['id'],
288 $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
291 public function testNoteJoin() {
292 $org = $this->callAPISuccess('Contact', 'create', [
293 'contact_type' => 'Organization',
294 'organization_name' => 'Org123',
295 'api.Note.create' => [
296 'note' => 'Hello join',
299 // Fetch contact info via join
300 $result = $this->callAPISuccessGetSingle('Note', [
301 'return' => ["entity_id.organization_name", "note"],
302 'entity_id' => $org['id'],
303 'entity_table' => "civicrm_contact",
305 $this->assertEquals('Org123', $result['entity_id.organization_name']);
306 $this->assertEquals('Hello join', $result['note']);
307 // This should return no results by restricting contact_type
308 $result = $this->callAPISuccess('Note', 'get', [
309 'return' => ["entity_id.organization_name"],
310 'entity_id' => $org['id'],
311 'entity_table' => "civicrm_contact",
312 'entity_id.contact_type' => "Individual",
314 $this->assertEquals(0, $result['count']);
320 * Test civicrm note create() using example code.
322 function testNoteCreateExample() {
323 require_once 'api/v3/examples/Note/Create.ex.php';
324 $result = Note_get_example();
325 $expectedResult = Note_get_expectedresult();
326 $this->assertEquals($result, $expectedResult);