Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
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 | * | |
34 | * @package CiviCRM | |
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; | |
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', | |
52 | 'help_pre' => 'Profile to Test API', | |
53 | 'title' =>'Test Profile', | |
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 | )); | |
61 | $this->_ufGroupId = $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 | ||
86 | 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 | /** | |
100 | * updating group | |
101 | */ | |
102 | public function testUpdateUFGroup() { | |
103 | $params = array( | |
104 | 'title' => 'Edited Test Profile', | |
105 | 'help_post' => 'Profile Pro help text.', | |
106 | 'is_active' => 1, | |
7fbb4198 | 107 | 'id' => $this->_ufGroupId |
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 | ||
116 | function testUFGroupCreate() { | |
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 | ||
137 | function testUFGroupCreateWithWrongParams() { | |
7fbb4198 | 138 | $result = $this->callAPIFailure('uf_group', 'create', array('name' => 'A title-less group')); |
6a488035 TO |
139 | } |
140 | ||
141 | function testUFGroupUpdate() { | |
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', | |
7fbb4198 | 163 | 'title' => 'Test Group', ); |
164 | $result = $this->callAPISuccess('uf_group', 'create', $params); | |
6a488035 TO |
165 | $params['created_date'] = date('YmdHis', strtotime($params['created_date'])); |
166 | foreach ($params as $key => $value) { | |
167 | if ($key == 'add_contact_to_group' or $key == 'group') { | |
168 | continue; | |
169 | } | |
170 | $this->assertEquals($result['values'][$result['id']][$key], $params[$key], $key . " doesn't match " . $value); | |
171 | } | |
172 | ||
173 | $this->assertEquals($result['values'][$this->_ufGroupId]['add_to_group_id'], $params['add_contact_to_group'], 'in line ' . __LINE__); | |
174 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $params['group'], 'in line ' . __LINE__); | |
175 | } | |
176 | ||
177 | function testUFGroupGet() { | |
7fbb4198 | 178 | $result = $this->callAPISuccess('uf_group', 'create', $this->params); |
179 | $params = array('id' => $result['id']); | |
180 | $result = $this->callAPIAndDocument('uf_group', 'get', $params, __FUNCTION__, __FILE__); | |
6a488035 TO |
181 | $this->assertEquals($result['values'][$result['id']]['add_to_group_id'], $this->params['add_contact_to_group'], 'in line ' . __LINE__); |
182 | $this->assertEquals($result['values'][$result['id']]['limit_listings_group_id'], $this->params['group'], 'in line ' . __LINE__); | |
183 | foreach ($this->params as $key => $value) { | |
184 | // skip created date because it doesn't seem to be working properly & fixing date handling is for another day | |
7fbb4198 | 185 | if ($key == 'add_contact_to_group' or $key == 'group' or $key == 'created_date') { |
6a488035 TO |
186 | continue; |
187 | } | |
188 | $expected = $this->params[$key]; | |
189 | $received = $result['values'][$result['id']][$key]; | |
190 | // group names are renamed to name_id by BAO | |
191 | if ($key == 'name') { | |
192 | $expected = $this->params[$key] . '_' . $result['id']; | |
193 | } | |
194 | $this->assertEquals($expected, $received, "The string '$received' does not equal '$expected' for key '$key' in line " . __LINE__); | |
195 | } | |
196 | } | |
197 | ||
198 | function testUFGroupUpdateWithEmptyParams() { | |
7fbb4198 | 199 | $result = $this->callAPIFailure('uf_group', 'create', array(), $this->_ufGroupId); |
6a488035 TO |
200 | } |
201 | ||
202 | function testUFGroupDelete() { | |
7fbb4198 | 203 | $ufGroup = $this->callAPISuccess('uf_group', 'create', $this->params); |
204 | $params = array('id' => $ufGroup['id']); | |
205 | $this->assertEquals(1, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__); | |
206 | $result = $this->callAPIAndDocument('uf_group', 'delete', $params, __FUNCTION__, __FILE__); | |
207 | $this->assertEquals(0, $this->callAPISuccess('uf_group', 'getcount', $params), "in line " . __LINE__); | |
6a488035 TO |
208 | } |
209 | } |