Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | /** |
29 | * Class contains api test cases for "civicrm_note" | |
acb109b7 | 30 | * @group headless |
6a488035 TO |
31 | */ |
32 | class api_v3_NoteTest extends CiviUnitTestCase { | |
33 | ||
34 | protected $_apiversion; | |
35 | protected $_contactID; | |
36 | protected $_params; | |
37 | protected $_noteID; | |
38 | protected $_note; | |
b7c9bc4c | 39 | |
00be9182 | 40 | public function setUp() { |
6a488035 TO |
41 | |
42 | $this->_apiversion = 3; | |
7fe37828 | 43 | // Connect to the database. |
6a488035 | 44 | parent::setUp(); |
bd772bfe | 45 | $this->useTransaction(TRUE); |
6a488035 TO |
46 | |
47 | $this->_contactID = $this->organizationCreate(NULL); | |
48 | ||
49 | $this->_params = array( | |
50 | 'entity_table' => 'civicrm_contact', | |
51 | 'entity_id' => $this->_contactID, | |
52 | 'note' => 'Hello!!! m testing Note', | |
53 | 'contact_id' => $this->_contactID, | |
54 | 'modified_date' => '2011-01-31', | |
92915c55 TO |
55 | 'subject' => 'Test Note', |
56 | ); | |
6a488035 TO |
57 | $this->_note = $this->noteCreate($this->_contactID); |
58 | $this->_noteID = $this->_note['id']; | |
59 | } | |
60 | ||
6a488035 TO |
61 | ///////////////// civicrm_note_get methods |
62 | ||
6a488035 | 63 | /** |
7fe37828 EM |
64 | * Check retrieve note with empty parameter array. |
65 | * | |
6a488035 TO |
66 | * Error expected |
67 | */ | |
00be9182 | 68 | public function testGetWithEmptyParams() { |
d0e1eff2 | 69 | $this->callAPISuccess('note', 'get', array()); |
6a488035 TO |
70 | } |
71 | ||
72 | /** | |
7fe37828 EM |
73 | * Check retrieve note with missing parameters. |
74 | * | |
6a488035 TO |
75 | * Error expected |
76 | */ | |
00be9182 | 77 | public function testGetWithoutEntityId() { |
6a488035 TO |
78 | $params = array( |
79 | 'entity_table' => 'civicrm_contact', | |
6a488035 | 80 | ); |
7fe37828 | 81 | $this->callAPISuccess('note', 'get', $params); |
6a488035 TO |
82 | } |
83 | ||
84 | /** | |
7fe37828 | 85 | * Check civicrm_note get. |
6a488035 | 86 | */ |
00be9182 | 87 | public function testGet() { |
6a488035 TO |
88 | $entityId = $this->_noteID; |
89 | $params = array( | |
90 | 'entity_table' => 'civicrm_contact', | |
91 | 'entity_id' => $entityId, | |
6a488035 | 92 | ); |
7fe37828 | 93 | $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
94 | } |
95 | ||
6a488035 | 96 | /** |
7fe37828 EM |
97 | * Check create with empty parameter array. |
98 | * | |
6a488035 TO |
99 | * Error Expected |
100 | */ | |
00be9182 | 101 | public function testCreateWithEmptyNoteField() { |
6a488035 | 102 | $this->_params['note'] = ""; |
7fe37828 EM |
103 | $this->callAPIFailure('note', 'create', $this->_params, |
104 | 'Mandatory key(s) missing from params array: note' | |
105 | ); | |
6a488035 TO |
106 | } |
107 | ||
108 | /** | |
7fe37828 EM |
109 | * Check create with partial params. |
110 | * | |
6a488035 TO |
111 | * Error expected |
112 | */ | |
00be9182 | 113 | public function testCreateWithoutEntityId() { |
6a488035 | 114 | unset($this->_params['entity_id']); |
7fe37828 | 115 | $this->callAPIFailure('note', 'create', $this->_params, |
b5ee049f | 116 | 'Mandatory key(s) missing from params array: entity_id'); |
6a488035 TO |
117 | } |
118 | ||
119 | /** | |
7fe37828 EM |
120 | * Check create with partially empty params. |
121 | * | |
6a488035 TO |
122 | * Error expected |
123 | */ | |
00be9182 | 124 | public function testCreateWithEmptyEntityId() { |
6a488035 | 125 | $this->_params['entity_id'] = ""; |
7fe37828 | 126 | $this->callAPIFailure('note', 'create', $this->_params, |
b5ee049f | 127 | 'Mandatory key(s) missing from params array: entity_id'); |
6a488035 TO |
128 | } |
129 | ||
130 | /** | |
7fe37828 | 131 | * Check civicrm note create. |
6a488035 | 132 | */ |
00be9182 | 133 | public function testCreate() { |
6a488035 | 134 | |
b5ee049f | 135 | $result = $this->callAPIAndDocument('note', 'create', $this->_params, __FUNCTION__, __FILE__); |
ba4a1892 TM |
136 | $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note'); |
137 | $this->assertEquals(date('Y-m-d', strtotime($this->_params['modified_date'])), date('Y-m-d', strtotime($result['values'][$result['id']]['modified_date']))); | |
6a488035 | 138 | |
61ef23bd | 139 | $this->assertArrayHasKey('id', $result); |
6a488035 | 140 | $note = array( |
92915c55 TO |
141 | 'id' => $result['id'], |
142 | ); | |
6a488035 TO |
143 | $this->noteDelete($note); |
144 | } | |
145 | ||
00be9182 | 146 | public function testCreateWithApostropheInString() { |
6a488035 TO |
147 | $params = array( |
148 | 'entity_table' => 'civicrm_contact', | |
149 | 'entity_id' => $this->_contactID, | |
150 | 'note' => "Hello!!! ' testing Note", | |
151 | 'contact_id' => $this->_contactID, | |
152 | 'modified_date' => '2011-01-31', | |
153 | 'subject' => "With a '", | |
92915c55 TO |
154 | 'sequential' => 1, |
155 | ); | |
b5ee049f | 156 | $result = $this->callAPISuccess('Note', 'Create', $params); |
a15773db | 157 | $this->assertAPISuccess($result); |
ba4a1892 TM |
158 | $this->assertEquals($result['values'][0]['note'], "Hello!!! ' testing Note"); |
159 | $this->assertEquals($result['values'][0]['subject'], "With a '"); | |
a15773db | 160 | $this->assertArrayHasKey('id', $result); |
6a488035 TO |
161 | |
162 | //CleanUP | |
163 | $note = array( | |
92915c55 TO |
164 | 'id' => $result['id'], |
165 | ); | |
6a488035 TO |
166 | $this->noteDelete($note); |
167 | } | |
168 | ||
169 | /** | |
7fe37828 | 170 | * Check civicrm_note_create - tests used of default set to . |
6a488035 | 171 | */ |
00be9182 | 172 | public function testCreateWithoutModifiedDate() { |
6a488035 | 173 | unset($this->_params['modified_date']); |
b5ee049f | 174 | $apiResult = $this->callAPISuccess('note', 'create', $this->_params); |
6a488035 TO |
175 | $this->assertAPISuccess($apiResult); |
176 | $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($apiResult['values'][$apiResult['id']]['modified_date']))); | |
177 | $this->noteDelete(array( | |
92915c55 TO |
178 | 'id' => $apiResult['id'], |
179 | )); | |
6a488035 TO |
180 | } |
181 | ||
6a488035 | 182 | /** |
7fe37828 EM |
183 | * Check update with empty parameter array. |
184 | * | |
b5ee049f | 185 | * Please don't copy & paste this - is of marginal value |
186 | * better to put time into the function on Syntax Conformance class that tests this | |
6a488035 | 187 | */ |
00be9182 | 188 | public function testUpdateWithEmptyParams() { |
7fe37828 | 189 | $this->callAPIFailure('note', 'create', array()); |
6a488035 TO |
190 | } |
191 | ||
192 | /** | |
7fe37828 EM |
193 | * Check update with missing parameter (contact id). |
194 | * | |
6a488035 TO |
195 | * Error expected |
196 | */ | |
00be9182 | 197 | public function testUpdateWithoutContactId() { |
6a488035 TO |
198 | $params = array( |
199 | 'entity_id' => $this->_contactID, | |
92915c55 TO |
200 | 'entity_table' => 'civicrm_contact', |
201 | ); | |
7fe37828 | 202 | $this->callAPIFailure('note', 'create', $params, |
b5ee049f | 203 | 'Mandatory key(s) missing from params array: note' |
6a488035 | 204 | ); |
6a488035 TO |
205 | } |
206 | ||
207 | /** | |
7fe37828 | 208 | * Check civicrm_note update. |
6a488035 | 209 | */ |
00be9182 | 210 | public function testUpdate() { |
6a488035 TO |
211 | $params = array( |
212 | 'id' => $this->_noteID, | |
213 | 'contact_id' => $this->_contactID, | |
214 | 'note' => 'Note1', | |
92915c55 TO |
215 | 'subject' => 'Hello World', |
216 | ); | |
6a488035 | 217 | |
7fe37828 | 218 | // Update Note. |
b5ee049f | 219 | $this->callAPISuccess('note', 'create', $params); |
220 | $note = $this->callAPISuccess('Note', 'Get', array()); | |
a15773db TM |
221 | $this->assertEquals($note['id'], $this->_noteID); |
222 | $this->assertEquals($note['values'][$this->_noteID]['entity_id'], $this->_contactID); | |
ba4a1892 TM |
223 | $this->assertEquals($note['values'][$this->_noteID]['entity_table'], 'civicrm_contact'); |
224 | $this->assertEquals('Hello World', $note['values'][$this->_noteID]['subject']); | |
225 | $this->assertEquals('Note1', $note['values'][$this->_noteID]['note']); | |
6a488035 TO |
226 | } |
227 | ||
6a488035 | 228 | /** |
7fe37828 EM |
229 | * Check delete with empty parameters array. |
230 | * | |
231 | * Error expected. | |
6a488035 | 232 | */ |
00be9182 | 233 | public function testDeleteWithEmptyParams() { |
7fe37828 | 234 | $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
235 | } |
236 | ||
237 | /** | |
7fe37828 EM |
238 | * Check delete with wrong id. |
239 | * | |
6a488035 TO |
240 | * Error expected |
241 | */ | |
00be9182 | 242 | public function testDeleteWithWrongID() { |
6a488035 TO |
243 | $params = array( |
244 | 'id' => 0, | |
6a488035 | 245 | ); |
7fe37828 | 246 | $this->callAPIFailure('note', 'delete', $params, 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
247 | } |
248 | ||
249 | /** | |
7fe37828 | 250 | * Check civicrm_note delete. |
6a488035 | 251 | */ |
00be9182 | 252 | public function testDelete() { |
6a488035 TO |
253 | $additionalNote = $this->noteCreate($this->_contactID); |
254 | ||
255 | $params = array( | |
256 | 'id' => $additionalNote['id'], | |
6a488035 TO |
257 | ); |
258 | ||
7fe37828 | 259 | $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 | 260 | } |
96025800 | 261 | |
6a488035 TO |
262 | } |
263 | ||
264 | /** | |
7fe37828 | 265 | * Test civicrm note create() using example code. |
6a488035 TO |
266 | */ |
267 | function testNoteCreateExample() { | |
3ec6e38d | 268 | require_once 'api/v3/examples/Note/Create.php'; |
7fe37828 EM |
269 | $result = Note_get_example(); |
270 | $expectedResult = Note_get_expectedresult(); | |
6a488035 TO |
271 | $this->assertEquals($result, $expectedResult); |
272 | } |