Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | /** |
29 | * Test class for UFGroup API - civicrm_uf_* | |
30 | * @todo Split UFGroup and UFJoin tests | |
31 | * | |
6c6e6187 | 32 | * @package CiviCRM |
acb109b7 | 33 | * @group headless |
6a488035 TO |
34 | */ |
35 | class api_v3_UFJoinTest extends CiviUnitTestCase { | |
36 | // ids from the uf_group_test.xml fixture | |
37 | protected $_ufGroupId = 11; | |
38 | protected $_ufFieldId; | |
39 | protected $_contactId = 69; | |
40 | protected $_apiversion; | |
b7c9bc4c | 41 | |
6a488035 TO |
42 | protected function setUp() { |
43 | parent::setUp(); | |
44 | // Truncate the tables | |
45 | $this->quickCleanup( | |
46 | array( | |
47 | 'civicrm_group', | |
48 | 'civicrm_contact', | |
49 | 'civicrm_uf_group', | |
50 | 'civicrm_uf_join', | |
51 | 'civicrm_uf_match', | |
52 | ) | |
53 | ); | |
54 | $this->_apiversion = 3; | |
d5cc0fc2 | 55 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); |
6a488035 TO |
56 | $op->execute( |
57 | $this->_dbconn, | |
bbfd46a5 | 58 | $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') |
6a488035 | 59 | ); |
6a488035 TO |
60 | } |
61 | ||
00be9182 | 62 | public function tearDown() { |
6a488035 TO |
63 | // Truncate the tables |
64 | $this->quickCleanup( | |
65 | array( | |
66 | 'civicrm_group', | |
67 | 'civicrm_contact', | |
68 | 'civicrm_uf_group', | |
69 | 'civicrm_uf_join', | |
70 | 'civicrm_uf_match', | |
71 | ) | |
72 | ); | |
73 | } | |
74 | ||
75 | /** | |
eceb18cc | 76 | * Find uf join group id. |
6a488035 TO |
77 | */ |
78 | public function testFindUFGroupId() { | |
79 | $params = array( | |
80 | 'module' => 'CiviContribute', | |
81 | 'entity_table' => 'civicrm_contribution_page', | |
82 | 'entity_id' => 1, | |
83 | 'weight' => 1, | |
84 | 'uf_group_id' => $this->_ufGroupId, | |
92915c55 TO |
85 | 'is_active' => 1, |
86 | ); | |
e6ff1593 | 87 | $ufJoin = $this->callAPISuccess('uf_join', 'create', $params); |
6a488035 TO |
88 | |
89 | $searchParams = array( | |
90 | 'entity_table' => 'civicrm_contribution_page', | |
92915c55 TO |
91 | 'entity_id' => 1, |
92 | ); | |
e6ff1593 | 93 | $result = $this->callAPISuccess('uf_join', 'get', $searchParams); |
6a488035 TO |
94 | |
95 | foreach ($result['values'] as $key => $value) { | |
a15773db | 96 | $this->assertEquals($value['uf_group_id'], $this->_ufGroupId); |
6a488035 TO |
97 | } |
98 | } | |
99 | ||
100 | ||
101 | public function testUFJoinEditWrongParamsType() { | |
102 | $params = 'a string'; | |
d0e1eff2 | 103 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
ba4a1892 | 104 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
6a488035 TO |
105 | } |
106 | ||
107 | public function testUFJoinEditEmptyParams() { | |
108 | $params = array(); | |
d0e1eff2 | 109 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
ba4a1892 | 110 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id'); |
6a488035 TO |
111 | } |
112 | ||
113 | public function testUFJoinEditWithoutUFGroupId() { | |
114 | $params = array( | |
115 | 'module' => 'CiviContribute', | |
116 | 'entity_table' => 'civicrm_contribution_page', | |
117 | 'entity_id' => 1, | |
118 | 'weight' => 1, | |
92915c55 TO |
119 | 'is_active' => 1, |
120 | ); | |
d0e1eff2 | 121 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
ba4a1892 | 122 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id'); |
6a488035 TO |
123 | } |
124 | ||
125 | /** | |
100fef9d | 126 | * Create/update uf join |
6a488035 TO |
127 | */ |
128 | public function testCreateUFJoin() { | |
129 | $params = array( | |
130 | 'module' => 'CiviContribute', | |
131 | 'entity_table' => 'civicrm_contribution_page', | |
132 | 'entity_id' => 1, | |
133 | 'weight' => 1, | |
134 | 'uf_group_id' => $this->_ufGroupId, | |
6c6e6187 | 135 | 'is_active' => 1, |
92915c55 | 136 | 'sequential' => 1, |
6a488035 | 137 | ); |
e6ff1593 | 138 | $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__); |
ba4a1892 TM |
139 | $this->assertEquals($ufJoin['values'][0]['module'], $params['module']); |
140 | $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']); | |
141 | $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']); | |
6a488035 TO |
142 | |
143 | $params = array( | |
144 | 'id' => $ufJoin['id'], | |
145 | 'module' => 'CiviContribute', | |
146 | 'entity_table' => 'civicrm_contribution_page', | |
147 | 'entity_id' => 1, | |
148 | 'weight' => 1, | |
149 | 'uf_group_id' => $this->_ufGroupId, | |
6c6e6187 | 150 | 'is_active' => 0, |
92915c55 | 151 | 'sequential' => 1, |
6a488035 | 152 | ); |
e6ff1593 | 153 | $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params); |
ba4a1892 TM |
154 | $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']); |
155 | $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']); | |
156 | $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active']); | |
6a488035 TO |
157 | } |
158 | ||
9ca7d5da JM |
159 | /** |
160 | * Ensure we can create a survey join which is less common than event or contribution | |
161 | * joins. | |
162 | */ | |
163 | public function testCreateSurveyUFJoin() { | |
164 | $params = array( | |
165 | 'module' => 'CiviCampaign', | |
166 | 'entity_table' => 'civicrm_survey', | |
167 | 'entity_id' => 1, | |
168 | 'weight' => 1, | |
169 | 'uf_group_id' => $this->_ufGroupId, | |
170 | 'is_active' => 1, | |
171 | 'sequential' => 1, | |
172 | ); | |
173 | $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__); | |
174 | $this->assertEquals($ufJoin['values'][0]['module'], $params['module']); | |
175 | $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']); | |
176 | $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']); | |
177 | } | |
6a488035 TO |
178 | |
179 | public function testFindUFJoinWrongParamsType() { | |
180 | $params = 'a string'; | |
d0e1eff2 | 181 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
ba4a1892 | 182 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array'); |
6a488035 TO |
183 | } |
184 | ||
185 | public function testFindUFJoinEmptyParams() { | |
d0e1eff2 | 186 | $result = $this->callAPIFailure('uf_join', 'create', array()); |
ba4a1892 | 187 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id'); |
6a488035 TO |
188 | } |
189 | ||
190 | public function testFindUFJoinWithoutUFGroupId() { | |
191 | $params = array( | |
192 | 'module' => 'CiviContribute', | |
193 | 'entity_table' => 'civicrm_contribution_page', | |
194 | 'entity_id' => 1, | |
195 | 'weight' => 1, | |
196 | 'is_active' => 1, | |
6a488035 | 197 | ); |
d0e1eff2 | 198 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
ba4a1892 | 199 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id'); |
6a488035 TO |
200 | } |
201 | ||
202 | /** | |
eceb18cc | 203 | * Find uf join id. |
6a488035 TO |
204 | */ |
205 | public function testGetUFJoinId() { | |
206 | $params = array( | |
207 | 'module' => 'CiviContribute', | |
208 | 'entity_table' => 'civicrm_contribution_page', | |
209 | 'entity_id' => 1, | |
210 | 'weight' => 1, | |
211 | 'uf_group_id' => $this->_ufGroupId, | |
92915c55 TO |
212 | 'is_active' => 1, |
213 | ); | |
6a488035 | 214 | |
e6ff1593 | 215 | $ufJoin = $this->callAPISuccess('uf_join', 'create', $params); |
6a488035 TO |
216 | $searchParams = array( |
217 | 'entity_table' => 'civicrm_contribution_page', | |
6c6e6187 | 218 | 'entity_id' => 1, |
92915c55 | 219 | 'sequential' => 1, |
6a488035 TO |
220 | ); |
221 | ||
e6ff1593 | 222 | $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__, __FILE__); |
ba4a1892 TM |
223 | $this->assertEquals($result['values'][0]['module'], $params['module']); |
224 | $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id']); | |
225 | $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id']); | |
6a488035 TO |
226 | } |
227 | ||
228 | /** | |
d177a2a6 | 229 | * Test civicrm_activity_create() using example code. |
6a488035 | 230 | */ |
00be9182 | 231 | public function testUFJoinCreateExample() { |
3ec6e38d | 232 | require_once 'api/v3/examples/UFJoin/Create.php'; |
6a488035 TO |
233 | $result = UF_join_create_example(); |
234 | $expectedResult = UF_join_create_expectedresult(); | |
235 | $this->assertEquals($result, $expectedResult); | |
236 | } | |
96025800 | 237 | |
6a488035 | 238 | } |