test suite - fix signature on GroupCreate call
[civicrm-core.git] / tests / phpunit / api / v3 / GroupContactTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29
30 require_once 'CiviTest/CiviUnitTestCase.php';
31 class api_v3_GroupContactTest extends CiviUnitTestCase {
32
33 protected $_contactId;
34 protected $_contactId1;
35 protected $_apiversion = 3;
36 protected $_groupId1;
37
38 function get_info() {
39 return array(
40 'name' => 'Group Contact Create',
41 'description' => 'Test all Group Contact Create API methods.',
42 'group' => 'CiviCRM API Tests',
43 );
44 }
45
46 /*
47 * Set up for group contact tests
48 *
49 * @todo set up calls function that doesn't work @ the moment
50 */
51 function setUp() {
52 parent::setUp();
53
54 $this->_contactId = $this->individualCreate();
55
56 $this->_groupId1 = $this->groupCreate(NULL);
57 $params = array(
58 'contact_id' => $this->_contactId,
59 'group_id' => $this->_groupId1,
60 );
61
62 $result = $this->callAPISuccess('group_contact', 'create', $params);
63
64 $group = array(
65 'name' => 'Test Group 2',
66 'domain_id' => 1,
67 'title' => 'New Test Group2 Created',
68 'description' => 'New Test Group2 Created',
69 'is_active' => 1,
70 'visibility' => 'User and User Admin Only',
71 );
72
73 $this->_groupId2 = $this->groupCreate();
74 $params = array(
75 'contact_id.1' => $this->_contactId,
76 'group_id' => $this->_groupId2,
77 );
78
79 $this->_group = array(
80 $this->_groupId1 => array('title' => 'New Test Group Created',
81 'visibility' => 'Public Pages',
82 'in_method' => 'API',
83 ),
84 $this->_groupId2 => array(
85 'title' => 'New Test Group2 Created',
86 'visibility' => 'User and User Admin Only',
87 'in_method' => 'API',
88 ),
89 );
90 }
91
92 function tearDown() {
93 $tablesToTruncate = array(
94 'civicrm_contact',
95 'civicrm_group',
96 );
97 $this->quickCleanup($tablesToTruncate);
98 }
99
100 ///////////////// civicrm_group_contact_get methods
101 function testGet() {
102 $params = array(
103 'contact_id' => $this->_contactId,
104 );
105 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__);
106 foreach ($result['values'] as $v) {
107 $this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']);
108 $this->assertEquals($v['visibility'], $this->_group[$v['group_id']]['visibility']);
109 $this->assertEquals($v['in_method'], $this->_group[$v['group_id']]['in_method']);
110 }
111 }
112
113 function testGetGroupID() {
114 $description = "Get all from group and display contacts";
115 $subfile = "GetWithGroupID";
116 $params = array(
117 'group_id' => $this->_groupId1,
118 'api.group.get' => 1,
119 'sequential' => 1,
120 );
121 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile);
122 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
123 $key = $values['id'];
124 $this->assertEquals($values['title'], $this->_group[$key]['title']);
125 $this->assertEquals($values['visibility'], $this->_group[$key]['visibility']);
126 }
127 }
128
129 function testCreateWithEmptyParams() {
130 $params = array();
131 $groups = $this->callAPIFailure('group_contact', 'create', $params);
132 $this->assertEquals($groups['error_message'],
133 'Mandatory key(s) missing from params array: group_id, contact_id'
134 );
135 }
136
137 function testCreateWithoutGroupIdParams() {
138 $params = array(
139 'contact_id' => $this->_contactId, );
140
141 $groups = $this->callAPIFailure('group_contact', 'create', $params);
142 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
143 }
144
145 function testCreateWithoutContactIdParams() {
146 $params = array(
147 'group_id' => $this->_groupId1, );
148 $groups = $this->callAPIFailure('group_contact', 'create', $params);
149 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
150 }
151
152 function testCreate() {
153 $cont = array(
154 'first_name' => 'Amiteshwar',
155 'middle_name' => 'L.',
156 'last_name' => 'Prasad',
157 'prefix_id' => 3,
158 'suffix_id' => 3,
159 'email' => 'amiteshwar.prasad@civicrm.org',
160 'contact_type' => 'Individual', );
161
162 $this->_contactId1 = $this->individualCreate($cont);
163 $params = array(
164 'contact_id' => $this->_contactId,
165 'contact_id.2' => $this->_contactId1,
166 'group_id' => $this->_groupId1,
167 );
168
169 $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__);
170 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__);
171 $this->assertEquals($result['added'], 1, "in line " . __LINE__);
172 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__);
173 }
174
175 ///////////////// civicrm_group_contact_remove methods
176 function testDelete() {
177 $params = array(
178 'contact_id' => $this->_contactId,
179 'group_id' => 1,
180 );
181
182 $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__);
183 $this->assertEquals($result['removed'], 1, "in line " . __LINE__);
184 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__);
185 }
186 }
187