3ed73cde |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
39de6fd5 |
4 | | CiviCRM version 4.6 | |
3ed73cde |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | |
9 | | | |
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. | |
13 | | | |
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. | |
18 | | | |
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 | +--------------------------------------------------------------------+ |
26 | */ |
27 | |
28 | |
29 | require_once 'CiviTest/CiviUnitTestCase.php'; |
30 | |
31 | |
32 | /** |
33 | * Test APIv3 civicrm_activity_contact* functions |
34 | * |
35 | * @package CiviCRM_APIv3 |
36 | * @subpackage API_Activity |
37 | */ |
38 | class api_v3_ActivityContactTest extends CiviUnitTestCase { |
39 | protected $_apiversion; |
40 | protected $_contactID; |
41 | protected $_activityID; |
42 | protected $_params; |
43 | |
44 | |
45 | function setUp() { |
46 | $this->_apiversion = 3; |
47 | parent::setUp(); |
323df81e |
48 | $this->useTransaction(TRUE); |
3ed73cde |
49 | |
50 | $this->_contactID = $this->organizationCreate(); |
51 | $activity = $this->activityCreate(); |
52 | $this->_activityID = $activity['id']; |
53 | CRM_Core_PseudoConstant::flush(); |
3ed73cde |
54 | $this->_params = array( |
55 | 'contact_id' => $this->_contactID, |
56 | 'activity_id' => $this->_activityID, |
57 | 'record_type_id' => 2, |
58 | ); |
59 | } |
60 | |
3ed73cde |
61 | public function testCreateActivityContact() { |
62 | |
63 | $result = $this->callAPIAndDocument('activity_contact', 'create', $this->_params, __FUNCTION__, __FILE__); |
64 | $this->assertEquals(1, $result['count']); |
65 | $this->assertNotNull($result['values'][$result['id']]['id']); |
66 | |
67 | $this->callAPISuccess('activity_contact', 'delete', array('id' => $result['id'])); |
68 | } |
69 | |
70 | public function testDeleteActivityContact() { |
71 | //create one |
72 | $create = $this->callAPISuccess('activity_contact', 'create', $this->_params); |
73 | |
74 | $result = $this->callAPIAndDocument('activity_contact', 'delete', array('id' => $create['id'],), __FUNCTION__, __FILE__); |
75 | $this->assertEquals(1, $result['count']); |
76 | $get = $this->callAPISuccess('activity_contact', 'get', array( |
77 | 'id' => $create['id'], |
78 | )); |
79 | $this->assertEquals(0, $get['count'], 'ActivityContact not successfully deleted'); |
80 | } |
81 | |
82 | public function testGetActivitiesByContact() { |
83 | $result = $this->callAPISuccess('ActivityContact', 'Get', array('contact_id' => $this->_contactID)); |
84 | } |
85 | |
86 | public function testGetPartitipantsByActivity() { |
87 | $result = $this->callAPISuccess('ActivityContact', 'Get', array('activity_id' => $this->_activityID)); |
88 | } |
89 | |
90 | /** |
91 | * Test civicrm_activity_contact_get with empty params. |
92 | */ |
93 | public function testGetEmptyParams() { |
94 | $result = $this->callAPISuccess('ActivityContact', 'Get', array()); |
95 | } |
96 | |
97 | /** |
98 | * Test civicrm_activity_contact_get with wrong params. |
99 | */ |
100 | public function testGetWrongParams() { |
101 | $this->callAPIFailure('ActivityContact', 'Get', array('contact_id' => 'abc')); |
102 | $this->callAPIFailure('ActivityContact', 'Get', array('activity_id' => 'abc')); |
103 | $this->callAPIFailure('ActivityContact', 'Get', array('record_type_id' => 'abc')); |
104 | } |
105 | } |
106 | |