Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 TO |
27 | |
28 | require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
31 | * Class contains api test cases for "civicrm_note" | |
32 | * | |
33 | */ | |
34 | class api_v3_NoteTest extends CiviUnitTestCase { | |
35 | ||
36 | protected $_apiversion; | |
37 | protected $_contactID; | |
38 | protected $_params; | |
39 | protected $_noteID; | |
40 | protected $_note; | |
b7c9bc4c | 41 | |
00be9182 | 42 | public function setUp() { |
6a488035 TO |
43 | |
44 | $this->_apiversion = 3; | |
45 | // Connect to the database | |
46 | parent::setUp(); | |
bd772bfe | 47 | $this->useTransaction(TRUE); |
6a488035 TO |
48 | |
49 | $this->_contactID = $this->organizationCreate(NULL); | |
50 | ||
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', | |
92915c55 TO |
57 | 'subject' => 'Test Note', |
58 | ); | |
6a488035 TO |
59 | $this->_note = $this->noteCreate($this->_contactID); |
60 | $this->_noteID = $this->_note['id']; | |
61 | } | |
62 | ||
6a488035 TO |
63 | ///////////////// civicrm_note_get methods |
64 | ||
6a488035 | 65 | /** |
100fef9d | 66 | * Check retrieve note with empty parameter array |
6a488035 TO |
67 | * Error expected |
68 | */ | |
00be9182 | 69 | public function testGetWithEmptyParams() { |
d0e1eff2 | 70 | $this->callAPISuccess('note', 'get', array()); |
6a488035 TO |
71 | } |
72 | ||
73 | /** | |
100fef9d | 74 | * Check retrieve note with missing patrameters |
6a488035 TO |
75 | * Error expected |
76 | */ | |
00be9182 | 77 | public function testGetWithoutEntityId() { |
6a488035 TO |
78 | $params = array( |
79 | 'entity_table' => 'civicrm_contact', | |
6a488035 | 80 | ); |
b5ee049f | 81 | $note = $this->callAPISuccess('note', 'get', $params); |
6a488035 TO |
82 | } |
83 | ||
84 | /** | |
100fef9d | 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 | ); |
b5ee049f | 93 | $result = $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
94 | } |
95 | ||
96 | ||
97 | ///////////////// civicrm_note_create methods | |
98 | ||
6a488035 TO |
99 | /** |
100 | * Check create with empty parameter array | |
101 | * Error Expected | |
102 | */ | |
00be9182 | 103 | public function testCreateWithEmptyNoteField() { |
6a488035 | 104 | $this->_params['note'] = ""; |
b5ee049f | 105 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
106 | 'Mandatory key(s) missing from params array: note'); | |
6a488035 TO |
107 | } |
108 | ||
109 | /** | |
110 | * Check create with partial params | |
111 | * Error expected | |
112 | */ | |
00be9182 | 113 | public function testCreateWithoutEntityId() { |
6a488035 | 114 | unset($this->_params['entity_id']); |
b5ee049f | 115 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
116 | 'Mandatory key(s) missing from params array: entity_id'); | |
6a488035 TO |
117 | } |
118 | ||
119 | /** | |
120 | * Check create with partially empty params | |
121 | * Error expected | |
122 | */ | |
00be9182 | 123 | public function testCreateWithEmptyEntityId() { |
6a488035 | 124 | $this->_params['entity_id'] = ""; |
b5ee049f | 125 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
126 | 'Mandatory key(s) missing from params array: entity_id'); | |
6a488035 TO |
127 | } |
128 | ||
129 | /** | |
130 | * Check civicrm_note_create | |
131 | */ | |
00be9182 | 132 | public function testCreate() { |
6a488035 | 133 | |
b5ee049f | 134 | $result = $this->callAPIAndDocument('note', 'create', $this->_params, __FUNCTION__, __FILE__); |
6a488035 TO |
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__); | |
137 | ||
61ef23bd | 138 | $this->assertArrayHasKey('id', $result); |
6a488035 | 139 | $note = array( |
92915c55 TO |
140 | 'id' => $result['id'], |
141 | ); | |
6a488035 TO |
142 | $this->noteDelete($note); |
143 | } | |
144 | ||
00be9182 | 145 | public function testCreateWithApostropheInString() { |
6a488035 TO |
146 | $params = array( |
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 '", | |
92915c55 TO |
153 | 'sequential' => 1, |
154 | ); | |
b5ee049f | 155 | $result = $this->callAPISuccess('Note', 'Create', $params); |
791c263c | 156 | $this->assertAPISuccess($result, 'in line ' . __LINE__); |
6a488035 TO |
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__); | |
160 | ||
161 | //CleanUP | |
162 | $note = array( | |
92915c55 TO |
163 | 'id' => $result['id'], |
164 | ); | |
6a488035 TO |
165 | $this->noteDelete($note); |
166 | } | |
167 | ||
168 | /** | |
169 | * Check civicrm_note_create - tests used of default set to now | |
170 | */ | |
00be9182 | 171 | public function testCreateWithoutModifiedDate() { |
6a488035 | 172 | unset($this->_params['modified_date']); |
b5ee049f | 173 | $apiResult = $this->callAPISuccess('note', 'create', $this->_params); |
6a488035 TO |
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( | |
92915c55 TO |
177 | 'id' => $apiResult['id'], |
178 | )); | |
6a488035 TO |
179 | } |
180 | ||
181 | ||
182 | ///////////////// civicrm_note_update methods | |
183 | ||
6a488035 TO |
184 | /** |
185 | * Check update with empty parameter array | |
b5ee049f | 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 | |
6a488035 | 188 | */ |
00be9182 | 189 | public function testUpdateWithEmptyParams() { |
b5ee049f | 190 | $note = $this->callAPIFailure('note', 'create', array()); |
6a488035 TO |
191 | } |
192 | ||
193 | /** | |
194 | * Check update with missing parameter (contact id) | |
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 | ); | |
b5ee049f | 202 | $note = $this->callAPIFailure('note', 'create', $params, |
203 | 'Mandatory key(s) missing from params array: note' | |
6a488035 | 204 | ); |
6a488035 TO |
205 | } |
206 | ||
207 | /** | |
208 | * Check civicrm_note_update | |
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 TO |
217 | |
218 | //Update Note | |
b5ee049f | 219 | $this->callAPISuccess('note', 'create', $params); |
220 | $note = $this->callAPISuccess('Note', 'Get', array()); | |
6a488035 | 221 | $this->assertEquals($note['id'], $this->_noteID, 'in line ' . __LINE__); |
6a488035 TO |
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__); | |
226 | } | |
227 | ||
228 | ///////////////// civicrm_note_delete methods | |
229 | ||
6a488035 TO |
230 | |
231 | /** | |
232 | * Check delete with empty parametes array | |
233 | * Error expected | |
234 | */ | |
00be9182 | 235 | public function testDeleteWithEmptyParams() { |
b5ee049f | 236 | $deleteNote = $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
237 | } |
238 | ||
239 | /** | |
240 | * Check delete with wrong id | |
241 | * Error expected | |
242 | */ | |
00be9182 | 243 | public function testDeleteWithWrongID() { |
6a488035 TO |
244 | $params = array( |
245 | 'id' => 0, | |
6a488035 | 246 | ); |
6c6e6187 | 247 | $deleteNote = $this->callAPIFailure('note', 'delete', $params, 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
248 | } |
249 | ||
250 | /** | |
251 | * Check civicrm_note_delete | |
252 | */ | |
00be9182 | 253 | public function testDelete() { |
6a488035 TO |
254 | $additionalNote = $this->noteCreate($this->_contactID); |
255 | ||
256 | $params = array( | |
257 | 'id' => $additionalNote['id'], | |
6a488035 TO |
258 | ); |
259 | ||
b5ee049f | 260 | $result = $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 | 261 | } |
96025800 | 262 | |
6a488035 TO |
263 | } |
264 | ||
265 | /** | |
266 | * Test civicrm_activity_create() using example code | |
267 | */ | |
268 | function testNoteCreateExample() { | |
3ec6e38d | 269 | require_once 'api/v3/examples/Note/Create.php'; |
6a488035 TO |
270 | $result = UF_match_get_example(); |
271 | $expectedResult = UF_match_get_expectedresult(); | |
272 | $this->assertEquals($result, $expectedResult); | |
273 | } |