Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
232624b1 | 5 | | CiviCRM version 4.4 | |
6a488035 TO |
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; | |
7fbb4198 | 35 | protected $_apiversion = 3; |
6a488035 | 36 | protected $_groupId1; |
6a488035 TO |
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() { | |
6a488035 TO |
52 | parent::setUp(); |
53 | ||
e4d5f1e2 | 54 | $this->_contactId = $this->individualCreate(); |
6a488035 TO |
55 | |
56 | $this->_groupId1 = $this->groupCreate(NULL); | |
57 | $params = array( | |
58 | 'contact_id' => $this->_contactId, | |
59 | 'group_id' => $this->_groupId1, | |
6a488035 TO |
60 | ); |
61 | ||
7fbb4198 | 62 | $result = $this->callAPISuccess('group_contact', 'create', $params); |
6a488035 TO |
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', | |
6a488035 TO |
71 | ); |
72 | ||
fadb804f | 73 | $this->_groupId2 = $this->groupCreate(); |
6a488035 TO |
74 | $params = array( |
75 | 'contact_id.1' => $this->_contactId, | |
76 | 'group_id' => $this->_groupId2, | |
6a488035 | 77 | ); |
6a488035 TO |
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, | |
6a488035 | 104 | ); |
7fbb4198 | 105 | $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
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, | |
6a488035 TO |
118 | 'api.group.get' => 1, |
119 | 'sequential' => 1, | |
120 | ); | |
7fbb4198 | 121 | $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
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 | ||
6a488035 TO |
129 | function testCreateWithEmptyParams() { |
130 | $params = array(); | |
d0e1eff2 | 131 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 | 132 | $this->assertEquals($groups['error_message'], |
d0e1eff2 | 133 | 'Mandatory key(s) missing from params array: group_id, contact_id' |
6a488035 TO |
134 | ); |
135 | } | |
136 | ||
137 | function testCreateWithoutGroupIdParams() { | |
138 | $params = array( | |
7fbb4198 | 139 | 'contact_id' => $this->_contactId, ); |
6a488035 | 140 | |
d0e1eff2 | 141 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 TO |
142 | $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); |
143 | } | |
144 | ||
145 | function testCreateWithoutContactIdParams() { | |
146 | $params = array( | |
7fbb4198 | 147 | 'group_id' => $this->_groupId1, ); |
d0e1eff2 | 148 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 TO |
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', | |
7fbb4198 | 160 | 'contact_type' => 'Individual', ); |
6a488035 TO |
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, | |
6a488035 TO |
167 | ); |
168 | ||
7fbb4198 | 169 | $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
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, | |
6a488035 TO |
180 | ); |
181 | ||
7fbb4198 | 182 | $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
183 | $this->assertEquals($result['removed'], 1, "in line " . __LINE__); |
184 | $this->assertEquals($result['total_count'], 1, "in line " . __LINE__); | |
185 | } | |
186 | } | |
187 |