3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test class for UFGroup API - civicrm_uf_*
30 * @todo Split UFGroup and UFJoin tests
35 class api_v3_UFGroupTest
extends CiviUnitTestCase
{
37 * ids from the uf_group_test.xml fixture
40 protected $_ufGroupId;
41 protected $_ufFieldId;
42 protected $_contactId;
46 protected function setUp() {
48 $this->_groupId
= $this->groupCreate();
49 $this->_contactId
= $this->individualCreate();
50 $this->createLoggedInUser();
51 $ufGroup = $this->callAPISuccess('uf_group', 'create', array(
52 'group_type' => 'Contact',
53 'help_pre' => 'Profile to Test API',
54 'title' => 'Test Profile',
56 $this->_ufGroupId
= $ufGroup['id'];
57 $ufMatch = $this->callAPISuccess('uf_match', 'create', array(
58 'contact_id' => $this->_contactId
,
60 'uf_name' => 'email@mail.com',
62 $this->_ufMatchId
= $ufMatch['id'];
63 $this->params
= array(
65 'add_contact_to_group' => $this->_groupId
,
66 'group' => $this->_groupId
,
67 'cancel_URL' => 'http://example.org/cancel',
68 'created_date' => '2009-06-27 00:00:00',
69 'created_id' => $this->_contactId
,
70 'group_type' => 'Individual,Contact',
71 'help_post' => 'help post',
72 'help_pre' => 'help pre',
79 'is_update_dupe' => 1,
80 'name' => 'Test_Group',
81 'notify' => 'admin@example.org',
82 'post_URL' => 'http://example.org/post',
83 'title' => 'Test Group',
87 public function tearDown() {
88 // Truncate the tables
101 * @param int $version
102 * @dataProvider versionThreeAndFour
104 public function testUpdateUFGroup($version) {
105 $this->_apiversion
= $version;
107 'title' => 'Edited Test Profile',
108 'help_post' => 'Profile Pro help text.',
110 'id' => $this->_ufGroupId
,
113 $result = $this->callAPISuccess('uf_group', 'create', $params);
114 foreach ($params as $key => $value) {
115 $this->assertEquals($result['values'][$result['id']][$key], $value);
120 * @param int $version
121 * @dataProvider versionThreeAndFour
123 public function testUFGroupCreate($version) {
124 $this->_apiversion
= $version;
125 $result = $this->callAPIAndDocument('uf_group', 'create', $this->params
, __FUNCTION__
, __FILE__
);
126 $this->assertAPISuccess($result);
127 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group']);
128 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group']);
129 $this->params
['created_date'] = date('YmdHis', strtotime($this->params
['created_date']));
130 foreach ($this->params
as $key => $value) {
131 if ($key == 'add_contact_to_group' or $key == 'group') {
134 $expected = $this->params
[$key];
135 $received = $result['values'][$result['id']][$key];
136 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
141 * @param int $version
142 * @dataProvider versionThreeAndFour
144 public function testUFGroupCreateWithWrongParams($version) {
145 $this->_apiversion
= $version;
146 $result = $this->callAPIFailure('uf_group', 'create', array('name' => 'A title-less group'));
150 * @param int $version
151 * @dataProvider versionThreeAndFour
153 public function testUFGroupUpdate($version) {
154 $this->_apiversion
= $version;
156 'id' => $this->_ufGroupId
,
158 'add_contact_to_group' => $this->_groupId
,
159 'cancel_URL' => 'http://example.org/cancel',
160 'created_date' => '2009-06-27',
161 'created_id' => $this->_contactId
,
162 'group' => $this->_groupId
,
163 'group_type' => 'Individual,Contact',
164 'help_post' => 'help post',
165 'help_pre' => 'help pre',
172 'is_update_dupe' => 1,
173 'name' => 'test_group',
174 'notify' => 'admin@example.org',
175 'post_URL' => 'http://example.org/post',
176 'title' => 'Test Group',
178 $result = $this->callAPISuccess('uf_group', 'create', $params);
179 $params['created_date'] = date('YmdHis', strtotime($params['created_date']));
180 foreach ($params as $key => $value) {
181 if ($key == 'add_contact_to_group' or $key == 'group') {
184 $this->assertEquals($result['values'][$result['id']][$key], $params[$key], $key . " doesn't match " . $value);
187 $this->assertEquals($result['values'][$this->_ufGroupId
]['add_to_group_id'], $params['add_contact_to_group']);
188 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $params['group']);
192 * @param int $version
193 * @dataProvider versionThreeAndFour
195 public function testUFGroupGet($version) {
196 $this->_apiversion
= $version;
197 $result = $this->callAPISuccess('uf_group', 'create', $this->params
);
198 $params = array('id' => $result['id']);
199 $result = $this->callAPIAndDocument('uf_group', 'get', $params, __FUNCTION__
, __FILE__
);
200 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group']);
201 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group']);
202 foreach ($this->params
as $key => $value) {
203 // skip created date because it doesn't seem to be working properly & fixing date handling is for another day
204 if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'created_date') {
207 $expected = $this->params
[$key];
208 $received = $result['values'][$result['id']][$key];
209 // Api4 auto-splits serialized fields, v3 sometimes does but not in this case
210 if ($version == 4 && is_array($received)) {
211 $received = implode(',', $received);
213 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
218 * @param int $version
219 * @dataProvider versionThreeAndFour
221 public function testUFGroupUpdateWithEmptyParams($version) {
222 $this->_apiversion
= $version;
223 $result = $this->callAPIFailure('uf_group', 'create', [], 'title');
227 * @param int $version
228 * @dataProvider versionThreeAndFour
230 public function testUFGroupDelete($version) {
231 $this->_apiversion
= $version;
232 $ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params
);
233 $params = array('id' => $ufGroup['id']);
234 $this->assertEquals(1, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__
);
235 $result = $this->callAPIAndDocument('uf_group', 'delete', $params, __FUNCTION__
, __FILE__
);
236 $this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__
);