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