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 | +--------------------------------------------------------------------+ | |
26 | */ | |
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 | |
6a488035 TO |
42 | function setUp() { |
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', | |
b5ee049f | 57 | 'subject' => 'Test Note', ); |
6a488035 TO |
58 | $this->_note = $this->noteCreate($this->_contactID); |
59 | $this->_noteID = $this->_note['id']; | |
60 | } | |
61 | ||
6a488035 TO |
62 | ///////////////// civicrm_note_get methods |
63 | ||
6a488035 | 64 | /** |
100fef9d | 65 | * Check retrieve note with empty parameter array |
6a488035 TO |
66 | * Error expected |
67 | */ | |
68 | function testGetWithEmptyParams() { | |
d0e1eff2 | 69 | $this->callAPISuccess('note', 'get', array()); |
6a488035 TO |
70 | } |
71 | ||
72 | /** | |
100fef9d | 73 | * Check retrieve note with missing patrameters |
6a488035 TO |
74 | * Error expected |
75 | */ | |
76 | function testGetWithoutEntityId() { | |
77 | $params = array( | |
78 | 'entity_table' => 'civicrm_contact', | |
6a488035 | 79 | ); |
b5ee049f | 80 | $note = $this->callAPISuccess('note', 'get', $params); |
6a488035 TO |
81 | } |
82 | ||
83 | /** | |
100fef9d | 84 | * Check civicrm_note_get |
6a488035 TO |
85 | */ |
86 | function testGet() { | |
87 | $entityId = $this->_noteID; | |
88 | $params = array( | |
89 | 'entity_table' => 'civicrm_contact', | |
90 | 'entity_id' => $entityId, | |
6a488035 | 91 | ); |
b5ee049f | 92 | $result = $this->callAPIAndDocument('note', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
93 | } |
94 | ||
95 | ||
96 | ///////////////// civicrm_note_create methods | |
97 | ||
6a488035 TO |
98 | /** |
99 | * Check create with empty parameter array | |
100 | * Error Expected | |
101 | */ | |
102 | function testCreateWithEmptyNoteField() { | |
103 | $this->_params['note'] = ""; | |
b5ee049f | 104 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
105 | 'Mandatory key(s) missing from params array: note'); | |
6a488035 TO |
106 | } |
107 | ||
108 | /** | |
109 | * Check create with partial params | |
110 | * Error expected | |
111 | */ | |
112 | function testCreateWithoutEntityId() { | |
113 | unset($this->_params['entity_id']); | |
b5ee049f | 114 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
115 | 'Mandatory key(s) missing from params array: entity_id'); | |
6a488035 TO |
116 | } |
117 | ||
118 | /** | |
119 | * Check create with partially empty params | |
120 | * Error expected | |
121 | */ | |
122 | function testCreateWithEmptyEntityId() { | |
123 | $this->_params['entity_id'] = ""; | |
b5ee049f | 124 | $result = $this->callAPIFailure('note', 'create', $this->_params, |
125 | 'Mandatory key(s) missing from params array: entity_id'); | |
6a488035 TO |
126 | } |
127 | ||
128 | /** | |
129 | * Check civicrm_note_create | |
130 | */ | |
131 | function testCreate() { | |
132 | ||
b5ee049f | 133 | $result = $this->callAPIAndDocument('note', 'create', $this->_params, __FUNCTION__, __FILE__); |
6a488035 TO |
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__); | |
136 | ||
61ef23bd | 137 | $this->assertArrayHasKey('id', $result); |
6a488035 | 138 | $note = array( |
b5ee049f | 139 | 'id' => $result['id'], ); |
6a488035 TO |
140 | $this->noteDelete($note); |
141 | } | |
142 | ||
143 | function testCreateWithApostropheInString() { | |
144 | $params = array( | |
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 '", | |
b5ee049f | 151 | 'sequential' => 1, ); |
152 | $result = $this->callAPISuccess('Note', 'Create', $params); | |
791c263c | 153 | $this->assertAPISuccess($result, 'in line ' . __LINE__); |
6a488035 TO |
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__); | |
157 | ||
158 | //CleanUP | |
159 | $note = array( | |
b5ee049f | 160 | 'id' => $result['id'], ); |
6a488035 TO |
161 | $this->noteDelete($note); |
162 | } | |
163 | ||
164 | /** | |
165 | * Check civicrm_note_create - tests used of default set to now | |
166 | */ | |
167 | function testCreateWithoutModifiedDate() { | |
168 | unset($this->_params['modified_date']); | |
b5ee049f | 169 | $apiResult = $this->callAPISuccess('note', 'create', $this->_params); |
6a488035 TO |
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( | |
b5ee049f | 173 | 'id' => $apiResult['id'], )); |
6a488035 TO |
174 | } |
175 | ||
176 | ||
177 | ///////////////// civicrm_note_update methods | |
178 | ||
6a488035 TO |
179 | /** |
180 | * Check update with empty parameter array | |
b5ee049f | 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 | |
6a488035 TO |
183 | */ |
184 | function testUpdateWithEmptyParams() { | |
b5ee049f | 185 | $note = $this->callAPIFailure('note', 'create', array()); |
6a488035 TO |
186 | } |
187 | ||
188 | /** | |
189 | * Check update with missing parameter (contact id) | |
190 | * Error expected | |
191 | */ | |
192 | function testUpdateWithoutContactId() { | |
193 | $params = array( | |
194 | 'entity_id' => $this->_contactID, | |
b5ee049f | 195 | 'entity_table' => 'civicrm_contact', ); |
196 | $note = $this->callAPIFailure('note', 'create', $params, | |
197 | 'Mandatory key(s) missing from params array: note' | |
6a488035 | 198 | ); |
6a488035 TO |
199 | } |
200 | ||
201 | /** | |
202 | * Check civicrm_note_update | |
203 | */ | |
204 | function testUpdate() { | |
205 | $params = array( | |
206 | 'id' => $this->_noteID, | |
207 | 'contact_id' => $this->_contactID, | |
208 | 'note' => 'Note1', | |
b5ee049f | 209 | 'subject' => 'Hello World', ); |
6a488035 TO |
210 | |
211 | //Update Note | |
b5ee049f | 212 | $this->callAPISuccess('note', 'create', $params); |
213 | $note = $this->callAPISuccess('Note', 'Get', array()); | |
6a488035 | 214 | $this->assertEquals($note['id'], $this->_noteID, 'in line ' . __LINE__); |
6a488035 TO |
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__); | |
219 | } | |
220 | ||
221 | ///////////////// civicrm_note_delete methods | |
222 | ||
6a488035 TO |
223 | |
224 | /** | |
225 | * Check delete with empty parametes array | |
226 | * Error expected | |
227 | */ | |
228 | function testDeleteWithEmptyParams() { | |
b5ee049f | 229 | $deleteNote = $this->callAPIFailure('note', 'delete', array(), 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
230 | } |
231 | ||
232 | /** | |
233 | * Check delete with wrong id | |
234 | * Error expected | |
235 | */ | |
236 | function testDeleteWithWrongID() { | |
237 | $params = array( | |
238 | 'id' => 0, | |
6a488035 | 239 | ); |
b5ee049f | 240 | $deleteNote = $this->callAPIFailure('note', 'delete', $params |
241 | , 'Mandatory key(s) missing from params array: id'); | |
6a488035 TO |
242 | } |
243 | ||
244 | /** | |
245 | * Check civicrm_note_delete | |
246 | */ | |
247 | function testDelete() { | |
248 | $additionalNote = $this->noteCreate($this->_contactID); | |
249 | ||
250 | $params = array( | |
251 | 'id' => $additionalNote['id'], | |
6a488035 TO |
252 | ); |
253 | ||
b5ee049f | 254 | $result = $this->callAPIAndDocument('note', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
255 | } |
256 | } | |
257 | ||
258 | /** | |
259 | * Test civicrm_activity_create() using example code | |
260 | */ | |
261 | function testNoteCreateExample() { | |
3ec6e38d | 262 | require_once 'api/v3/examples/Note/Create.php'; |
6a488035 TO |
263 | $result = UF_match_get_example(); |
264 | $expectedResult = UF_match_get_expectedresult(); | |
265 | $this->assertEquals($result, $expectedResult); | |
266 | } | |
267 |