3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test APIv3 civicrm_im_* functions
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contact
19 class api_v3_ImTest
extends CiviUnitTestCase
{
24 public $DBResetRequired = FALSE;
26 public function setUp() {
28 $this->useTransaction(TRUE);
30 $this->_entity
= 'im';
31 $this->_contactID
= $this->organizationCreate();
33 'contact_id' => $this->_contactID
,
34 'name' => 'My Yahoo IM Handle',
35 'location_type_id' => 1,
43 * @dataProvider versionThreeAndFour
47 public function testCreateIm($version) {
48 $this->_apiversion
= $version;
49 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
50 $this->assertEquals(1, $result['count']);
51 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
52 $this->assertNotNull($result['values'][$result['id']]['id']);
56 * If no location is specified when creating a new IM, it should default to
57 * the LocationType default
60 * @dataProvider versionThreeAndFour
62 public function testCreateImDefaultLocation($version) {
63 $this->_apiversion
= $version;
64 $params = $this->_params
;
65 unset($params['location_type_id']);
66 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
67 $this->assertEquals(CRM_Core_BAO_LocationType
::getDefault()->id
, $result['values'][$result['id']]['location_type_id']);
68 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
74 * @dataProvider versionThreeAndFour
76 public function testGetIm($version) {
77 $this->_apiversion
= $version;
78 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
79 $result = $this->callAPIAndDocument($this->_entity
, 'get', $this->_params
, __FUNCTION__
, __FILE__
);
80 $this->assertEquals(1, $result['count']);
81 $this->assertNotNull($result['values'][$result['id']]['id']);
82 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
88 * @dataProvider versionThreeAndFour
90 public function testDeleteIm($version) {
91 $this->_apiversion
= $version;
92 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
93 $deleteParams = ['id' => $result['id']];
94 $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
95 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
96 $this->assertEquals(0, $checkDeleted['count']);
100 * Skip api4 test - delete behaves differently
102 public function testDeleteImInvalid() {
103 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
104 $deleteParams = ['id' => 600];
105 $this->callAPIFailure($this->_entity
, 'delete', $deleteParams);
106 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
107 $this->assertEquals(1, $checkDeleted['count']);