From 3ed73cde937b5e44df2c1e6eb9ac411a6c480ac1 Mon Sep 17 00:00:00 2001 From: elcapo Date: Tue, 8 Apr 2014 09:48:59 +0200 Subject: [PATCH] Create new API entity: ActivityContact (#CRM-14414) --- api/v3/ActivityContact.php | 91 +++++++++++++++ tests/phpunit/api/v3/ActivityContactTest.php | 112 +++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100644 api/v3/ActivityContact.php create mode 100644 tests/phpunit/api/v3/ActivityContactTest.php diff --git a/api/v3/ActivityContact.php b/api/v3/ActivityContact.php new file mode 100644 index 0000000000..c6ca5ae86c --- /dev/null +++ b/api/v3/ActivityContact.php @@ -0,0 +1,91 @@ +_apiversion = 3; + parent::setUp(); + + $this->_contactID = $this->organizationCreate(); + $activity = $this->activityCreate(); + $this->_activityID = $activity['id']; + CRM_Core_PseudoConstant::flush(); + $this->quickCleanup(array('civicrm_activity_contact')); + $this->_params = array( + 'contact_id' => $this->_contactID, + 'activity_id' => $this->_activityID, + 'record_type_id' => 2, + ); + } + + function tearDown() { + $params['activity_id'] = $this->_activityID; + $this->callAPISuccess('activity', 'delete', $params); + $this->contactDelete($this->_contactID); + } + + public function testCreateActivityContact() { + + $result = $this->callAPIAndDocument('activity_contact', 'create', $this->_params, __FUNCTION__, __FILE__); + $this->assertEquals(1, $result['count']); + $this->assertNotNull($result['values'][$result['id']]['id']); + + $this->callAPISuccess('activity_contact', 'delete', array('id' => $result['id'])); + } + + public function testDeleteActivityContact() { + //create one + $create = $this->callAPISuccess('activity_contact', 'create', $this->_params); + + $result = $this->callAPIAndDocument('activity_contact', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__); + $this->assertEquals(1, $result['count']); + $get = $this->callAPISuccess('activity_contact', 'get', array( + 'id' => $create['id'], + )); + $this->assertEquals(0, $get['count'], 'ActivityContact not successfully deleted'); + } + + public function testGetActivitiesByContact() { + $result = $this->callAPISuccess('ActivityContact', 'Get', array('contact_id' => $this->_contactID)); + } + + public function testGetPartitipantsByActivity() { + $result = $this->callAPISuccess('ActivityContact', 'Get', array('activity_id' => $this->_activityID)); + } + + /** + * Test civicrm_activity_contact_get with empty params. + */ + public function testGetEmptyParams() { + $result = $this->callAPISuccess('ActivityContact', 'Get', array()); + } + + /** + * Test civicrm_activity_contact_get with wrong params. + */ + public function testGetWrongParams() { + $this->callAPIFailure('ActivityContact', 'Get', array('contact_id' => 'abc')); + $this->callAPIFailure('ActivityContact', 'Get', array('activity_id' => 'abc')); + $this->callAPIFailure('ActivityContact', 'Get', array('record_type_id' => 'abc')); + } +} + -- 2.25.1