Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | require_once 'CiviTest/CiviUnitTestCase.php'; |
29 | ||
30 | /** | |
31 | * Test class for UFGroup API - civicrm_uf_* | |
32 | * @todo Split UFGroup and UFJoin tests | |
33 | * | |
6c6e6187 | 34 | * @package CiviCRM |
6a488035 TO |
35 | */ |
36 | class api_v3_UFGroupTest extends CiviUnitTestCase { | |
37 | // ids from the uf_group_test.xml fixture | |
7fbb4198 | 38 | protected $_ufGroupId; |
6a488035 | 39 | protected $_ufFieldId; |
7fbb4198 | 40 | protected $_contactId; |
41 | protected $_groupId; | |
6c6e6187 | 42 | protected $_apiversion = 3; |
6a488035 TO |
43 | protected $params; |
44 | ||
45 | protected function setUp() { | |
46 | parent::setUp(); | |
7fbb4198 | 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', | |
92915c55 | 52 | 'help_pre' => 'Profile to Test API', |
6c6e6187 | 53 | 'title' => 'Test Profile', |
7fbb4198 | 54 | )); |
55 | $this->_ufGroupId = $ufGroup['id']; | |
56 | $ufMatch = $this->callAPISuccess('uf_match', 'create', array( | |
57 | 'contact_id' => $this->_contactId, | |
58 | 'uf_id' => 42, | |
59 | 'uf_name' => 'email@mail.com', | |
60 | )); | |
08fe8c7e | 61 | $this->_ufMatchId = $ufMatch['id']; |
6a488035 TO |
62 | $this->params = array( |
63 | 'add_captcha' => 1, | |
7fbb4198 | 64 | 'add_contact_to_group' => $this->_groupId, |
65 | 'group' => $this->_groupId, | |
6a488035 TO |
66 | 'cancel_URL' => 'http://example.org/cancel', |
67 | 'created_date' => '2009-06-27 00:00:00', | |
7fbb4198 | 68 | 'created_id' => $this->_contactId, |
6a488035 TO |
69 | 'group_type' => 'Individual,Contact', |
70 | 'help_post' => 'help post', | |
71 | 'help_pre' => 'help pre', | |
72 | 'is_active' => 0, | |
73 | 'is_cms_user' => 1, | |
74 | 'is_edit_link' => 1, | |
75 | 'is_map' => 1, | |
76 | 'is_reserved' => 1, | |
77 | 'is_uf_link' => 1, | |
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', | |
6a488035 TO |
83 | ); |
84 | } | |
85 | ||
00be9182 | 86 | public function tearDown() { |
6a488035 TO |
87 | // Truncate the tables |
88 | $this->quickCleanup( | |
89 | array( | |
90 | 'civicrm_group', | |
91 | 'civicrm_contact', | |
92 | 'civicrm_uf_group', | |
93 | 'civicrm_uf_join', | |
94 | 'civicrm_uf_match', | |
95 | ) | |
96 | ); | |
97 | } | |
98 | ||
99 | /** | |
100fef9d | 100 | * Updating group |
6a488035 TO |
101 | */ |
102 | public function testUpdateUFGroup() { | |
103 | $params = array( | |
104 | 'title' => 'Edited Test Profile', | |
105 | 'help_post' => 'Profile Pro help text.', | |
106 | 'is_active' => 1, | |
21dfd5f5 | 107 | 'id' => $this->_ufGroupId, |
92915c55 | 108 | ); |
6a488035 | 109 | |
7fbb4198 | 110 | $result = $this->callAPISuccess('uf_group', 'create', $params); |
6a488035 TO |
111 | foreach ($params as $key => $value) { |
112 | $this->assertEquals($result['values'][$result['id']][$key], $value); | |
113 | } | |
114 | } | |
115 | ||
00be9182 | 116 | public function testUFGroupCreate() { |
6a488035 | 117 | |
7fbb4198 | 118 | $result = $this->callAPIAndDocument('uf_group', 'create', $this->params, __FUNCTION__, __FILE__); |
6a73ef3f | 119 | $this->assertAPISuccess($result); |
6a488035 TO |
120 | $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group'], 'in line ' . __LINE__); |
121 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group'], 'in line ' . __LINE__); | |
122 | $this->params['created_date'] = date('YmdHis', strtotime($this->params['created_date'])); | |
123 | foreach ($this->params as $key => $value) { | |
7fbb4198 | 124 | if ($key == 'add_contact_to_group' or $key == 'group') { |
6a488035 TO |
125 | continue; |
126 | } | |
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']; | |
132 | } | |
133 | $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__); | |
134 | } | |
135 | } | |
136 | ||
00be9182 | 137 | public function testUFGroupCreateWithWrongParams() { |
7fbb4198 | 138 | $result = $this->callAPIFailure('uf_group', 'create', array('name' => 'A title-less group')); |
6a488035 TO |
139 | } |
140 | ||
00be9182 | 141 | public function testUFGroupUpdate() { |
6a488035 TO |
142 | $params = array( |
143 | 'id' => $this->_ufGroupId, | |
144 | 'add_captcha' => 1, | |
7fbb4198 | 145 | 'add_contact_to_group' => $this->_groupId, |
6a488035 TO |
146 | 'cancel_URL' => 'http://example.org/cancel', |
147 | 'created_date' => '2009-06-27', | |
7fbb4198 | 148 | 'created_id' => $this->_contactId, |
149 | 'group' => $this->_groupId, | |
6a488035 TO |
150 | 'group_type' => 'Individual,Contact', |
151 | 'help_post' => 'help post', | |
152 | 'help_pre' => 'help pre', | |
153 | 'is_active' => 0, | |
154 | 'is_cms_user' => 1, | |
155 | 'is_edit_link' => 1, | |
156 | 'is_map' => 1, | |
157 | 'is_reserved' => 1, | |
158 | 'is_uf_link' => 1, | |
159 | 'is_update_dupe' => 1, | |
160 | 'name' => 'test_group', | |
161 | 'notify' => 'admin@example.org', | |
162 | 'post_URL' => 'http://example.org/post', | |
92915c55 TO |
163 | 'title' => 'Test Group', |
164 | ); | |
7fbb4198 | 165 | $result = $this->callAPISuccess('uf_group', 'create', $params); |
6a488035 TO |
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') { | |
169 | continue; | |
170 | } | |
171 | $this->assertEquals($result['values'][$result['id']][$key], $params[$key], $key . " doesn't match " . $value); | |
172 | } | |
173 | ||
174 | $this->assertEquals($result['values'][$this->_ufGroupId]['add_to_group_id'], $params['add_contact_to_group'], 'in line ' . __LINE__); | |
175 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $params['group'], 'in line ' . __LINE__); | |
176 | } | |
177 | ||
00be9182 | 178 | public function testUFGroupGet() { |
7fbb4198 | 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__); | |
6a488035 TO |
182 | $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group'], 'in line ' . __LINE__); |
183 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group'], 'in line ' . __LINE__); | |
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 | |
7fbb4198 | 186 | if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'created_date') { |
6a488035 TO |
187 | continue; |
188 | } | |
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']; | |
194 | } | |
195 | $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__); | |
196 | } | |
197 | } | |
198 | ||
00be9182 | 199 | public function testUFGroupUpdateWithEmptyParams() { |
7fbb4198 | 200 | $result = $this->callAPIFailure('uf_group', 'create', array(), $this->_ufGroupId); |
6a488035 TO |
201 | } |
202 | ||
00be9182 | 203 | public function testUFGroupDelete() { |
7fbb4198 | 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__); | |
6a488035 | 209 | } |
96025800 | 210 | |
6a488035 | 211 | } |