3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test APIv3 civicrm_im_* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contact
35 class api_v3_ImTest
extends CiviUnitTestCase
{
40 public $DBResetRequired = FALSE;
42 public function setUp() {
44 $this->useTransaction(TRUE);
46 $this->_entity
= 'im';
47 $this->_contactID
= $this->organizationCreate();
49 'contact_id' => $this->_contactID
,
50 'name' => 'My Yahoo IM Handle',
51 'location_type_id' => 1,
59 * @dataProvider versionThreeAndFour
63 public function testCreateIm($version) {
64 $this->_apiversion
= $version;
65 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->_params
, __FUNCTION__
, __FILE__
);
66 $this->assertEquals(1, $result['count']);
67 $this->getAndCheck($this->_params
, $result['id'], $this->_entity
);
68 $this->assertNotNull($result['values'][$result['id']]['id']);
72 * If no location is specified when creating a new IM, it should default to
73 * the LocationType default
76 * @dataProvider versionThreeAndFour
78 public function testCreateImDefaultLocation($version) {
79 $this->_apiversion
= $version;
80 $params = $this->_params
;
81 unset($params['location_type_id']);
82 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
);
83 $this->assertEquals(CRM_Core_BAO_LocationType
::getDefault()->id
, $result['values'][$result['id']]['location_type_id']);
84 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
90 * @dataProvider versionThreeAndFour
92 public function testGetIm($version) {
93 $this->_apiversion
= $version;
94 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
95 $result = $this->callAPIAndDocument($this->_entity
, 'get', $this->_params
, __FUNCTION__
, __FILE__
);
96 $this->assertEquals(1, $result['count']);
97 $this->assertNotNull($result['values'][$result['id']]['id']);
98 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $result['id']]);
102 * @param int $version
104 * @dataProvider versionThreeAndFour
106 public function testDeleteIm($version) {
107 $this->_apiversion
= $version;
108 $result = $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
109 $deleteParams = ['id' => $result['id']];
110 $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
111 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
112 $this->assertEquals(0, $checkDeleted['count']);
116 * Skip api4 test - delete behaves differently
118 public function testDeleteImInvalid() {
119 $this->callAPISuccess($this->_entity
, 'create', $this->_params
);
120 $deleteParams = ['id' => 600];
121 $this->callAPIFailure($this->_entity
, 'delete', $deleteParams);
122 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
123 $this->assertEquals(1, $checkDeleted['count']);