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