Merge pull request #17294 from agh1/sr-rel-perms
[civicrm-core.git] / tests / phpunit / api / v3 / ActivityContactTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12
13 /**
14 * Test APIv3 civicrm_activity_contact* functions
15 *
16 * @package CiviCRM_APIv3
17 * @subpackage API_Activity
18 * @group headless
19 */
20 class api_v3_ActivityContactTest extends CiviUnitTestCase {
21 protected $_apiversion;
22 protected $_contactID;
23 protected $_activityID;
24 protected $_params;
25
26 public function setUp() {
27 parent::setUp();
28 $this->useTransaction(TRUE);
29
30 $this->_contactID = $this->organizationCreate();
31 $activity = $this->activityCreate();
32 $this->_activityID = $activity['id'];
33 CRM_Core_PseudoConstant::flush();
34 $this->_params = [
35 'contact_id' => $this->_contactID,
36 'activity_id' => $this->_activityID,
37 'record_type_id' => 2,
38 ];
39 }
40
41 /**
42 * @param int $version
43 * @dataProvider versionThreeAndFour
44 */
45 public function testCreateActivityContact($version) {
46 $this->_apiversion = $version;
47
48 $result = $this->callAPIAndDocument('activity_contact', 'create', $this->_params, __FUNCTION__, __FILE__);
49 $this->assertEquals(1, $result['count']);
50 $this->assertNotNull($result['values'][$result['id']]['id']);
51
52 $this->callAPISuccess('activity_contact', 'delete', ['id' => $result['id']]);
53 }
54
55 /**
56 * @param int $version
57 * @dataProvider versionThreeAndFour
58 */
59 public function testDeleteActivityContact($version) {
60 $this->_apiversion = $version;
61 //create one
62 $create = $this->callAPISuccess('activity_contact', 'create', $this->_params);
63
64 $result = $this->callAPIAndDocument('activity_contact', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
65 $this->assertEquals(1, $result['count']);
66 $get = $this->callAPISuccess('activity_contact', 'get', [
67 'id' => $create['id'],
68 ]);
69 $this->assertEquals(0, $get['count'], 'ActivityContact not successfully deleted');
70 }
71
72 /**
73 * @param int $version
74 * @dataProvider versionThreeAndFour
75 */
76 public function testGetActivitiesByContact($version) {
77 $this->_apiversion = $version;
78 $this->callAPISuccess('ActivityContact', 'Get', ['contact_id' => $this->_contactID]);
79 }
80
81 /**
82 * @param int $version
83 * @dataProvider versionThreeAndFour
84 */
85 public function testGetActivitiesByActivity($version) {
86 $this->_apiversion = $version;
87 $this->callAPISuccess('ActivityContact', 'Get', ['activity_id' => $this->_activityID]);
88 }
89
90 /**
91 * Test civicrm_activity_contact_get with empty params.
92 * @param int $version
93 * @dataProvider versionThreeAndFour
94 */
95 public function testGetEmptyParams($version) {
96 $this->_apiversion = $version;
97 $this->callAPISuccess('ActivityContact', 'Get', []);
98 }
99
100 /**
101 * Test civicrm_activity_contact_get with wrong params.
102 * FIXME: Api4
103 */
104 public function testGetWrongParams() {
105 $this->callAPIFailure('ActivityContact', 'Get', ['contact_id' => 'abc']);
106 $this->callAPIFailure('ActivityContact', 'Get', ['activity_id' => 'abc']);
107 $this->callAPIFailure('ActivityContact', 'Get', ['record_type_id' => 'abc']);
108 }
109
110 }