3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
29 * Test class for UFGroup API - civicrm_uf_*
30 * @todo Split UFGroup and UFJoin tests
35 class api_v3_UFJoinTest
extends CiviUnitTestCase
{
37 * ids from the uf_group_test.xml fixture
40 protected $_ufGroupId = 11;
41 protected $_ufFieldId;
42 protected $_contactId = 69;
44 protected function setUp() {
46 // Truncate the tables
56 $this->loadXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml');
59 public function tearDown() {
60 // Truncate the tables
73 * Find uf join group id.
75 * @dataProvider versionThreeAndFour
77 public function testFindUFGroupId($version) {
78 $this->_apiversion
= $version;
80 'module' => 'CiviContribute',
81 'entity_table' => 'civicrm_contribution_page',
84 'uf_group_id' => $this->_ufGroupId
,
87 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
90 'entity_table' => 'civicrm_contribution_page',
93 $result = $this->callAPISuccess('uf_join', 'get', $searchParams);
95 foreach ($result['values'] as $key => $value) {
96 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId
);
101 * @param int $version
102 * @dataProvider versionThreeAndFour
104 public function testUFJoinEditWrongParamsType($version) {
105 $this->_apiversion
= $version;
106 $params = 'a string';
107 $result = $this->callAPIFailure('uf_join', 'create', $params);
108 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
112 * @param int $version
113 * @dataProvider versionThreeAndFour
115 public function testUFJoinEditWithoutUFGroupId($version) {
116 $this->_apiversion
= $version;
118 'module' => 'CiviContribute',
119 'entity_table' => 'civicrm_contribution_page',
124 $result = $this->callAPIFailure('uf_join', 'create', $params);
125 $this->assertContains('Mandatory', $result['error_message']);
126 $this->assertContains('missing', $result['error_message']);
127 $this->assertContains('uf_group_id', $result['error_message']);
131 * Create/update uf join
132 * @param int $version
133 * @dataProvider versionThreeAndFour
135 public function testCreateUFJoin($version) {
136 $this->_apiversion
= $version;
138 'module' => 'CiviContribute',
139 'entity_table' => 'civicrm_contribution_page',
142 'uf_group_id' => $this->_ufGroupId
,
146 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
147 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
148 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
149 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
152 'id' => $ufJoin['id'],
153 'module' => 'CiviContribute',
154 'entity_table' => 'civicrm_contribution_page',
157 'uf_group_id' => $this->_ufGroupId
,
161 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
162 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']);
163 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']);
164 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active']);
168 * Ensure we can create a survey join which is less common than event or contribution
170 * @param int $version
171 * @dataProvider versionThreeAndFour
173 public function testCreateSurveyUFJoin($version) {
174 $this->_apiversion
= $version;
176 'module' => 'CiviCampaign',
177 'entity_table' => 'civicrm_survey',
180 'uf_group_id' => $this->_ufGroupId
,
184 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
185 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
186 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
187 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
191 * @param int $version
192 * @dataProvider versionThreeAndFour
194 public function testFindUFJoinEmptyParams($version) {
195 $this->_apiversion
= $version;
196 $result = $this->callAPIFailure('uf_join', 'create', []);
197 $this->assertContains('Mandatory', $result['error_message']);
198 $this->assertContains('missing', $result['error_message']);
199 $this->assertContains('module', $result['error_message']);
200 $this->assertContains('uf_group_id', $result['error_message']);
204 * @param int $version
205 * @dataProvider versionThreeAndFour
207 public function testCreateUFJoinWithoutUFGroupId($version) {
208 $this->_apiversion
= $version;
210 'module' => 'CiviContribute',
211 'entity_table' => 'civicrm_contribution_page',
216 $result = $this->callAPIFailure('uf_join', 'create', $params);
217 $this->assertContains('Mandatory', $result['error_message']);
218 $this->assertContains('missing', $result['error_message']);
219 $this->assertContains('uf_group_id', $result['error_message']);
224 * @param int $version
225 * @dataProvider versionThreeAndFour
227 public function testGetUFJoinId($version) {
228 $this->_apiversion
= $version;
230 'module' => 'CiviContribute',
231 'entity_table' => 'civicrm_contribution_page',
234 'uf_group_id' => $this->_ufGroupId
,
238 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
240 'entity_table' => 'civicrm_contribution_page',
245 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__
, __FILE__
);
246 $this->assertEquals($result['values'][0]['module'], $params['module']);
247 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id']);
248 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id']);
252 * Test civicrm_activity_create() using example code.
253 * @param int $version
254 * @dataProvider versionThreeAndFour
256 public function testUFJoinCreateExample($version) {
257 $this->_apiversion
= $version;
258 require_once 'api/v3/examples/UFJoin/Create.php';
259 $result = UF_join_create_example();
260 $expectedResult = UF_join_create_expectedresult();
261 $this->assertEquals($result, $expectedResult);