3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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;
42 public function setUp() {
44 $this->_apiversion
= 3;
45 // Connect to the database
47 $this->useTransaction(TRUE);
49 $this->_contactID
= $this->organizationCreate(NULL);
51 $this->_params
= array(
52 'entity_table' => 'civicrm_contact',
53 'entity_id' => $this->_contactID
,
54 'note' => 'Hello!!! m testing Note',
55 'contact_id' => $this->_contactID
,
56 'modified_date' => '2011-01-31',
57 'subject' => 'Test Note',
59 $this->_note
= $this->noteCreate($this->_contactID
);
60 $this->_noteID
= $this->_note
['id'];
63 ///////////////// civicrm_note_get methods
66 * Check retrieve note with empty parameter array
69 public function testGetWithEmptyParams() {
70 $this->callAPISuccess('note', 'get', array());
74 * Check retrieve note with missing patrameters
77 public function testGetWithoutEntityId() {
79 'entity_table' => 'civicrm_contact',
81 $note = $this->callAPISuccess('note', 'get', $params);
85 * Check civicrm_note_get
87 public function testGet() {
88 $entityId = $this->_noteID
;
90 'entity_table' => 'civicrm_contact',
91 'entity_id' => $entityId,
93 $result = $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
97 ///////////////// civicrm_note_create methods
100 * Check create with empty parameter array
103 public function testCreateWithEmptyNoteField() {
104 $this->_params
['note'] = "";
105 $result = $this->callAPIFailure('note', 'create', $this->_params
,
106 'Mandatory key(s) missing from params array: note');
110 * Check create with partial params
113 public function testCreateWithoutEntityId() {
114 unset($this->_params
['entity_id']);
115 $result = $this->callAPIFailure('note', 'create', $this->_params
,
116 'Mandatory key(s) missing from params array: entity_id');
120 * Check create with partially empty params
123 public function testCreateWithEmptyEntityId() {
124 $this->_params
['entity_id'] = "";
125 $result = $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', 'in line ' . __LINE__
);
136 $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__
);
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, 'in line ' . __LINE__
);
157 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note", 'in line ' . __LINE__
);
158 $this->assertEquals($result['values'][0]['subject'], "With a '", 'in line ' . __LINE__
);
159 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
163 'id' => $result['id'],
165 $this->noteDelete($note);
169 * Check civicrm_note_create - tests used of default set to now
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 ///////////////// civicrm_note_update methods
185 * 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 $note = $this->callAPIFailure('note', 'create', array());
194 * Check update with missing parameter (contact id)
197 public function testUpdateWithoutContactId() {
199 'entity_id' => $this->_contactID
,
200 'entity_table' => 'civicrm_contact',
202 $note = $this->callAPIFailure('note', 'create', $params,
203 'Mandatory key(s) missing from params array: note'
208 * Check civicrm_note_update
210 public function testUpdate() {
212 'id' => $this->_noteID
,
213 'contact_id' => $this->_contactID
,
215 'subject' => 'Hello World',
219 $this->callAPISuccess('note', 'create', $params);
220 $note = $this->callAPISuccess('Note', 'Get', array());
221 $this->assertEquals($note['id'], $this->_noteID
, 'in line ' . __LINE__
);
222 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
, 'in line ' . __LINE__
);
223 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact', 'in line ' . __LINE__
);
224 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject'], 'in line ' . __LINE__
);
225 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note'], 'in line ' . __LINE__
);
228 ///////////////// civicrm_note_delete methods
232 * Check delete with empty parametes array
235 public function testDeleteWithEmptyParams() {
236 $deleteNote = $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id');
240 * Check delete with wrong id
243 public function testDeleteWithWrongID() {
247 $deleteNote = $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 $result = $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
266 * Test civicrm_activity_create() using example code
268 function testNoteCreateExample() {
269 require_once 'api/v3/examples/Note/Create.php';
270 $result = UF_match_get_example();
271 $expectedResult = UF_match_get_expectedresult();
272 $this->assertEquals($result, $expectedResult);