3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
13 * Test class for UFGroup API - civicrm_uf_*
14 * @todo Split UFGroup and UFJoin tests
19 class api_v3_UFGroupTest
extends CiviUnitTestCase
{
21 * ids from the uf_group_test.xml fixture
24 protected $_ufGroupId;
25 protected $_ufFieldId;
26 protected $_contactId;
30 protected function setUp() {
32 $this->_groupId
= $this->groupCreate();
33 $this->_contactId
= $this->individualCreate();
34 $this->createLoggedInUser();
35 $ufGroup = $this->callAPISuccess('uf_group', 'create', [
36 'group_type' => 'Contact',
37 'help_pre' => 'Profile to Test API',
38 'title' => 'Test Profile',
40 $this->_ufGroupId
= $ufGroup['id'];
41 $ufMatch = $this->callAPISuccess('uf_match', 'create', [
42 'contact_id' => $this->_contactId
,
44 'uf_name' => 'email@mail.com',
46 $this->_ufMatchId
= $ufMatch['id'];
49 'add_contact_to_group' => $this->_groupId
,
50 'group' => $this->_groupId
,
51 'cancel_URL' => 'http://example.org/cancel',
52 'created_date' => '2009-06-27 00:00:00',
53 'created_id' => $this->_contactId
,
54 'group_type' => 'Individual,Contact',
55 'help_post' => 'help post',
56 'help_pre' => 'help pre',
63 'is_update_dupe' => 1,
64 'name' => 'Test_Group',
65 'notify' => 'admin@example.org',
66 'post_URL' => 'http://example.org/post',
67 'title' => 'Test Group',
71 public function tearDown() {
72 // Truncate the tables
86 * @dataProvider versionThreeAndFour
88 public function testUpdateUFGroup($version) {
89 $this->_apiversion
= $version;
91 'title' => 'Edited Test Profile',
92 'help_post' => 'Profile Pro help text.',
94 'id' => $this->_ufGroupId
,
97 $result = $this->callAPISuccess('uf_group', 'create', $params);
98 foreach ($params as $key => $value) {
99 $this->assertEquals($result['values'][$result['id']][$key], $value);
104 * @param int $version
105 * @dataProvider versionThreeAndFour
107 public function testUFGroupCreate($version) {
108 $this->_apiversion
= $version;
109 $result = $this->callAPIAndDocument('uf_group', 'create', $this->params
, __FUNCTION__
, __FILE__
);
110 $this->assertAPISuccess($result);
111 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group']);
112 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group']);
113 $this->params
['created_date'] = date('YmdHis', strtotime($this->params
['created_date']));
114 foreach ($this->params
as $key => $value) {
115 if ($key == 'add_contact_to_group' or $key == 'group') {
118 $received = $result['values'][$result['id']][$key];
119 if ($key == 'group_type' && $version == 4) {
120 $received = implode(',', $received);
122 $expected = $this->params
[$key];
123 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
128 * @param int $version
129 * @dataProvider versionThreeAndFour
131 public function testUFGroupCreateWithWrongParams($version) {
132 $this->_apiversion
= $version;
133 $result = $this->callAPIFailure('uf_group', 'create', ['name' => 'A title-less group']);
137 * @param int $version
138 * @dataProvider versionThreeAndFour
140 public function testUFGroupUpdate($version) {
141 $this->_apiversion
= $version;
143 'id' => $this->_ufGroupId
,
145 'add_contact_to_group' => $this->_groupId
,
146 'cancel_URL' => 'http://example.org/cancel',
147 'created_date' => '2009-06-27',
148 'created_id' => $this->_contactId
,
149 'group' => $this->_groupId
,
150 'group_type' => 'Individual,Contact',
151 'help_post' => 'help post',
152 'help_pre' => 'help pre',
159 'is_update_dupe' => 1,
160 'name' => 'test_group',
161 'notify' => 'admin@example.org',
162 'post_URL' => 'http://example.org/post',
163 'title' => 'Test Group',
165 $result = $this->callAPISuccess('uf_group', 'create', $params);
166 $params['created_date'] = date('YmdHis', strtotime($params['created_date']));
167 foreach ($params as $key => $value) {
168 if ($key == 'add_contact_to_group' or $key == 'group') {
171 $received = $result['values'][$result['id']][$key];
172 if ($key == 'group_type' && $version == 4) {
173 $received = implode(',', $received);
175 $this->assertEquals($received, $params[$key], $key . " doesn't match " . $value);
178 $this->assertEquals($result['values'][$this->_ufGroupId
]['add_to_group_id'], $params['add_contact_to_group']);
179 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $params['group']);
183 * @param int $version
184 * @dataProvider versionThreeAndFour
186 public function testUFGroupGet($version) {
187 $this->_apiversion
= $version;
188 $result = $this->callAPISuccess('uf_group', 'create', $this->params
);
189 $params = ['id' => $result['id']];
190 $result = $this->callAPIAndDocument('uf_group', 'get', $params, __FUNCTION__
, __FILE__
);
191 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group']);
192 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group']);
193 foreach ($this->params
as $key => $value) {
194 // skip created date because it doesn't seem to be working properly & fixing date handling is for another day
195 if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'created_date') {
198 $expected = $this->params
[$key];
199 $received = $result['values'][$result['id']][$key];
200 // Api4 auto-splits serialized fields, v3 sometimes does but not in this case
201 if ($version == 4 && is_array($received)) {
202 $received = implode(',', $received);
204 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
209 * @param int $version
210 * @dataProvider versionThreeAndFour
212 public function testUFGroupUpdateWithEmptyParams($version) {
213 $this->_apiversion
= $version;
214 $result = $this->callAPIFailure('uf_group', 'create', [], 'title');
218 * @param int $version
219 * @dataProvider versionThreeAndFour
221 public function testUFGroupDelete($version) {
222 $this->_apiversion
= $version;
223 $ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params
);
224 $params = ['id' => $ufGroup['id']];
225 $this->assertEquals(1, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__
);
226 $result = $this->callAPIAndDocument('uf_group', 'delete', $params, __FUNCTION__
, __FILE__
);
227 $this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__
);