Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
7d61e75f TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 | 11 | |
6a488035 TO |
12 | /** |
13 | * Test APIv3 civicrm_im_* functions | |
14 | * | |
6c6e6187 TO |
15 | * @package CiviCRM_APIv3 |
16 | * @subpackage API_Contact | |
acb109b7 | 17 | * @group headless |
6a488035 | 18 | */ |
6a488035 | 19 | class api_v3_ImTest extends CiviUnitTestCase { |
f19fee10 | 20 | protected $_params; |
6a488035 TO |
21 | protected $id; |
22 | protected $_entity; | |
b7c9bc4c | 23 | |
430ae6dd TO |
24 | public $DBResetRequired = FALSE; |
25 | ||
00be9182 | 26 | public function setUp() { |
6a488035 | 27 | parent::setUp(); |
c008f892 | 28 | $this->useTransaction(TRUE); |
6a488035 | 29 | |
92915c55 TO |
30 | $this->_entity = 'im'; |
31 | $this->_contactID = $this->organizationCreate(); | |
f19fee10 | 32 | $this->_params = [ |
6a488035 TO |
33 | 'contact_id' => $this->_contactID, |
34 | 'name' => 'My Yahoo IM Handle', | |
35 | 'location_type_id' => 1, | |
36 | 'provider_id' => 1, | |
f78dbf0b | 37 | ]; |
6a488035 TO |
38 | } |
39 | ||
2d932085 CW |
40 | /** |
41 | * @param int $version | |
f78dbf0b | 42 | * |
2d932085 | 43 | * @dataProvider versionThreeAndFour |
f78dbf0b | 44 | * |
45 | * @throws \Exception | |
2d932085 CW |
46 | */ |
47 | public function testCreateIm($version) { | |
48 | $this->_apiversion = $version; | |
f19fee10 | 49 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
ba4a1892 | 50 | $this->assertEquals(1, $result['count']); |
f19fee10 | 51 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); |
ba4a1892 | 52 | $this->assertNotNull($result['values'][$result['id']]['id']); |
6a488035 TO |
53 | } |
54 | ||
0e70279a AS |
55 | /** |
56 | * If no location is specified when creating a new IM, it should default to | |
57 | * the LocationType default | |
58 | * | |
59 | * @param int $version | |
60 | * @dataProvider versionThreeAndFour | |
61 | */ | |
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']]); | |
69 | } | |
70 | ||
2d932085 CW |
71 | /** |
72 | * @param int $version | |
f78dbf0b | 73 | * |
2d932085 CW |
74 | * @dataProvider versionThreeAndFour |
75 | */ | |
76 | public function testGetIm($version) { | |
77 | $this->_apiversion = $version; | |
f19fee10 AS |
78 | $this->callAPISuccess($this->_entity, 'create', $this->_params); |
79 | $result = $this->callAPIAndDocument($this->_entity, 'get', $this->_params, __FUNCTION__, __FILE__); | |
ba4a1892 TM |
80 | $this->assertEquals(1, $result['count']); |
81 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
f78dbf0b | 82 | $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); |
6a488035 TO |
83 | } |
84 | ||
2d932085 CW |
85 | /** |
86 | * @param int $version | |
f78dbf0b | 87 | * |
2d932085 CW |
88 | * @dataProvider versionThreeAndFour |
89 | */ | |
90 | public function testDeleteIm($version) { | |
91 | $this->_apiversion = $version; | |
f19fee10 | 92 | $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
f78dbf0b | 93 | $deleteParams = ['id' => $result['id']]; |
94 | $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); | |
95 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); | |
ba4a1892 | 96 | $this->assertEquals(0, $checkDeleted['count']); |
6a488035 | 97 | } |
92915c55 | 98 | |
2d932085 CW |
99 | /** |
100 | * Skip api4 test - delete behaves differently | |
101 | */ | |
6a488035 | 102 | public function testDeleteImInvalid() { |
f19fee10 | 103 | $this->callAPISuccess($this->_entity, 'create', $this->_params); |
f78dbf0b | 104 | $deleteParams = ['id' => 600]; |
105 | $this->callAPIFailure($this->_entity, 'delete', $deleteParams); | |
106 | $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); | |
ba4a1892 | 107 | $this->assertEquals(1, $checkDeleted['count']); |
6a488035 | 108 | } |
96025800 | 109 | |
6a488035 | 110 | } |