Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / api / v3 / ContactTest.php
1 <?php
2 /**
3 * File for the TestContact class
4 *
5 * (PHP 5)
6 *
7 * @author Walt Haas <walt@dharmatech.org> (801) 534-1262
8 * @copyright Copyright CiviCRM LLC (C) 2009
9 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
10 * GNU Affero General Public License version 3
11 * @version $Id: ContactTest.php 31254 2010-12-15 10:09:29Z eileen $
12 * @package CiviCRM
13 *
14 * This file is part of CiviCRM
15 *
16 * CiviCRM is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Affero General Public License
18 * as published by the Free Software Foundation; either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * CiviCRM is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
25 *
26 * You should have received a copy of the GNU Affero General Public
27 * License along with this program. If not, see
28 * <http://www.gnu.org/licenses/>.
29 */
30
31 /**
32 * Include class definitions
33 */
34 require_once 'CiviTest/CiviUnitTestCase.php';
35
36
37 /**
38 * Test APIv3 civicrm_contact* functions
39 *
40 * @package CiviCRM_APIv3
41 * @subpackage API_Contact
42 */
43
44 class api_v3_ContactTest extends CiviUnitTestCase {
45 public $DBResetRequired = FALSE;
46 protected $_apiversion;
47 protected $_entity;
48 protected $_params;
49 public $_eNoticeCompliant = TRUE;
50 protected $_contributionTypeId;
51
52 /**
53 * Constructor
54 *
55 * Initialize configuration
56 */
57 function __construct() {
58 parent::__construct();
59 }
60
61 /**
62 * Test setup for every test
63 *
64 * Connect to the database, truncate the tables that will be used
65 * and redirect stdin to a temporary file
66 */
67 public function setUp() {
68 // Connect to the database
69 parent::setUp();
70 $this->_apiversion = 3;
71 $this->_entity = 'contact';
72 $this->_params = array(
73 'first_name' => 'abc1',
74 'contact_type' => 'Individual',
75 'last_name' => 'xyz1',
76 'version' => $this->_apiversion,
77 );
78 $this->_contributionTypeId = 1;// don't rely on flaky xml based fn - use built in
79 }
80
81 function tearDown() {
82 // truncate a few tables
83 $tablesToTruncate = array(
84 'civicrm_contact',
85 'civicrm_email',
86 'civicrm_contribution',
87 'civicrm_line_item',
88 'civicrm_website',
89 'civicrm_relationship'
90 );
91
92 $this->quickCleanup($tablesToTruncate);
93 $this->contributionTypeDelete();
94 }
95
96 /**
97 * Test civicrm_contact_create
98 *
99 * Verify that attempt to create individual contact with only
100 * first and last names succeeds
101 */
102 function testAddCreateIndividual() {
103 $oldCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_contact');
104 $params = array(
105 'first_name' => 'abc1',
106 'contact_type' => 'Individual',
107 'last_name' => 'xyz1',
108 'version' => $this->_apiversion,
109 );
110
111 $contact = civicrm_api('contact', 'create', $params);
112 $this->assertApiSuccess($contact, "In line " . __LINE__);
113 $this->assertTrue(is_numeric($contact['id']), "In line " . __LINE__);
114 $this->assertTrue($contact['id'] > 0, "In line " . __LINE__);
115 $newCount = CRM_Core_DAO::singleValueQuery('select count(*) from civicrm_contact');
116 $this->assertEquals($oldCount+1, $newCount);
117
118 unset($params['version']);
119 $this->assertDBState('CRM_Contact_DAO_Contact',
120 $contact['id'],
121 $params
122 );
123 }
124
125 /**
126 * Test civicrm_contact_create with sub-types
127 *
128 * Verify that sub-types are created successfully and not deleted by subsequent updates
129 */
130 function testIndividualSubType() {
131 $params = array(
132 'first_name' => 'test abc',
133 'contact_type' => 'Individual',
134 'last_name' => 'test xyz',
135 'contact_sub_type' => array('Student', 'Staff'),
136 'version' => $this->_apiversion,
137 );
138 $contact = civicrm_api('contact', 'create', $params);
139 $cid = $contact['id'];
140
141 $params = array(
142 'id' => $cid,
143 'middle_name' => 'foo',
144 'version' => $this->_apiversion,
145 );
146 civicrm_api('contact', 'create', $params);
147 unset($params['middle_name']);
148
149 $contact = civicrm_api('contact', 'get', $params);
150
151 $this->assertEquals(array('Student', 'Staff'), $contact['values'][$cid]['contact_sub_type'], "In line " . __LINE__);
152 }
153
154 /**
155 * Verify that attempt to create contact with empty params fails
156 */
157 function testCreateEmptyContact() {
158 $params = array();
159 $contact = civicrm_api('contact', 'create', $params);
160 $this->assertEquals($contact['is_error'], 1,
161 "In line " . __LINE__
162 );
163 }
164
165 /**
166 * Verify that attempt to create contact with bad contact type fails
167 */
168 function testCreateBadTypeContact() {
169 $params = array(
170 'email' => 'man1@yahoo.com',
171 'contact_type' => 'Does not Exist',
172 'version' => $this->_apiversion,
173 );
174 $contact = civicrm_api('contact', 'create', $params);
175 $this->assertEquals($contact['is_error'], 1, "In line " . __LINE__);
176 $this->assertEquals('contact_type `Does not Exist` is not valid.', $contact['error_message']);
177 }
178
179 /**
180 * Verify that attempt to create individual contact with required
181 * fields missing fails
182 */
183 function testCreateBadRequiredFieldsIndividual() {
184 $params = array(
185 'middle_name' => 'This field is not required',
186 'contact_type' => 'Individual',
187 );
188
189 $contact = civicrm_api('contact', 'create', $params);
190 $this->assertEquals($contact['is_error'], 1,
191 "In line " . __LINE__
192 );
193 }
194
195 /**
196 * Verify that attempt to create household contact with required
197 * fields missing fails
198 */
199 function testCreateBadRequiredFieldsHousehold() {
200 $params = array(
201 'middle_name' => 'This field is not required',
202 'contact_type' => 'Household',
203 );
204
205 $contact = civicrm_api('contact', 'create', $params);
206 $this->assertEquals($contact['is_error'], 1,
207 "In line " . __LINE__
208 );
209 }
210
211 /**
212 * Verify that attempt to create organization contact with
213 * required fields missing fails
214 */
215 function testCreateBadRequiredFieldsOrganization() {
216 $params = array(
217 'middle_name' => 'This field is not required',
218 'contact_type' => 'Organization',
219 );
220
221 $contact = civicrm_api('contact', 'create', $params);
222 $this->assertEquals($contact['is_error'], 1,
223 "In line " . __LINE__
224 );
225 }
226
227 /**
228 * Verify that attempt to create individual contact with only an
229 * email succeeds
230 */
231 function testCreateEmailIndividual() {
232
233 $params = array(
234 'email' => 'man3@yahoo.com',
235 'contact_type' => 'Individual',
236 'location_type_id' => 1,
237 'version' => $this->_apiversion,
238 );
239
240 $contact = civicrm_api('contact', 'create', $params);
241 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
242 );
243 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
244 $email = civicrm_api('email', 'get', array('contact_id' => $contact['id'], 'version' => $this->_apiversion));
245 $this->assertEquals(0, $email['is_error'], "In line " . __LINE__);
246 $this->assertEquals(1, $email['count'], "In line " . __LINE__);
247 $this->assertEquals('man3@yahoo.com', $email['values'][$email['id']]['email'], "In line " . __LINE__);
248
249 // delete the contact
250 civicrm_api('contact', 'delete', $contact);
251 }
252
253 /**
254 * Verify that attempt to create individual contact with only
255 * first and last names succeeds
256 */
257 function testCreateNameIndividual() {
258 $params = array(
259 'first_name' => 'abc1',
260 'contact_type' => 'Individual',
261 'last_name' => 'xyz1',
262 'version' => $this->_apiversion,
263 );
264
265 $contact = civicrm_api('contact', 'create', $params);
266 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
267 );
268 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
269
270 // delete the contact
271 civicrm_api('contact', 'delete', $contact);
272 }
273
274 /**
275 * Verify that attempt to create individual contact with
276 * first and last names and old key values works
277 */
278 function testCreateNameIndividualOldKeys() {
279 $params = array(
280 'individual_prefix' => 'Dr.',
281 'first_name' => 'abc1',
282 'contact_type' => 'Individual',
283 'last_name' => 'xyz1',
284 'individual_suffix' => 'Jr.',
285 'version' => $this->_apiversion,
286 );
287
288 $contact = civicrm_api('contact', 'create', $params);
289 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
290 );
291 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
292
293 // delete the contact
294 civicrm_api('contact', 'delete', $contact);
295 }
296
297 /**
298 * Verify that attempt to create individual contact with
299 * first and last names and old key values works
300 */
301 function testCreateNameIndividualOldKeys2() {
302 $params = array(
303 'prefix_id' => 'Dr.',
304 'first_name' => 'abc1',
305 'contact_type' => 'Individual',
306 'last_name' => 'xyz1',
307 'suffix_id' => 'Jr.',
308 'gender_id' => 'Male',
309 'version' => $this->_apiversion,
310 );
311
312 $contact = civicrm_api('contact', 'create', $params);
313 $this->assertApiSuccess($contact, "In line " . __LINE__ );
314 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
315
316 // delete the contact
317 civicrm_api('contact', 'delete', $contact);
318 }
319
320 /**
321 * Verify that attempt to create household contact with only
322 * household name succeeds
323 */
324 function testCreateNameHousehold() {
325 $params = array(
326 'household_name' => 'The abc Household',
327 'contact_type' => 'Household',
328 'version' => $this->_apiversion,
329 );
330
331 $contact = civicrm_api('contact', 'create', $params);
332 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
333 );
334 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
335
336 // delete the contact
337 civicrm_api('contact', 'delete', $contact);
338 }
339
340 /**
341 * Verify that attempt to create organization contact with only
342 * organization name succeeds
343 */
344 function testCreateNameOrganization() {
345 $params = array(
346 'organization_name' => 'The abc Organization',
347 'contact_type' => 'Organization',
348 'version' => $this->_apiversion,
349 );
350 $contact = civicrm_api('contact', 'create', $params);
351 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
352 );
353 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
354
355 // delete the contact
356 civicrm_api('contact', 'delete', $contact);
357 }
358 /**
359 * Verify that attempt to create organization contact with only
360 * organization name succeeds
361 */
362 function testCreateNoNameOrganization() {
363 $params = array(
364 'first_name' => 'The abc Organization',
365 'contact_type' => 'Organization',
366 'version' => $this->_apiversion,
367 );
368 $result = civicrm_api('contact', 'create', $params);
369 $this->assertEquals(1, $result['is_error'], "In line " . __LINE__);
370 }
371 /**
372 * check with complete array + custom field
373 * Note that the test is written on purpose without any
374 * variables specific to participant so it can be replicated into other entities
375 * and / or moved to the automated test suite
376 */
377 function testCreateWithCustom() {
378 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
379
380 $params = $this->_params;
381 $params['custom_' . $ids['custom_field_id']] = "custom string";
382 $description = "/*this demonstrates setting a custom field through the API ";
383 $subfile = "CustomFieldCreate";
384 $result = civicrm_api($this->_entity, 'create', $params);
385 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
386 $this->assertAPISuccess($result, ' in line ' . __LINE__);
387
388 $check = civicrm_api($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'version' => $this->_apiversion, 'id' => $result['id']));
389 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
390
391 $this->customFieldDelete($ids['custom_field_id']);
392 $this->customGroupDelete($ids['custom_group_id']);
393 }
394
395 /*
396 * Test creating a current employer through API
397 */
398 function testContactCreateCurrentEmployer(){
399 //here we will just do the get for set-up purposes
400 $count = civicrm_api('contact', 'getcount', array(
401 'version' => 3,
402 'organization_name' => 'new employer org',
403 'contact_type' => 'Organization'
404 ));
405 $this->assertEquals(0, $count);
406 $employerResult = civicrm_api('contact', 'create', array_merge($this->_params, array(
407 'current_employer' => 'new employer org',)
408 ));
409
410 $count = civicrm_api('contact', 'getcount', array(
411 'version' => 3,
412 'organization_name' => 'new employer org',
413 'contact_type' => 'Organization'
414 ));
415 $this->assertEquals(1, $count['count'], 'failed to create organization');
416
417 $result = civicrm_api('contact', 'getsingle', array(
418 'version' => $this->_apiversion,
419 'id' => $employerResult['id'],
420 ));
421
422 $this->assertEquals('new employer org', $result['current_employer']);
423
424 }
425
426 /*
427 * Test that sort works - old syntax
428 */
429 function testGetSort() {
430 $c1 = civicrm_api($this->_entity, 'create', $this->_params);
431 $this->assertAPISuccess($c1, 'in line ' . __LINE__);
432 $c2 = civicrm_api($this->_entity, 'create', array('version' => $this->_apiversion, 'first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual'));
433 $result = civicrm_api($this->_entity, 'get', array(
434 'version' => $this->_apiversion,
435 'sort' => 'first_name ASC',
436 'return.first_name' => 1,
437 'sequential' => 1,
438 'rowCount' => 1,
439 ));
440 $this->assertAPISuccess($result, 'in line ' . __LINE__);
441
442 $this->assertEquals('abc1', $result['values'][0]['first_name']);
443 $result = civicrm_api($this->_entity, 'get', array(
444 'version' => $this->_apiversion,
445 'sort' => 'first_name DESC',
446 'return.first_name' => 1,
447 'sequential' => 1,
448 'rowCount' => 1,
449 ));
450 $this->assertEquals('bb', $result['values'][0]['first_name']);
451
452 civicrm_api($this->_entity, 'delete', array('version' => $this->_apiversion, 'id' => $c1['id']));
453 civicrm_api($this->_entity, 'delete', array('version' => $this->_apiversion, 'id' => $c2['id']));
454 }
455 /*
456 * Test variants on deleted behaviour
457 */
458 function testGetDeleted() {
459 $params = $this->_params;
460 $contact1 = civicrm_api('contact', 'create', $params);
461 $params['is_deleted'] = 1;
462 $params['last_name'] = 'bcd';
463 $contact2 = civicrm_api('contact', 'create', $params);
464 $countActive = civicrm_api('contact', 'getcount', array('version' => $this->_apiversion, 'showAll' => 'active'));
465 $countAll = civicrm_api('contact', 'getcount', array('version' => $this->_apiversion, 'showAll' => 'all'));
466 $countTrash = civicrm_api('contact', 'getcount', array('version' => $this->_apiversion, 'showAll' => 'trash'));
467 $countDefault = civicrm_api('contact', 'getcount', array(
468 'version' => $this->_apiversion,
469 ));
470 $countDeleted = civicrm_api('contact', 'getcount', array(
471 'version' => $this->_apiversion, 'contact_is_deleted' => 1,
472 ));
473 $countNotDeleted = civicrm_api('contact', 'getcount', array(
474 'version' => $this->_apiversion, 'contact_is_deleted' => 0,
475 ));
476 civicrm_api('contact', 'delete', array('version' => $this->_apiversion, 'id' => $contact1['id']));
477 civicrm_api('contact', 'delete', array('version' => $this->_apiversion, 'id' => $contact2['id']));
478 $this->assertEquals(1, $countNotDeleted, 'contact_is_deleted => 0 is respected in line ' . __LINE__);
479 $this->assertEquals(1, $countActive, 'in line ' . __LINE__);
480 $this->assertEquals(1, $countTrash, 'in line ' . __LINE__);
481 $this->assertEquals(2, $countAll, 'in line ' . __LINE__);
482 $this->assertEquals(1, $countDeleted, 'in line ' . __LINE__);
483 $this->assertEquals(1, $countDefault, 'Only active by default in line ' . __LINE__);
484 }
485 /*
486 * Test that sort works - new syntax
487 */
488 function testGetSortNewSYntax() {
489 $c1 = civicrm_api($this->_entity, 'create', $this->_params);
490 $c2 = civicrm_api($this->_entity, 'create', array('version' => $this->_apiversion, 'first_name' => 'bb', 'last_name' => 'ccc', 'contact_type' => 'Individual'));
491 $result = civicrm_api($this->_entity, 'getvalue', array(
492 'version' => $this->_apiversion,
493 'return' => 'first_name',
494 'options' => array(
495 'limit' => 1,
496 'sort' => 'first_name',
497 ),
498 ));
499 $this->assertEquals('abc1', $result, 'in line' . __LINE__);
500
501 $result = civicrm_api($this->_entity, 'getvalue', array(
502 'version' => $this->_apiversion,
503 'return' => 'first_name',
504 'options' => array(
505 'limit' => 1,
506 'sort' => 'first_name DESC',
507 ),
508 ));
509 $this->assertEquals('bb', $result);
510
511 civicrm_api($this->_entity, 'delete', array('version' => $this->_apiversion, 'id' => $c1['id']));
512 civicrm_api($this->_entity, 'delete', array('version' => $this->_apiversion, 'id' => $c2['id']));
513 }
514 /*
515 * Test appostrophe works in get & create
516 */
517 function testGetAppostropheCRM10857() {
518 $params = array_merge($this->_params, array('last_name' => "O'Connor"));
519 $contact = civicrm_api($this->_entity, 'create', $params);
520 $this->assertAPISuccess($contact, 'check contact with appostrophe created');
521 $result = civicrm_api($this->_entity, 'getsingle', array(
522 'version' => $this->_apiversion,
523 'last_name' => "O'Connor",
524 'sequential' => 1,
525 ));
526 $this->assertEquals("O'Connor", $result['last_name'], 'in line' . __LINE__);
527 }
528
529 /**
530 * check with complete array + custom field
531 * Note that the test is written on purpose without any
532 * variables specific to participant so it can be replicated into other entities
533 * and / or moved to the automated test suite
534 */
535 function testGetWithCustom() {
536 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
537
538 $params = $this->_params;
539 $params['custom_' . $ids['custom_field_id']] = "custom string";
540 $description = "/*this demonstrates setting a custom field through the API ";
541 $subfile = "CustomFieldGet";
542 $result = civicrm_api($this->_entity, 'create', $params);
543 $this->assertAPISuccess($result, ' in line ' . __LINE__);
544
545 $check = civicrm_api($this->_entity, 'get', array('return.custom_' . $ids['custom_field_id'] => 1, 'version' => $this->_apiversion, 'id' => $result['id']));
546 $this->documentMe($params, $check, __FUNCTION__, __FILE__, $description, $subfile);
547
548 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
549 $fields = (civicrm_api('contact', 'getfields', $params));
550 $this->assertTrue(is_array($fields['values']['custom_' . $ids['custom_field_id']]));
551 $this->customFieldDelete($ids['custom_field_id']);
552 $this->customGroupDelete($ids['custom_group_id']);
553 }
554 /*
555 * check with complete array + custom field
556 * Note that the test is written on purpose without any
557 * variables specific to participant so it can be replicated into other entities
558 * and / or moved to the automated test suite
559 */
560 function testGetWithCustomReturnSyntax() {
561 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
562
563 $params = $this->_params;
564 $params['custom_' . $ids['custom_field_id']] = "custom string";
565 $description = "/*this demonstrates setting a custom field through the API ";
566 $subfile = "CustomFieldGetReturnSyntaxVariation";
567 $result = civicrm_api($this->_entity, 'create', $params);
568 $this->assertAPISuccess($result, ' in line ' . __LINE__);
569 $params = array('return' => 'custom_' . $ids['custom_field_id'], 'version' => $this->_apiversion, 'id' => $result['id']);
570 $check = civicrm_api($this->_entity, 'get', $params);
571 $this->documentMe($params, $check, __FUNCTION__, __FILE__, $description, $subfile);
572
573 $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__);
574 civicrm_api('Contact', 'Delete', array('version' => $this->_apiversion, 'id' => $check['id']));
575 $this->customFieldDelete($ids['custom_field_id']);
576 $this->customGroupDelete($ids['custom_group_id']);
577 }
578
579 function testGetGroupIDFromContact() {
580 $groupId = $this->groupCreate(NULL);
581 $description = "Get all from group and display contacts";
582 $subfile = "GroupFilterUsingContactAPI";
583 $params = array(
584 'email' => 'man2@yahoo.com',
585 'contact_type' => 'Individual',
586 'location_type_id' => 1,
587 'version' => $this->_apiversion,
588 'api.group_contact.create' => array('group_id' => $groupId),
589 );
590
591
592 $contact = civicrm_api('contact', 'create', $params);
593 // testing as integer
594 $params = array(
595 'filter.group_id' => $groupId,
596 'version' => $this->_apiversion,
597 'contact_type' => 'Individual',
598 );
599 $result = civicrm_api('contact', 'get', $params);
600 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
601 $this->assertEquals(1, $result['count']);
602 // group 26 doesn't exist, but we can still search contacts in it.
603 $params = array(
604 'filter.group_id' => 26,
605 'version' => $this->_apiversion,
606 'contact_type' => 'Individual',
607 );
608 $result = civicrm_api('contact', 'get', $params);
609 $this->assertEquals(0, $result['count'], " in line " . __LINE__);
610 // testing as string
611 $params = array(
612 'filter.group_id' => "$groupId,26",
613 'version' => $this->_apiversion,
614 'contact_type' => 'Individual',
615 );
616 $result = civicrm_api('contact', 'get', $params);
617 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
618 $this->assertEquals(1, $result['count']);
619 $params = array(
620 'filter.group_id' => "26,27",
621 'version' => $this->_apiversion,
622 'contact_type' => 'Individual',
623 );
624 $result = civicrm_api('contact', 'get', $params);
625 $this->assertEquals(0, $result['count'], " in line " . __LINE__);
626
627 // testing as string
628 $params = array('filter.group_id' => array($groupId, 26),
629 'version' => $this->_apiversion,
630 'contact_type' => 'Individual',
631 );
632 $result = civicrm_api('contact', 'get', $params);
633 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
634 $this->assertEquals(1, $result['count']);
635
636 //test in conjunction with other criteria
637 $params = array('filter.group_id' => array($groupId, 26),
638 'version' => $this->_apiversion,
639 'contact_type' => 'Organization',
640 );
641 $result = civicrm_api('contact', 'get', $params);
642 $this->assertEquals(0, $result['count']);
643 $params = array('filter.group_id' => array(26, 27),
644 'version' => $this->_apiversion,
645 'contact_type' => 'Individual',
646 );
647 $result = civicrm_api('contact', 'get', $params);
648 $this->assertEquals(0, $result['count'], " in line " . __LINE__);
649 }
650
651 /**
652 * Verify that attempt to create individual contact with two chained websites succeeds
653 */
654 function testCreateIndividualWithContributionDottedSyntax() {
655 $description = "test demonstrates the syntax to create 2 chained entities";
656 $subfile = "ChainTwoWebsites";
657 $params = array(
658 'first_name' => 'abc3',
659 'last_name' => 'xyz3',
660 'contact_type' => 'Individual',
661 'email' => 'man3@yahoo.com',
662 'version' => $this->_apiversion,
663 'api.contribution.create' => array(
664 'receive_date' => '2010-01-01',
665 'total_amount' => 100.00,
666 'financial_type_id' => 1,
667 'payment_instrument_id' => 1,
668 'non_deductible_amount' => 10.00,
669 'fee_amount' => 50.00,
670 'net_amount' => 90.00,
671 'trxn_id' => 15345,
672 'invoice_id' => 67990,
673 'source' => 'SSF',
674 'contribution_status_id' => 1,
675 ),
676 'api.website.create' => array(
677 'url' => "http://civicrm.org",
678 ),
679 'api.website.create.2' => array(
680 'url' => "http://chained.org",
681 ),
682 );
683
684 $result = civicrm_api('Contact', 'create', $params);
685 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
686 $this->assertAPISuccess( $result, "In line " . __LINE__ );
687
688 $this->assertEquals(1, $result['id'], "In line " . __LINE__);
689 $this->assertEquals(0, $result['values'][$result['id']]['api.website.create']['is_error'], "In line " . __LINE__);
690 $this->assertEquals("http://chained.org", $result['values'][$result['id']]['api.website.create.2']['values'][0]['url'], "In line " . __LINE__);
691 $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.create']['values'][0]['url'], "In line " . __LINE__);
692
693 // delete the contact
694 civicrm_api('contact', 'delete', $result);
695 }
696
697 /**
698 * Verify that attempt to create individual contact with chained contribution and website succeeds
699 */
700 function testCreateIndividualWithContributionChainedArrays() {
701 $params = array(
702 'first_name' => 'abc3',
703 'last_name' => 'xyz3',
704 'contact_type' => 'Individual',
705 'email' => 'man3@yahoo.com',
706 'version' => $this->_apiversion,
707 'api.contribution.create' => array(
708 'receive_date' => '2010-01-01',
709 'total_amount' => 100.00,
710 'financial_type_id' => 1,
711 'payment_instrument_id' => 1,
712 'non_deductible_amount' => 10.00,
713 'fee_amount' => 50.00,
714 'net_amount' => 90.00,
715 'trxn_id' => 12345,
716 'invoice_id' => 67890,
717 'source' => 'SSF',
718 'contribution_status_id' => 1,
719 ),
720 'api.website.create' => array(
721 array(
722 'url' => "http://civicrm.org",
723 ),
724 array(
725 'url' => "http://chained.org",
726 'website_type_id' => 2,
727 ),
728 ),
729 );
730
731 $description = "demonstrates creating two websites as an array";
732 $subfile = "ChainTwoWebsitesSyntax2";
733 $result = civicrm_api('Contact', 'create', $params);
734 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
735 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
736 );
737 $this->assertEquals(1, $result['id'], "In line " . __LINE__);
738 $this->assertEquals(0, $result['values'][$result['id']]['api.website.create'][0]['is_error'], "In line " . __LINE__);
739 $this->assertEquals("http://chained.org", $result['values'][$result['id']]['api.website.create'][1]['values'][0]['url'], "In line " . __LINE__);
740 $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.create'][0]['values'][0]['url'], "In line " . __LINE__);
741
742 // delete the contact
743 civicrm_api('contact', 'delete', $result);
744 }
745
746 /**
747 * Verify that attempt to create individual contact with first
748 * and last names and email succeeds
749 */
750 function testCreateIndividualWithNameEmail() {
751 $params = array(
752 'first_name' => 'abc3',
753 'last_name' => 'xyz3',
754 'contact_type' => 'Individual',
755 'email' => 'man3@yahoo.com',
756 'version' => $this->_apiversion,
757 );
758
759 $contact = civicrm_api('contact', 'create', $params);
760 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
761 );
762 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
763
764 // delete the contact
765 civicrm_api('contact', 'delete', $contact);
766 }
767 /**
768 * Verify that attempt to create individual contact with no data fails
769 */
770 function testCreateIndividualWithOutNameEmail() {
771 $params = array(
772 'contact_type' => 'Individual',
773 'version' => $this->_apiversion,
774 );
775
776 $result = civicrm_api('contact', 'create', $params);
777 $this->assertEquals(1, $result['is_error'], "In line " . __LINE__);
778 }
779 /**
780 * Verify that attempt to create individual contact with first
781 * and last names, email and location type succeeds
782 */
783 function testCreateIndividualWithNameEmailLocationType() {
784 $params = array(
785 'first_name' => 'abc4',
786 'last_name' => 'xyz4',
787 'email' => 'man4@yahoo.com',
788 'contact_type' => 'Individual',
789 'location_type_id' => 1,
790 'version' => $this->_apiversion,
791 );
792 $result = civicrm_api('contact', 'create', $params);
793
794 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
795 );
796 $this->assertEquals(1, $result['id'], "In line " . __LINE__);
797
798 // delete the contact
799 civicrm_api('contact', 'delete', $params);
800 }
801
802 /**
803 * Verify that when changing employers
804 * the old employer relationship becomes inactive
805 */
806 function testCreateIndividualWithEmployer() {
807 $employer = $this->organizationCreate();
808 $employer2 = $this->organizationCreate();
809
810 $params = array(
811 'email' => 'man4@yahoo.com',
812 'contact_type' => 'Individual',
813 'version' => $this->_apiversion,
814 'employer_id' => $employer,
815 );
816
817 $result = civicrm_api('contact', 'create', $params);
818 $this->assertAPISuccess($result, ' in line ' . __LINE__);
819 $relationships = civicrm_api('relationship', 'get', array(
820 'version' => $this->_apiversion,
821 'contact_id_a' => $result['id'],
822 'sequential' => 1,
823 ));
824
825 $this->assertEquals($employer, $relationships['values'][0]['contact_id_b']);
826
827 // Add more random relationships to make the test more realistic
828 foreach (array('Employee of', 'Volunteer for') as $rtype) {
829 $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $rtype, 'id', 'name_a_b');
830 $random_rel = civicrm_api('relationship', 'create', array(
831 'version' => $this->_apiversion,
832 'contact_id_a' => $result['id'],
833 'contact_id_b' => $this->organizationCreate(),
834 'is_active' => 1,
835 'relationship_type_id' => $relTypeId,
836 ));
837 $this->assertAPISuccess($random_rel, ' in line ' . __LINE__);
838 }
839
840 // Add second employer
841 $params['employer_id'] = $employer2;
842 $params['id'] = $result['id'];
843 $result = civicrm_api('contact', 'create', $params);
844 $this->assertAPISuccess($result, ' in line ' . __LINE__);
845
846 $relationships = civicrm_api('relationship', 'get', array(
847 'version' => $this->_apiversion,
848 'contact_id_a' => $result['id'],
849 'sequential' => 1,
850 'is_active' => 0,
851 ));
852
853 $this->assertEquals($employer, $relationships['values'][0]['contact_id_b']);
854 }
855
856 /**
857 * Verify that attempt to create household contact with details
858 * succeeds
859 */
860 function testCreateHouseholdDetails() {
861 $params = array(
862 'household_name' => 'abc8\'s House',
863 'nick_name' => 'x House',
864 'email' => 'man8@yahoo.com',
865 'contact_type' => 'Household',
866 'version' => $this->_apiversion,
867 );
868
869 $contact = civicrm_api('contact', 'create', $params);
870 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
871 );
872 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
873
874 // delete the contact
875 civicrm_api('contact', 'delete', $contact);
876 }
877 /**
878 * Verify that attempt to create household contact with inadequate details
879 * fails
880 */
881 function testCreateHouseholdInadequateDetails() {
882 $params = array(
883 'nick_name' => 'x House',
884 'email' => 'man8@yahoo.com',
885 'contact_type' => 'Household',
886 'version' => $this->_apiversion,
887 );
888
889 $result = civicrm_api('contact', 'create', $params);
890 $this->assertEquals(1, $result['is_error'], 'should fail due to missing household name on line ' . __LINE__);
891 }
892
893 /**
894 * Test civicrm_contact_check_params with params and no checkss
895 */
896 function testCheckParamsWithNoCheckss() {
897 $params = array();
898 $contact = _civicrm_api3_contact_check_params($params, FALSE, FALSE, FALSE);
899 $this->assertNull($contact, "In line " . __LINE__);
900 }
901
902
903 /**
904 * Verify successful update of individual contact
905 */
906 function testUpdateIndividualWithAll() {
907 // Insert a row in civicrm_contact creating individual contact
908 $op = new PHPUnit_Extensions_Database_Operation_Insert();
909 $op->execute($this->_dbconn,
910 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
911 dirname(__FILE__) . '/dataset/contact_ind.xml'
912 )
913 );
914
915 $params = array(
916 'id' => 23,
917 'first_name' => 'abcd',
918 'contact_type' => 'Individual',
919 'nick_name' => 'This is nickname first',
920 'do_not_email' => '1',
921 'do_not_phone' => '1',
922 'do_not_mail' => '1',
923 'do_not_trade' => '1',
924 'legal_identifier' => 'ABC23853ZZ2235',
925 'external_identifier' => '1928837465',
926 'image_URL' => 'http://some.url.com/image.jpg',
927 'home_url' => 'http://www.example.org',
928 'preferred_mail_format' => 'HTML',
929 'version' => $this->_apiversion,
930 );
931 $getResult = civicrm_api('Contact', 'Get', array('version' => $this->_apiversion));
932 $result = civicrm_api('Contact', 'Update', $params);
933 $getResult = civicrm_api('Contact', 'Get', $params);
934 // Result should indicate successful update
935 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__);
936 unset($params['version']);
937 unset($params['contact_id']);
938 //Todo - neither API v2 or V3 are testing for home_url - not sure if it is being set.
939 //reducing this test partially back to apiv2 level to get it through
940 unset($params['home_url']);
941 foreach ($params as $key => $value) {
942 $this->assertEquals($value, $result['values'][23][$key], "In line " . __LINE__);
943 }
944 // Check updated civicrm_contact against expected
945 $expected = new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
946 dirname(__FILE__) . '/dataset/contact_ind_upd.xml'
947 );
948 $actual = new PHPUnit_Extensions_Database_DataSet_QueryDataset(
949 $this->_dbconn
950 );
951 $actual->addTable('civicrm_contact');
952 $expected->matches($actual);
953 }
954
955 /**
956 * Verify successful update of organization contact
957 */
958 function testUpdateOrganizationWithAll() {
959 // Insert a row in civicrm_contact creating organization contact
960 $op = new PHPUnit_Extensions_Database_Operation_Insert();
961 $op->execute($this->_dbconn,
962 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
963 dirname(__FILE__) . '/dataset/contact_org.xml'
964 )
965 );
966
967 $params = array(
968 'id' => 24,
969 'organization_name' => 'WebAccess India Pvt Ltd',
970 'legal_name' => 'WebAccess',
971 'sic_code' => 'ABC12DEF',
972 'contact_type' => 'Organization',
973 'version' => $this->_apiversion,
974 );
975
976 $result = civicrm_api('Contact', 'Update', $params);
977
978 $expected = array(
979 'is_error' => 0,
980 'id' => 24,
981 );
982
983 // Result should indicate successful update
984 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
985 );
986
987 // Check updated civicrm_contact against expected
988 $expected = new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
989 dirname(__FILE__) . '/dataset/contact_org_upd.xml'
990 );
991 $actual = new PHPUnit_Extensions_Database_DataSet_QueryDataset(
992 $this->_dbconn
993 );
994 $actual->addTable('civicrm_contact');
995 $expected->matches($actual);
996 }
997
998 /**
999 * Verify successful update of household contact
1000 */
1001 function testUpdateHouseholdwithAll() {
1002 // Insert a row in civicrm_contact creating household contact
1003 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1004 $op->execute($this->_dbconn,
1005 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1006 dirname(__FILE__) . '/dataset/contact_hld.xml'
1007 )
1008 );
1009
1010 $params = array(
1011 'id' => 25,
1012 'household_name' => 'ABC household',
1013 'nick_name' => 'ABC House',
1014 'contact_type' => 'Household',
1015 'version' => $this->_apiversion,
1016 );
1017
1018 $result = civicrm_api('Contact', 'Update', $params);
1019
1020 $expected = array(
1021 'is_error' => 0,
1022 'contact_id' => 25,
1023 );
1024
1025 // Result should indicate successful update
1026 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
1027 );
1028
1029 // Check updated civicrm_contact against expected
1030 $expected = new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1031 dirname(__FILE__) . '/dataset/contact_hld_upd.xml'
1032 );
1033 $actual = new PHPUnit_Extensions_Database_DataSet_QueryDataset(
1034 $this->_dbconn
1035 );
1036 $actual->addTable('civicrm_contact');
1037 $expected->matches($actual);
1038 }
1039
1040 /**
1041 * Test civicrm_update() Deliberately exclude contact_type as it should still
1042 * cope using civicrm_api CRM-7645
1043 */
1044
1045 public function testUpdateCreateWithID() {
1046 // Insert a row in civicrm_contact creating individual contact
1047 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1048 $op->execute($this->_dbconn,
1049 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1050 dirname(__FILE__) . '/dataset/contact_ind.xml'
1051 )
1052 );
1053
1054
1055
1056 $params = array(
1057 'id' => 23,
1058 'first_name' => 'abcd',
1059 'last_name' => 'wxyz',
1060 'version' => $this->_apiversion,
1061 );
1062
1063 $result = civicrm_api('Contact', 'Update', $params);
1064 $this->assertTrue(is_array($result));
1065 $this->assertEquals(0, $result['is_error']);
1066 }
1067
1068 /**
1069 * Test civicrm_contact_delete() with no contact ID
1070 */
1071 function testContactDeleteNoID() {
1072 $params = array(
1073 'foo' => 'bar',
1074 'version' => $this->_apiversion,
1075 );
1076 $result = civicrm_api('contact', 'delete', $params);
1077 $this->assertEquals(1, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
1078 );
1079 }
1080
1081 /**
1082 * Test civicrm_contact_delete() with error
1083 */
1084 function testContactDeleteError() {
1085 $params = array('contact_id' => 17);
1086 $result = civicrm_api('contact', 'delete', $params);
1087 $this->assertEquals(1, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
1088 );
1089 }
1090
1091 /**
1092 * Test civicrm_contact_delete()
1093 */
1094 function testContactDelete() {
1095 // Insert a row in civicrm_contact creating contact 17
1096 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1097 $op->execute($this->_dbconn,
1098 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1099 dirname(__FILE__) . '/dataset/contact_17.xml'
1100 )
1101 );
1102 $params = array(
1103 'id' => 17,
1104 'version' => $this->_apiversion,
1105 );
1106 $result = civicrm_api('contact', 'delete', $params);
1107 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
1108 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
1109 );
1110 }
1111
1112 /**
1113 * Test civicrm_contact_get() return only first name
1114 */
1115 public function testContactGetRetFirst() {
1116 $contact = civicrm_api('contact', 'create', $this->_params);
1117 $params = array(
1118 'contact_id' => $contact['id'],
1119 'return' => 'first_name, last_name',
1120 'version' => $this->_apiversion,
1121 );
1122 $params = array(
1123 'contact_id' => $contact['id'],
1124 'return_first_name' => TRUE,
1125 'sort' => 'first_name',
1126 'version' => $this->_apiversion,
1127 );
1128 $result = civicrm_api('contact', 'get', $params);
1129 $this->assertEquals(1, $result['count'], "In line " . __LINE__);
1130 $this->assertEquals($contact['id'], $result['id'], "In line " . __LINE__);
1131 $this->assertEquals('abc1', $result['values'][$contact['id']]['first_name'], "In line " . __LINE__);
1132 }
1133
1134 /**
1135 * Test civicrm_contact_get() return only first name & last name
1136 * Use comma separated string return with a space
1137 */
1138 public function testContactGetRetFirstLast() {
1139 $contact = civicrm_api('contact', 'create', $this->_params);
1140 $params = array(
1141 'contact_id' => $contact['id'],
1142 'return' => 'first_name, last_name',
1143 'version' => $this->_apiversion,
1144 );
1145 $result = civicrm_api('contact', 'getsingle', $params);
1146 $this->assertEquals('abc1', $result['first_name'], "In line " . __LINE__);
1147 $this->assertEquals('xyz1', $result['last_name'], "In line " . __LINE__);
1148 //check that other defaults not returns
1149 $this->assertArrayNotHasKey('sort_name', $result);
1150 $params = array(
1151 'contact_id' => $contact['id'],
1152 'return' => 'first_name,last_name',
1153 'version' => $this->_apiversion,
1154 );
1155 $result = civicrm_api('contact', 'getsingle', $params);
1156 $this->assertEquals('abc1', $result['first_name'], "In line " . __LINE__);
1157 $this->assertEquals('xyz1', $result['last_name'], "In line " . __LINE__);
1158 //check that other defaults not returns
1159 $this->assertArrayNotHasKey('sort_name', $result);
1160 }
1161
1162 /**
1163 * Test civicrm_contact_get() return only first name & last name
1164 * Use comma separated string return without a space
1165 */
1166 public function testContactGetRetFirstLastNoComma() {
1167 $contact = civicrm_api('contact', 'create', $this->_params);
1168 $params = array(
1169 'contact_id' => $contact['id'],
1170 'return' => 'first_name,last_name',
1171 'version' => $this->_apiversion,
1172 );
1173 $result = civicrm_api('contact', 'getsingle', $params);
1174 $this->assertEquals('abc1', $result['first_name'], "In line " . __LINE__);
1175 $this->assertEquals('xyz1', $result['last_name'], "In line " . __LINE__);
1176 //check that other defaults not returns
1177 $this->assertArrayNotHasKey('sort_name', $result);
1178 }
1179
1180 /**
1181 * Test civicrm_contact_get() with default return properties
1182 */
1183 public function testContactGetRetDefault() {
1184 // Insert a row in civicrm_contact creating contact 17
1185 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1186 $op->execute($this->_dbconn,
1187 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1188 dirname(__FILE__) . '/dataset/contact_17.xml'
1189 )
1190 );
1191 $params = array(
1192 'contact_id' => 17,
1193 'sort' => 'first_name',
1194 'version' => $this->_apiversion,
1195 );
1196 $result = civicrm_api('contact', 'get', $params);
1197 $this->assertEquals(17, $result['values'][17]['contact_id'], "In line " . __LINE__);
1198 $this->assertEquals('Test', $result['values'][17]['first_name'], "In line " . __LINE__);
1199 }
1200
1201 /**
1202 * Test civicrm_contact_quicksearch() with empty name param
1203 */
1204 public function testContactGetQuickEmpty() {
1205 $params = array(
1206 'version' => $this->_apiversion,
1207 );
1208 $result = civicrm_api('contact', 'getquick', $params);
1209 $this->assertTrue(is_array($result), 'in line ' . __LINE__);
1210 $this->assertEquals(1, $result['is_error'], 'in line ' . __LINE__);
1211 }
1212
1213 /**
1214 * Test civicrm_contact_quicksearch() with empty name param
1215 */
1216 public function testContactGetQuick() {
1217 // Insert a row in civicrm_contact creating individual contact
1218 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1219 $op->execute($this->_dbconn,
1220 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1221 dirname(__FILE__) . '/dataset/contact_17.xml'
1222 )
1223 );
1224 $op->execute($this->_dbconn,
1225 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1226 dirname(__FILE__) . '/dataset/email_contact_17.xml'
1227 )
1228 );
1229 $params = array(
1230 'name' => "T",
1231 'version' => $this->_apiversion,
1232 );
1233
1234 $result = civicrm_api('contact', 'quicksearch', $params);
1235 $this->assertTrue(is_array($result), 'in line ' . __LINE__);
1236 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__);
1237 $this->assertEquals(17, $result['values'][0]['id'], 'in line ' . __LINE__);
1238 }
1239
1240 /**
1241 * Test civicrm_contact_get) with empty params
1242 */
1243 public function testContactGetEmptyParams() {
1244 $params = array();
1245 $result = civicrm_api('contact', 'get', $params);
1246
1247 $this->assertTrue(is_array($result), 'in line ' . __LINE__);
1248 $this->assertEquals(1, $result['is_error'], 'in line ' . __LINE__);
1249 }
1250
1251 /**
1252 * Test civicrm_contact_get(,true) with params not array
1253 */
1254 public function testContactGetParamsNotArray() {
1255 $params = 17;
1256 $result = civicrm_api('contact', 'get', $params, TRUE);
1257 $this->assertTrue(is_array($result));
1258 $this->assertEquals(1, $result['is_error']);
1259 $this->assertRegexp("/not.*array/s",
1260 CRM_Utils_Array::value('error_message', $result)
1261 );
1262 }
1263
1264 /**
1265 * Test civicrm_contact_get(,true) with no matches
1266 */
1267 public function testContactGetOldParamsNoMatches() {
1268 // Insert a row in civicrm_contact creating contact 17
1269 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1270 $op->execute($this->_dbconn,
1271 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1272 dirname(__FILE__) . '/dataset/contact_17.xml'
1273 )
1274 );
1275
1276 $params = array(
1277 'first_name' => 'Fred',
1278 'version' => $this->_apiversion,
1279 );
1280 $result = civicrm_api('contact', 'get', $params);
1281 $this->assertTrue(is_array($result), 'in line ' . __LINE__);
1282 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__);
1283 $this->assertEquals(0, $result['count'], 'in line ' . __LINE__);
1284 }
1285
1286 /**
1287 * Test civicrm_contact_get(,true) with one match
1288 */
1289 public function testContactGetOldParamsOneMatch() {
1290 // Insert a row in civicrm_contact creating contact 17
1291 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1292 $op->execute($this->_dbconn,
1293 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/contact_17.xml'
1294 )
1295 );
1296
1297 $params = array(
1298 'first_name' => 'Test',
1299 'version' => $this->_apiversion,
1300 );
1301 $result = civicrm_api('contact', 'get', $params);
1302 $this->assertTrue(is_array($result));
1303 $this->assertEquals(0, $result['is_error'], 'in line ' . __LINE__);
1304 $this->assertEquals(17, $result['values'][17]['contact_id'], 'in line ' . __LINE__);
1305 $this->assertEquals(17, $result['id'], 'in line ' . __LINE__);
1306 }
1307 /*
1308 * seems contribution is no longer creating activity - test is in the too hard basket for now
1309 public function testContactGetWithActivityies(){
1310 $params = array(
1311 'email' => 'man2@yahoo.com',
1312 'contact_type' => 'Individual',
1313 'location_type_id' => 1,
1314 'version' => $this->_apiversion,
1315 'api.contribution.create' => array(
1316
1317 'receive_date' => '2010-01-01',
1318 'total_amount' => 100.00,
1319 'financial_type_id' => 1,
1320 'payment_instrument_id' => 1,
1321 'non_deductible_amount' => 10.00,
1322 'fee_amount' => 50.00,
1323 'net_amount' => 90.00,
1324 'trxn_id' => 15343455,
1325 'invoice_id' => 6755990,
1326 'source' => 'SSF',
1327 'contribution_status_id' => 1,
1328 ),
1329
1330 );
1331
1332 $contact = civicrm_api('Contact', 'Create',$params);
1333 $params = array('version' => $this->_apiversion, 'id' => $contact['id'], 'api.activity' => array());
1334 $result = civicrm_api('Contact', 'Get', $params);
1335 $this->documentMe($params,$result,__FUNCTION__,__FILE__);
1336 $this->assertGreaterThan(0, $result['values'][$result['id']]['api.activity']['count']);
1337 $this->assertEquals('Contribution', $result['values'][$result['id']]['api.activity']['values'][0]['activity_name']);
1338 }
1339 */
1340
1341 /**
1342 * Test civicrm_contact_search_count()
1343 */
1344 public function testContactGetEmail() {
1345 $params = array(
1346 'email' => 'man2@yahoo.com',
1347 'contact_type' => 'Individual',
1348 'location_type_id' => 1,
1349 'version' => $this->_apiversion,
1350 );
1351
1352 $contact = civicrm_api('contact', 'create', $params);
1353 $this->assertApiSuccess($contact, "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $contact)
1354 );
1355 $this->assertEquals(1, $contact['id'], "In line " . __LINE__);
1356
1357 $params = array(
1358 'email' => 'man2@yahoo.com',
1359 'version' => $this->_apiversion,
1360 );
1361 $result = civicrm_api('contact', 'get', $params);
1362 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
1363 $this->assertEquals(1, $result['values'][1]['contact_id'], "In line " . __LINE__);
1364 $this->assertEquals('man2@yahoo.com', $result['values'][1]['email'], "In line " . __LINE__);
1365
1366 // delete the contact
1367 civicrm_api('contact', 'delete', $contact);
1368 }
1369
1370 /**
1371 * Verify attempt to create individual with chained arrays
1372 */
1373 function testGetIndividualWithChainedArrays() {
1374 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
1375 $params['custom_' . $ids['custom_field_id']] = "custom string";
1376
1377 $moreids = $this->CustomGroupMultipleCreateWithFields();
1378 $description = "/*this demonstrates the usage of chained api functions. In this case no notes or custom fields have been created ";
1379 $subfile = "APIChainedArray";
1380 $params = array(
1381 'first_name' => 'abc3',
1382 'last_name' => 'xyz3',
1383 'contact_type' => 'Individual',
1384 'email' => 'man3@yahoo.com',
1385 'version' => $this->_apiversion,
1386 'api.contribution.create' => array(
1387 'receive_date' => '2010-01-01',
1388 'total_amount' => 100.00,
1389 'financial_type_id' => 1,
1390 'payment_instrument_id' => 1,
1391 'non_deductible_amount' => 10.00,
1392 'fee_amount' => 50.00,
1393 'net_amount' => 90.00,
1394 'trxn_id' => 12345,
1395 'invoice_id' => 67890,
1396 'source' => 'SSF',
1397 'contribution_status_id' => 1,
1398 ),
1399 'api.contribution.create.1' => array(
1400 'receive_date' => '2011-01-01',
1401 'total_amount' => 120.00,
1402 'financial_type_id' => $this->_contributionTypeId,
1403 'payment_instrument_id' => 1,
1404 'non_deductible_amount' => 10.00,
1405 'fee_amount' => 50.00,
1406 'net_amount' => 90.00,
1407 'trxn_id' => 12335,
1408 'invoice_id' => 67830,
1409 'source' => 'SSF',
1410 'contribution_status_id' => 1,
1411 ),
1412 'api.website.create' => array(
1413 array(
1414 'url' => "http://civicrm.org",
1415 ),
1416 ),
1417 );
1418
1419 $result = civicrm_api('Contact', 'create', $params);
1420 $this->assertAPISuccess($result);
1421 $params = array(
1422 'id' => $result['id'], 'version' => $this->_apiversion,
1423 'api.website.get' => array(),
1424 'api.Contribution.get' => array(
1425 'total_amount' => '120.00',
1426 ), 'api.CustomValue.get' => 1,
1427 'api.Note.get' => 1,
1428 );
1429 $result = civicrm_api('Contact', 'Get', $params);
1430 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1431 // delete the contact
1432 civicrm_api('contact', 'delete', $result);
1433 $this->customGroupDelete($ids['custom_group_id']);
1434 $this->customGroupDelete($moreids['custom_group_id']);
1435 $this->assertEquals(0, $result['is_error'], "In line " . __LINE__ . " error message: " . CRM_Utils_Array::value('error_message', $result)
1436 );
1437 $this->assertEquals(1, $result['id'], "In line " . __LINE__);
1438 $this->assertEquals(0, $result['values'][$result['id']]['api.website.get']['is_error'], "In line " . __LINE__);
1439 $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.get']['values'][0]['url'], "In line " . __LINE__);
1440 }
1441
1442 function testGetIndividualWithChainedArraysFormats() {
1443 $description = "/*this demonstrates the usage of chained api functions. A variety of return formats are used. Note that no notes
1444 *custom fields or memberships exist";
1445 $subfile = "APIChainedArrayFormats";
1446 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
1447 $params['custom_' . $ids['custom_field_id']] = "custom string";
1448
1449 $moreids = $this->CustomGroupMultipleCreateWithFields();
1450 $params = array(
1451 'first_name' => 'abc3',
1452 'last_name' => 'xyz3',
1453 'contact_type' => 'Individual',
1454 'email' => 'man3@yahoo.com',
1455 'version' => $this->_apiversion,
1456 'api.contribution.create' => array(
1457 'receive_date' => '2010-01-01',
1458 'total_amount' => 100.00,
1459 'financial_type_id' => $this->_contributionTypeId,
1460 'payment_instrument_id' => 1,
1461 'non_deductible_amount' => 10.00,
1462 'fee_amount' => 50.00,
1463 'net_amount' => 90.00,
1464 'source' => 'SSF',
1465 'contribution_status_id' => 1,
1466 ),
1467 'api.contribution.create.1' => array(
1468 'receive_date' => '2011-01-01',
1469 'total_amount' => 120.00,
1470 'financial_type_id' => $this->_contributionTypeId,
1471 'payment_instrument_id' => 1,
1472 'non_deductible_amount' => 10.00,
1473 'fee_amount' => 50.00,
1474 'net_amount' => 90.00,
1475 'source' => 'SSF',
1476 'contribution_status_id' => 1,
1477 ),
1478 'api.website.create' => array(
1479 array(
1480 'url' => "http://civicrm.org",
1481 ),
1482 ),
1483 );
1484
1485
1486 $result = civicrm_api('Contact', 'create', $params);
1487 $this->assertAPISuccess($result, 'in line ' . __LINE__);
1488 $this->assertAPISuccess($result['values'][$result['id']]['api.contribution.create'], 'in line ' . __LINE__);
1489 $params = array(
1490 'id' => $result['id'], 'version' => $this->_apiversion,
1491 'api.website.getValue' => array('return' => 'url'),
1492 'api.Contribution.getCount' => array(),
1493 'api.CustomValue.get' => 1,
1494 'api.Note.get' => 1,
1495 'api.Membership.getCount' => array(),
1496 );
1497 $result = civicrm_api('Contact', 'Get', $params);
1498 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1499 $this->assertAPISuccess($result, 'in line ' . __LINE__);
1500 $this->assertEquals(1, $result['id'], "In line " . __LINE__);
1501 $this->assertEquals(2, $result['values'][$result['id']]['api.Contribution.getCount'], "In line " . __LINE__);
1502 $this->assertEquals(0, $result['values'][$result['id']]['api.Note.get']['is_error'], "In line " . __LINE__);
1503 $this->assertEquals("http://civicrm.org", $result['values'][$result['id']]['api.website.getValue'], "In line " . __LINE__);
1504 // delete the contact
1505
1506 $params = array(
1507 'id' => $result['id'], 'version' => $this->_apiversion,
1508 'api_Contribution_get' => array(),
1509 'sequential' => 1,
1510 'format.smarty' => 'api/v3/exampleLetter.tpl',
1511 );
1512 $subfile = 'smartyExample';
1513 $description = "demonstrates use of smarty as output";
1514 $result = civicrm_api('Contact', 'Get', $params);
1515 // $this->documentMe($params,$result,__FUNCTION__,__FILE__,$description,$subfile);
1516 // $this->assertContains('USD', $result);
1517 // $this->assertContains('Dear', $result);
1518 // $this->assertContains('Friday', $result);
1519
1520 civicrm_api('contact', 'delete', $result);
1521 $this->customGroupDelete($ids['custom_group_id']);
1522 $this->customGroupDelete($moreids['custom_group_id']);
1523 }
1524
1525 function testGetIndividualWithChainedArraysAndMultipleCustom() {
1526 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__);
1527 $params['custom_' . $ids['custom_field_id']] = "custom string";
1528 $moreids = $this->CustomGroupMultipleCreateWithFields();
1529 $andmoreids = $this->CustomGroupMultipleCreateWithFields(array('title' => "another group"));
1530 $description = "/*this demonstrates the usage of chained api functions. A variety of techniques are used";
1531 $subfile = "APIChainedArrayMultipleCustom";
1532 $params = array(
1533 'first_name' => 'abc3',
1534 'last_name' => 'xyz3',
1535 'contact_type' => 'Individual',
1536 'email' => 'man3@yahoo.com',
1537 'version' => $this->_apiversion,
1538 'api.contribution.create' => array(
1539 'receive_date' => '2010-01-01',
1540 'total_amount' => 100.00,
1541 'financial_type_id' => 1,
1542 'payment_instrument_id' => 1,
1543 'non_deductible_amount' => 10.00,
1544 'fee_amount' => 50.00,
1545 'net_amount' => 90.00,
1546 'trxn_id' => 12345,
1547 'invoice_id' => 67890,
1548 'source' => 'SSF',
1549 'contribution_status_id' => 1,
1550 ),
1551 'api.contribution.create.1' => array(
1552 'receive_date' => '2011-01-01',
1553 'total_amount' => 120.00,
1554 'financial_type_id' => 1,
1555 'payment_instrument_id' => 1,
1556 'non_deductible_amount' => 10.00,
1557 'fee_amount' => 50.00,
1558 'net_amount' => 90.00,
1559 'trxn_id' => 12335,
1560 'invoice_id' => 67830,
1561 'source' => 'SSF',
1562 'contribution_status_id' => 1,
1563 ),
1564 'api.website.create' => array(
1565 array(
1566 'url' => "http://civicrm.org",
1567 ),
1568 ),
1569 'custom_' . $ids['custom_field_id'] => "value 1",
1570 'custom_' . $moreids['custom_field_id'][0] => "value 2",
1571 'custom_' . $moreids['custom_field_id'][1] => "warm beer",
1572 'custom_' . $andmoreids['custom_field_id'][1] => "vegemite",
1573 );
1574
1575
1576 $result = civicrm_api('Contact', 'create', $params);
1577 $result = civicrm_api('Contact', 'create', array(
1578 'contact_type' => 'Individual', 'id' => $result['id'], 'version' => $this->_apiversion, 'custom_' . $moreids['custom_field_id'][0] => "value 3", 'custom_' . $ids['custom_field_id'] => "value 4",
1579 ));
1580
1581 $params = array(
1582 'id' => $result['id'], 'version' => $this->_apiversion,
1583 'api.website.getValue' => array('return' => 'url'),
1584 'api.Contribution.getCount' => array(),
1585 'api.CustomValue.get' => 1,
1586 );
1587 $result = civicrm_api('Contact', 'Get', $params);
1588 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1589 // delete the contact
1590 civicrm_api('contact', 'delete', $result);
1591 $this->customGroupDelete($ids['custom_group_id']);
1592 $this->customGroupDelete($moreids['custom_group_id']);
1593 $this->customGroupDelete($andmoreids['custom_group_id']);
1594 $this->assertAPISuccess($result, "In line " . __LINE__);
1595 $this->assertEquals(1, $result['id'], "In line " . __LINE__);
1596 $this->assertEquals(0, $result['values'][$result['id']]['api.CustomValue.get']['is_error'], "In line " . __LINE__);
1597 $this->assertEquals('http://civicrm.org', $result['values'][$result['id']]['api.website.getValue'], "In line " . __LINE__);
1598 }
1599 /*
1600 * Test checks siusage of $values to pick & choose inputs
1601 */
1602 function testChainingValuesCreate() {
1603 $description = "/*this demonstrates the usage of chained api functions. Specifically it has one 'parent function' &
1604 2 child functions - one receives values from the parent (Contact) and the other child (Tag). ";
1605 $subfile = "APIChainedArrayValuesFromSiblingFunction";
1606 $params = array(
1607 'version' => $this->_apiversion, 'display_name' => 'batman', 'contact_type' => 'Individual',
1608 'api.tag.create' => array('name' => '$value.id', 'description' => '$value.display_name', 'format.only_id' => 1),
1609 'api.entity_tag.create' => array('tag_id' => '$value.api.tag.create'),
1610 );
1611 $result = civicrm_api('Contact', 'Create', $params);
1612
1613 $this->assertEquals(0, $result['is_error']);
1614 $this->assertEquals(0, $result['values'][$result['id']]['api.entity_tag.create']['is_error']);
1615 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1616 $tablesToTruncate = array(
1617 'civicrm_contact',
1618 'civicrm_activity',
1619 'civicrm_entity_tag',
1620 'civicrm_tag',
1621 );
1622 $this->quickCleanup($tablesToTruncate, TRUE);
1623 }
1624
1625 /*
1626 * test TrueFalse format - I couldn't come up with an easy way to get an error on Get
1627 */
1628 function testContactGetFormatIsSuccessTrue() {
1629 $this->createContactFromXML();
1630 $description = "This demonstrates use of the 'format.is_success' param.
1631 This param causes only the success or otherwise of the function to be returned as BOOLEAN";
1632 $subfile = "FormatIsSuccess_True";
1633 $params = array('version' => $this->_apiversion, 'id' => 17, 'format.is_success' => 1);
1634 $result = civicrm_api('Contact', 'Get', $params);
1635 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1636 $this->assertEquals(1, $result);
1637 civicrm_api('Contact', 'Delete', $params);
1638 }
1639 /*
1640 * test TrueFalse format
1641 */
1642 function testContactCreateFormatIsSuccessFalse() {
1643
1644 $description = "This demonstrates use of the 'format.is_success' param.
1645 This param causes only the success or otherwise of the function to be returned as BOOLEAN";
1646 $subfile = "FormatIsSuccess_Fail";
1647 $params = array('version' => $this->_apiversion, 'id' => 500, 'format.is_success' => 1);
1648 $result = civicrm_api('Contact', 'Create', $params);
1649 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1650 $this->assertEquals(0, $result);
1651 }
1652 /*
1653 * test Single Entity format
1654 */
1655 function testContactGetSingle_entity_array() {
1656 $this->createContactFromXML();
1657 $description = "This demonstrates use of the 'format.single_entity_array' param.
1658 /* This param causes the only contact to be returned as an array without the other levels.
1659 /* it will be ignored if there is not exactly 1 result";
1660 $subfile = "GetSingleContact";
1661 $params = array('version' => $this->_apiversion, 'id' => 17);
1662 $result = civicrm_api('Contact', 'GetSingle', $params);
1663 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1664 $this->assertEquals('Test Contact', $result['display_name'], "in line " . __LINE__);
1665 civicrm_api('Contact', 'Delete', $params);
1666 }
1667
1668 /*
1669 * test Single Entity format
1670 */
1671 function testContactGetFormatcount_only() {
1672 $this->createContactFromXML();
1673 $description = "/*This demonstrates use of the 'getCount' action
1674 /* This param causes the count of the only function to be returned as an integer";
1675 $subfile = "GetCountContact";
1676 $params = array('version' => $this->_apiversion, 'id' => 17);
1677 $result = civicrm_api('Contact', 'GetCount', $params);
1678 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1679 $this->assertEquals('1', $result, "in line " . __LINE__);
1680 civicrm_api('Contact', 'Delete', $params);
1681 }
1682 /*
1683 * Test id only format
1684 */
1685 function testContactGetFormatID_only() {
1686 $this->createContactFromXML();
1687 $description = "This demonstrates use of the 'format.id_only' param.
1688 /* This param causes the id of the only entity to be returned as an integer.
1689 /* it will be ignored if there is not exactly 1 result";
1690 $subfile = "FormatOnlyID";
1691 $params = array('version' => $this->_apiversion, 'id' => 17, 'format.only_id' => 1);
1692 $result = civicrm_api('Contact', 'Get', $params);
1693 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
1694 $this->assertEquals('17', $result, "in line " . __LINE__);
1695 civicrm_api('Contact', 'Delete', $params);
1696 }
1697
1698 /*
1699 * Test id only format
1700 */
1701 function testContactGetFormatSingleValue() {
1702 $this->createContactFromXML();
1703 $description = "This demonstrates use of the 'format.single_value' param.
1704 /* This param causes only a single value of the only entity to be returned as an string.
1705 /* it will be ignored if there is not exactly 1 result";
1706 $subfile = "FormatSingleValue";
1707 $params = array('version' => $this->_apiversion, 'id' => 17, 'return' => 'display_name');
1708 $result = civicrm_api('Contact', 'getvalue', $params);
1709 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile,'getvalue');
1710 $this->assertEquals('Test Contact', $result, "in line " . __LINE__);
1711 civicrm_api('Contact', 'Delete', $params);
1712 }
1713
1714 function testContactCreationPermissions() {
1715 $params = array(
1716 'contact_type' => 'Individual', 'first_name' => 'Foo',
1717 'last_name' => 'Bear',
1718 'check_permissions' => TRUE,
1719 'version' => $this->_apiversion,
1720 );
1721 $config = CRM_Core_Config::singleton();
1722 $config->userPermissionClass->permissions = array('access CiviCRM');
1723 $result = civicrm_api('contact', 'create', $params);
1724 $this->assertEquals(1, $result['is_error'], 'lacking permissions should not be enough to create a contact');
1725 $this->assertEquals('API permission check failed for contact/create call; missing permission: add contacts.', $result['error_message'], 'lacking permissions should not be enough to create a contact');
1726
1727 $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'import contacts');
1728 $result = civicrm_api('contact', 'create', $params);
1729 $this->assertEquals(0, $result['is_error'], 'overfluous permissions should be enough to create a contact');
1730 }
1731
1732 function testContactUpdatePermissions() {
1733 $params = array('contact_type' => 'Individual', 'first_name' => 'Foo', 'last_name' => 'Bear', 'check_permissions' => TRUE, 'version' => $this->_apiversion);
1734 $result = civicrm_api('contact', 'create', $params);
1735 $config = CRM_Core_Config::singleton();
1736 $params = array('id' => $result['id'], 'contact_type' => 'Individual', 'last_name' => 'Bar', 'check_permissions' => TRUE, 'version' => $this->_apiversion);
1737
1738 $config->userPermissionClass->permissions = array('access CiviCRM');
1739 $result = civicrm_api('contact', 'update', $params);
1740 $this->assertEquals(1, $result['is_error'], 'lacking permissions should not be enough to update a contact');
1741 $this->assertEquals('API permission check failed for contact/update call; missing permission: edit all contacts.', $result['error_message'], 'lacking permissions should not be enough to update a contact');
1742
1743 $config->userPermissionClass->permissions = array('access CiviCRM', 'add contacts', 'view all contacts', 'edit all contacts', 'import contacts');
1744
1745 $result = civicrm_api('contact', 'update', $params);
1746 $this->assertEquals(0, $result['is_error'], 'overfluous permissions should be enough to update a contact');
1747 }
1748
1749 function createContactFromXML() {
1750 // Insert a row in civicrm_contact creating contact 17
1751 $op = new PHPUnit_Extensions_Database_Operation_Insert();
1752 $op->execute($this->_dbconn,
1753 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
1754 dirname(__FILE__) . '/dataset/contact_17.xml'
1755 )
1756 );
1757 }
1758
1759 function testContactProximity() {
1760 // first create a contact with a SF location with a specific
1761 // geocode
1762 $contactID = $this->organizationCreate();
1763
1764 // now create the address
1765 $params = array(
1766 'street_address' => '123 Main Street',
1767 'city' => 'San Francisco',
1768 'is_primary' => 1,
1769 'country_id' => 1228,
1770 'state_province_id' => 1004,
1771 'geo_code_1' => '37.79',
1772 'geo_code_2' => '-122.40',
1773 'location_type_id' => 1,
1774 'contact_id' => $contactID,
1775 'version' => $this->_apiversion,
1776 );
1777
1778 $result = civicrm_api('address', 'create', $params);
1779 $this->assertAPISuccess($result, 'In line ' . __LINE__);
1780 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
1781
1782 // now do a proximity search with a close enough geocode and hope to match
1783 // that specific contact only!
1784 $proxParams = array(
1785 'latitude' => 37.7,
1786 'longitude' => -122.3,
1787 'unit' => 'mile',
1788 'distance' => 10,
1789 'version' => $this->_apiversion,
1790 );
1791 $result = civicrm_api('contact', 'proximity', $proxParams);
1792 $this->assertAPISuccess($result, 'In line ' . __LINE__);
1793 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
1794 }
1795 }