3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 +--------------------------------------------------------------------+
28 require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
31 * Class contains api test cases for "civicrm_note"
33 class api_v3_NoteTest
extends CiviUnitTestCase
{
35 protected $_apiversion;
36 protected $_contactID;
41 public function setUp() {
43 $this->_apiversion
= 3;
44 // Connect to the database.
46 $this->useTransaction(TRUE);
48 $this->_contactID
= $this->organizationCreate(NULL);
50 $this->_params
= array(
51 'entity_table' => 'civicrm_contact',
52 'entity_id' => $this->_contactID
,
53 'note' => 'Hello!!! m testing Note',
54 'contact_id' => $this->_contactID
,
55 'modified_date' => '2011-01-31',
56 'subject' => 'Test Note',
58 $this->_note
= $this->noteCreate($this->_contactID
);
59 $this->_noteID
= $this->_note
['id'];
62 ///////////////// civicrm_note_get methods
65 * Check retrieve note with empty parameter array.
69 public function testGetWithEmptyParams() {
70 $this->callAPISuccess('note', 'get', array());
74 * Check retrieve note with missing parameters.
78 public function testGetWithoutEntityId() {
80 'entity_table' => 'civicrm_contact',
82 $this->callAPISuccess('note', 'get', $params);
86 * Check civicrm_note get.
88 public function testGet() {
89 $entityId = $this->_noteID
;
91 'entity_table' => 'civicrm_contact',
92 'entity_id' => $entityId,
94 $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
98 * Check create with empty parameter array.
102 public function testCreateWithEmptyNoteField() {
103 $this->_params
['note'] = "";
104 $this->callAPIFailure('note', 'create', $this->_params
,
105 'Mandatory key(s) missing from params array: note'
110 * Check create with partial params.
114 public function testCreateWithoutEntityId() {
115 unset($this->_params
['entity_id']);
116 $this->callAPIFailure('note', 'create', $this->_params
,
117 'Mandatory key(s) missing from params array: entity_id');
121 * Check create with partially empty params.
125 public function testCreateWithEmptyEntityId() {
126 $this->_params
['entity_id'] = "";
127 $this->callAPIFailure('note', 'create', $this->_params
,
128 'Mandatory key(s) missing from params array: entity_id');
132 * Check civicrm note create.
134 public function testCreate() {
136 $result = $this->callAPIAndDocument('note', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
137 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note', 'in line ' . __LINE__
);
138 $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__
);
140 $this->assertArrayHasKey('id', $result);
142 'id' => $result['id'],
144 $this->noteDelete($note);
147 public function testCreateWithApostropheInString() {
149 'entity_table' => 'civicrm_contact',
150 'entity_id' => $this->_contactID
,
151 'note' => "Hello!!! ' testing Note",
152 'contact_id' => $this->_contactID
,
153 'modified_date' => '2011-01-31',
154 'subject' => "With a '",
157 $result = $this->callAPISuccess('Note', 'Create', $params);
158 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
159 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note", 'in line ' . __LINE__
);
160 $this->assertEquals($result['values'][0]['subject'], "With a '", 'in line ' . __LINE__
);
161 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
165 'id' => $result['id'],
167 $this->noteDelete($note);
171 * Check civicrm_note_create - tests used of default set to .
173 public function testCreateWithoutModifiedDate() {
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'])));
178 $this->noteDelete(array(
179 'id' => $apiResult['id'],
184 * Check update with empty parameter array.
186 * Please don't copy & paste this - is of marginal value
187 * better to put time into the function on Syntax Conformance class that tests this
189 public function testUpdateWithEmptyParams() {
190 $this->callAPIFailure('note', 'create', array());
194 * Check update with missing parameter (contact id).
198 public function testUpdateWithoutContactId() {
200 'entity_id' => $this->_contactID
,
201 'entity_table' => 'civicrm_contact',
203 $this->callAPIFailure('note', 'create', $params,
204 'Mandatory key(s) missing from params array: note'
209 * Check civicrm_note update.
211 public function testUpdate() {
213 'id' => $this->_noteID
,
214 'contact_id' => $this->_contactID
,
216 'subject' => 'Hello World',
220 $this->callAPISuccess('note', 'create', $params);
221 $note = $this->callAPISuccess('Note', 'Get', array());
222 $this->assertEquals($note['id'], $this->_noteID
, 'in line ' . __LINE__
);
223 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
, 'in line ' . __LINE__
);
224 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact', 'in line ' . __LINE__
);
225 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject'], 'in line ' . __LINE__
);
226 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note'], 'in line ' . __LINE__
);
230 * Check delete with empty parameters array.
234 public function testDeleteWithEmptyParams() {
235 $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id');
239 * Check delete with wrong id.
243 public function testDeleteWithWrongID() {
247 $this->callAPIFailure('note', 'delete', $params, 'Mandatory key(s) missing from params array: id');
251 * Check civicrm_note delete.
253 public function testDelete() {
254 $additionalNote = $this->noteCreate($this->_contactID
);
257 'id' => $additionalNote['id'],
260 $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
266 * Test civicrm note create() using example code.
268 function testNoteCreateExample() {
269 require_once 'api/v3/examples/Note/Create.php';
270 $result = Note_get_example();
271 $expectedResult = Note_get_expectedresult();
272 $this->assertEquals($result, $expectedResult);