3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test class for UFGroup API - civicrm_uf_*
14 * @todo Split UFGroup and UFJoin tests
19 class api_v3_UFJoinTest
extends CiviUnitTestCase
{
21 * ids from the uf_group_test.xml fixture
24 protected $_ufGroupId = 11;
25 protected $_ufFieldId;
26 protected $_contactId = 69;
28 protected function setUp() {
30 // Truncate the tables
40 $this->loadXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml');
43 public function tearDown() {
44 // Truncate the tables
57 * Find uf join group id.
59 * @dataProvider versionThreeAndFour
61 public function testFindUFGroupId($version) {
62 $this->_apiversion
= $version;
64 'module' => 'CiviContribute',
65 'entity_table' => 'civicrm_contribution_page',
68 'uf_group_id' => $this->_ufGroupId
,
71 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
74 'entity_table' => 'civicrm_contribution_page',
77 $result = $this->callAPISuccess('uf_join', 'get', $searchParams);
79 foreach ($result['values'] as $key => $value) {
80 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId
);
86 * @dataProvider versionThreeAndFour
88 public function testUFJoinEditWithoutUFGroupId($version) {
89 $this->_apiversion
= $version;
91 'module' => 'CiviContribute',
92 'entity_table' => 'civicrm_contribution_page',
97 $result = $this->callAPIFailure('uf_join', 'create', $params);
98 $this->assertContains('Mandatory', $result['error_message']);
99 $this->assertContains('missing', $result['error_message']);
100 $this->assertContains('uf_group_id', $result['error_message']);
104 * Create/update uf join
105 * @param int $version
106 * @dataProvider versionThreeAndFour
108 public function testCreateUFJoin($version) {
109 $this->_apiversion
= $version;
111 'module' => 'CiviContribute',
112 'entity_table' => 'civicrm_contribution_page',
115 'uf_group_id' => $this->_ufGroupId
,
119 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
120 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
121 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
122 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
125 'id' => $ufJoin['id'],
126 'module' => 'CiviContribute',
127 'entity_table' => 'civicrm_contribution_page',
130 'uf_group_id' => $this->_ufGroupId
,
134 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
135 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']);
136 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']);
137 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active']);
141 * Ensure we can create a survey join which is less common than event or contribution
143 * @param int $version
144 * @dataProvider versionThreeAndFour
146 public function testCreateSurveyUFJoin($version) {
147 $this->_apiversion
= $version;
149 'module' => 'CiviCampaign',
150 'entity_table' => 'civicrm_survey',
153 'uf_group_id' => $this->_ufGroupId
,
157 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
158 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
159 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
160 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
164 * @param int $version
165 * @dataProvider versionThreeAndFour
167 public function testFindUFJoinEmptyParams($version) {
168 $this->_apiversion
= $version;
169 $result = $this->callAPIFailure('uf_join', 'create', []);
170 $this->assertContains('Mandatory', $result['error_message']);
171 $this->assertContains('missing', $result['error_message']);
172 $this->assertContains('module', $result['error_message']);
173 $this->assertContains('uf_group_id', $result['error_message']);
177 * @param int $version
178 * @dataProvider versionThreeAndFour
180 public function testCreateUFJoinWithoutUFGroupId($version) {
181 $this->_apiversion
= $version;
183 'module' => 'CiviContribute',
184 'entity_table' => 'civicrm_contribution_page',
189 $result = $this->callAPIFailure('uf_join', 'create', $params);
190 $this->assertContains('Mandatory', $result['error_message']);
191 $this->assertContains('missing', $result['error_message']);
192 $this->assertContains('uf_group_id', $result['error_message']);
197 * @param int $version
198 * @dataProvider versionThreeAndFour
200 public function testGetUFJoinId($version) {
201 $this->_apiversion
= $version;
203 'module' => 'CiviContribute',
204 'entity_table' => 'civicrm_contribution_page',
207 'uf_group_id' => $this->_ufGroupId
,
211 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
213 'entity_table' => 'civicrm_contribution_page',
218 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__
, __FILE__
);
219 $this->assertEquals($result['values'][0]['module'], $params['module']);
220 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id']);
221 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id']);
225 * Test civicrm_activity_create() using example code.
226 * @param int $version
227 * @dataProvider versionThreeAndFour
229 public function testUFJoinCreateExample($version) {
230 $this->_apiversion
= $version;
231 require_once 'api/v3/examples/UFJoin/Create.ex.php';
232 $result = UF_join_create_example();
233 $expectedResult = UF_join_create_expectedresult();
234 $this->assertEquals($result, $expectedResult);