3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Test class for UFGroup API - civicrm_uf_*
32 * @todo Split UFGroup and UFJoin tests
36 class api_v3_UFGroupTest
extends CiviUnitTestCase
{
37 // ids from the uf_group_test.xml fixture
38 protected $_ufGroupId;
39 protected $_ufFieldId;
40 protected $_contactId;
42 protected $_apiversion = 3;
45 protected function setUp() {
47 $this->_groupId
= $this->groupCreate();
48 $this->_contactId
= $this->individualCreate();
49 $this->createLoggedInUser();
50 $ufGroup = $this->callAPISuccess('uf_group', 'create', array(
51 'group_type' => 'Contact',
52 'help_pre' => 'Profile to Test API',
53 'title' => 'Test Profile',
55 $this->_ufGroupId
= $ufGroup['id'];
56 $ufMatch = $this->callAPISuccess('uf_match', 'create', array(
57 'contact_id' => $this->_contactId
,
59 'uf_name' => 'email@mail.com',
61 $this->_ufMatchId
= $ufMatch['id'];
62 $this->params
= array(
64 'add_contact_to_group' => $this->_groupId
,
65 'group' => $this->_groupId
,
66 'cancel_URL' => 'http://example.org/cancel',
67 'created_date' => '2009-06-27 00:00:00',
68 'created_id' => $this->_contactId
,
69 'group_type' => 'Individual,Contact',
70 'help_post' => 'help post',
71 'help_pre' => 'help pre',
78 'is_update_dupe' => 1,
79 'name' => 'Test_Group',
80 'notify' => 'admin@example.org',
81 'post_URL' => 'http://example.org/post',
82 'title' => 'Test Group',
86 public function tearDown() {
87 // Truncate the tables
102 public function testUpdateUFGroup() {
104 'title' => 'Edited Test Profile',
105 'help_post' => 'Profile Pro help text.',
107 'id' => $this->_ufGroupId
,
110 $result = $this->callAPISuccess('uf_group', 'create', $params);
111 foreach ($params as $key => $value) {
112 $this->assertEquals($result['values'][$result['id']][$key], $value);
116 public function testUFGroupCreate() {
118 $result = $this->callAPIAndDocument('uf_group', 'create', $this->params
, __FUNCTION__
, __FILE__
);
119 $this->assertAPISuccess($result);
120 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group']);
121 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group']);
122 $this->params
['created_date'] = date('YmdHis', strtotime($this->params
['created_date']));
123 foreach ($this->params
as $key => $value) {
124 if ($key == 'add_contact_to_group' or $key == 'group') {
127 $expected = $this->params
[$key];
128 $received = $result['values'][$result['id']][$key];
129 // group names are renamed to name_id by BAO
130 if ($key == 'name') {
131 $expected = $this->params
[$key] . '_' . $result['id'];
133 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
137 public function testUFGroupCreateWithWrongParams() {
138 $result = $this->callAPIFailure('uf_group', 'create', array('name' => 'A title-less group'));
141 public function testUFGroupUpdate() {
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 $this->assertEquals($result['values'][$result['id']][$key], $params[$key], $key . " doesn't match " . $value);
174 $this->assertEquals($result['values'][$this->_ufGroupId
]['add_to_group_id'], $params['add_contact_to_group']);
175 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $params['group']);
178 public function testUFGroupGet() {
179 $result = $this->callAPISuccess('uf_group', 'create', $this->params
);
180 $params = array('id' => $result['id']);
181 $result = $this->callAPIAndDocument('uf_group', 'get', $params, __FUNCTION__
, __FILE__
);
182 $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params
['add_contact_to_group']);
183 $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params
['group']);
184 foreach ($this->params
as $key => $value) {
185 // skip created date because it doesn't seem to be working properly & fixing date handling is for another day
186 if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'created_date') {
189 $expected = $this->params
[$key];
190 $received = $result['values'][$result['id']][$key];
191 // group names are renamed to name_id by BAO
192 if ($key == 'name') {
193 $expected = $this->params
[$key] . '_' . $result['id'];
195 $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__
);
199 public function testUFGroupUpdateWithEmptyParams() {
200 $result = $this->callAPIFailure('uf_group', 'create', array(), $this->_ufGroupId
);
203 public function testUFGroupDelete() {
204 $ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params
);
205 $params = array('id' => $ufGroup['id']);
206 $this->assertEquals(1, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__
);
207 $result = $this->callAPIAndDocument('uf_group', 'delete', $params, __FUNCTION__
, __FILE__
);
208 $this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__
);