0cf6fc488dc52b2f212a1dbda5ceadf5298dbbe0
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',);
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
68 public function testGetWithEmptyParams() {
69 $this->callAPISuccess('note', 'get', array());
73 * Check retrieve note with missing patrameters
76 public function testGetWithoutEntityId() {
78 'entity_table' => 'civicrm_contact',
80 $note = $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 $result = $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__
, __FILE__
);
96 ///////////////// civicrm_note_create methods
99 * Check create with empty parameter array
102 public function testCreateWithEmptyNoteField() {
103 $this->_params
['note'] = "";
104 $result = $this->callAPIFailure('note', 'create', $this->_params
,
105 'Mandatory key(s) missing from params array: note');
109 * Check create with partial params
112 public function testCreateWithoutEntityId() {
113 unset($this->_params
['entity_id']);
114 $result = $this->callAPIFailure('note', 'create', $this->_params
,
115 'Mandatory key(s) missing from params array: entity_id');
119 * Check create with partially empty params
122 public function testCreateWithEmptyEntityId() {
123 $this->_params
['entity_id'] = "";
124 $result = $this->callAPIFailure('note', 'create', $this->_params
,
125 'Mandatory key(s) missing from params array: entity_id');
129 * Check civicrm_note_create
131 public function testCreate() {
133 $result = $this->callAPIAndDocument('note', 'create', $this->_params
, __FUNCTION__
, __FILE__
);
134 $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note', 'in line ' . __LINE__
);
135 $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__
);
137 $this->assertArrayHasKey('id', $result);
139 'id' => $result['id'],);
140 $this->noteDelete($note);
143 public function testCreateWithApostropheInString() {
145 'entity_table' => 'civicrm_contact',
146 'entity_id' => $this->_contactID
,
147 'note' => "Hello!!! ' testing Note",
148 'contact_id' => $this->_contactID
,
149 'modified_date' => '2011-01-31',
150 'subject' => "With a '",
152 $result = $this->callAPISuccess('Note', 'Create', $params);
153 $this->assertAPISuccess($result, 'in line ' . __LINE__
);
154 $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note", 'in line ' . __LINE__
);
155 $this->assertEquals($result['values'][0]['subject'], "With a '", 'in line ' . __LINE__
);
156 $this->assertArrayHasKey('id', $result, 'in line ' . __LINE__
);
160 'id' => $result['id'],);
161 $this->noteDelete($note);
165 * Check civicrm_note_create - tests used of default set to now
167 public function testCreateWithoutModifiedDate() {
168 unset($this->_params
['modified_date']);
169 $apiResult = $this->callAPISuccess('note', 'create', $this->_params
);
170 $this->assertAPISuccess($apiResult);
171 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date'])));
172 $this->noteDelete(array(
173 'id' => $apiResult['id'],));
177 ///////////////// civicrm_note_update methods
180 * Check update with empty parameter array
181 * Please don't copy & paste this - is of marginal value
182 * better to put time into the function on Syntax Conformance class that tests this
184 public function testUpdateWithEmptyParams() {
185 $note = $this->callAPIFailure('note', 'create', array());
189 * Check update with missing parameter (contact id)
192 public function testUpdateWithoutContactId() {
194 'entity_id' => $this->_contactID
,
195 'entity_table' => 'civicrm_contact',);
196 $note = $this->callAPIFailure('note', 'create', $params,
197 'Mandatory key(s) missing from params array: note'
202 * Check civicrm_note_update
204 public function testUpdate() {
206 'id' => $this->_noteID
,
207 'contact_id' => $this->_contactID
,
209 'subject' => 'Hello World',);
212 $this->callAPISuccess('note', 'create', $params);
213 $note = $this->callAPISuccess('Note', 'Get', array());
214 $this->assertEquals($note['id'], $this->_noteID
, 'in line ' . __LINE__
);
215 $this->assertEquals($note['values'][$this->_noteID
]['entity_id'], $this->_contactID
, 'in line ' . __LINE__
);
216 $this->assertEquals($note['values'][$this->_noteID
]['entity_table'], 'civicrm_contact', 'in line ' . __LINE__
);
217 $this->assertEquals('Hello World', $note['values'][$this->_noteID
]['subject'], 'in line ' . __LINE__
);
218 $this->assertEquals('Note1', $note['values'][$this->_noteID
]['note'], 'in line ' . __LINE__
);
221 ///////////////// civicrm_note_delete methods
225 * Check delete with empty parametes array
228 public function testDeleteWithEmptyParams() {
229 $deleteNote = $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id');
233 * Check delete with wrong id
236 public function testDeleteWithWrongID() {
240 $deleteNote = $this->callAPIFailure('note', 'delete', $params, 'Mandatory key(s) missing from params array: id');
244 * Check civicrm_note_delete
246 public function testDelete() {
247 $additionalNote = $this->noteCreate($this->_contactID
);
250 'id' => $additionalNote['id'],
253 $result = $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__
, __FILE__
);
258 * Test civicrm_activity_create() using example code
260 function testNoteCreateExample() {
261 require_once 'api/v3/examples/Note/Create.php';
262 $result = UF_match_get_example();
263 $expectedResult = UF_match_get_expectedresult();
264 $this->assertEquals($result, $expectedResult);