Merge pull request #19017 from eileenmcnaughton/remove_recur
[civicrm-core.git] / tests / phpunit / api / v3 / UFJoinTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
7d61e75f
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035 11
6a488035
TO
12/**
13 * Test class for UFGroup API - civicrm_uf_*
14 * @todo Split UFGroup and UFJoin tests
15 *
6c6e6187 16 * @package CiviCRM
acb109b7 17 * @group headless
6a488035
TO
18 */
19class api_v3_UFJoinTest extends CiviUnitTestCase {
39b959db
SL
20 /**
21 * ids from the uf_group_test.xml fixture
22 * @var int
23 */
6a488035
TO
24 protected $_ufGroupId = 11;
25 protected $_ufFieldId;
26 protected $_contactId = 69;
b7c9bc4c 27
6a488035
TO
28 protected function setUp() {
29 parent::setUp();
30 // Truncate the tables
31 $this->quickCleanup(
9099cab3 32 [
6a488035
TO
33 'civicrm_group',
34 'civicrm_contact',
35 'civicrm_uf_group',
36 'civicrm_uf_join',
37 'civicrm_uf_match',
9099cab3 38 ]
6a488035 39 );
1d291c60 40 $this->loadXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml');
6a488035
TO
41 }
42
00be9182 43 public function tearDown() {
6a488035
TO
44 // Truncate the tables
45 $this->quickCleanup(
9099cab3 46 [
6a488035
TO
47 'civicrm_group',
48 'civicrm_contact',
49 'civicrm_uf_group',
50 'civicrm_uf_join',
51 'civicrm_uf_match',
9099cab3 52 ]
6a488035
TO
53 );
54 }
55
56 /**
eceb18cc 57 * Find uf join group id.
2d932085
CW
58 * @param int $version
59 * @dataProvider versionThreeAndFour
6a488035 60 */
2d932085
CW
61 public function testFindUFGroupId($version) {
62 $this->_apiversion = $version;
9099cab3 63 $params = [
6a488035
TO
64 'module' => 'CiviContribute',
65 'entity_table' => 'civicrm_contribution_page',
66 'entity_id' => 1,
67 'weight' => 1,
68 'uf_group_id' => $this->_ufGroupId,
92915c55 69 'is_active' => 1,
9099cab3 70 ];
e6ff1593 71 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
6a488035 72
9099cab3 73 $searchParams = [
6a488035 74 'entity_table' => 'civicrm_contribution_page',
92915c55 75 'entity_id' => 1,
9099cab3 76 ];
e6ff1593 77 $result = $this->callAPISuccess('uf_join', 'get', $searchParams);
6a488035
TO
78
79 foreach ($result['values'] as $key => $value) {
a15773db 80 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId);
6a488035
TO
81 }
82 }
83
2d932085
CW
84 /**
85 * @param int $version
86 * @dataProvider versionThreeAndFour
87 */
88 public function testUFJoinEditWithoutUFGroupId($version) {
89 $this->_apiversion = $version;
9099cab3 90 $params = [
6a488035
TO
91 'module' => 'CiviContribute',
92 'entity_table' => 'civicrm_contribution_page',
93 'entity_id' => 1,
94 'weight' => 1,
92915c55 95 'is_active' => 1,
9099cab3 96 ];
d0e1eff2 97 $result = $this->callAPIFailure('uf_join', 'create', $params);
2d932085
CW
98 $this->assertContains('Mandatory', $result['error_message']);
99 $this->assertContains('missing', $result['error_message']);
100 $this->assertContains('uf_group_id', $result['error_message']);
6a488035
TO
101 }
102
103 /**
100fef9d 104 * Create/update uf join
2d932085
CW
105 * @param int $version
106 * @dataProvider versionThreeAndFour
6a488035 107 */
2d932085
CW
108 public function testCreateUFJoin($version) {
109 $this->_apiversion = $version;
9099cab3 110 $params = [
6a488035
TO
111 'module' => 'CiviContribute',
112 'entity_table' => 'civicrm_contribution_page',
113 'entity_id' => 1,
114 'weight' => 1,
115 'uf_group_id' => $this->_ufGroupId,
6c6e6187 116 'is_active' => 1,
92915c55 117 'sequential' => 1,
9099cab3 118 ];
e6ff1593 119 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__);
ba4a1892
TM
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']);
6a488035 123
9099cab3 124 $params = [
6a488035
TO
125 'id' => $ufJoin['id'],
126 'module' => 'CiviContribute',
127 'entity_table' => 'civicrm_contribution_page',
128 'entity_id' => 1,
129 'weight' => 1,
130 'uf_group_id' => $this->_ufGroupId,
6c6e6187 131 'is_active' => 0,
92915c55 132 'sequential' => 1,
9099cab3 133 ];
e6ff1593 134 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
ba4a1892
TM
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']);
6a488035
TO
138 }
139
9ca7d5da
JM
140 /**
141 * Ensure we can create a survey join which is less common than event or contribution
142 * joins.
2d932085
CW
143 * @param int $version
144 * @dataProvider versionThreeAndFour
9ca7d5da 145 */
2d932085
CW
146 public function testCreateSurveyUFJoin($version) {
147 $this->_apiversion = $version;
9099cab3 148 $params = [
9ca7d5da
JM
149 'module' => 'CiviCampaign',
150 'entity_table' => 'civicrm_survey',
151 'entity_id' => 1,
152 'weight' => 1,
153 'uf_group_id' => $this->_ufGroupId,
154 'is_active' => 1,
155 'sequential' => 1,
9099cab3 156 ];
9ca7d5da
JM
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']);
161 }
6a488035 162
2d932085
CW
163 /**
164 * @param int $version
165 * @dataProvider versionThreeAndFour
166 */
167 public function testFindUFJoinEmptyParams($version) {
168 $this->_apiversion = $version;
9099cab3 169 $result = $this->callAPIFailure('uf_join', 'create', []);
2d932085
CW
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']);
6a488035
TO
174 }
175
2d932085
CW
176 /**
177 * @param int $version
178 * @dataProvider versionThreeAndFour
179 */
180 public function testCreateUFJoinWithoutUFGroupId($version) {
181 $this->_apiversion = $version;
9099cab3 182 $params = [
6a488035
TO
183 'module' => 'CiviContribute',
184 'entity_table' => 'civicrm_contribution_page',
185 'entity_id' => 1,
186 'weight' => 1,
187 'is_active' => 1,
9099cab3 188 ];
d0e1eff2 189 $result = $this->callAPIFailure('uf_join', 'create', $params);
2d932085
CW
190 $this->assertContains('Mandatory', $result['error_message']);
191 $this->assertContains('missing', $result['error_message']);
192 $this->assertContains('uf_group_id', $result['error_message']);
6a488035
TO
193 }
194
195 /**
eceb18cc 196 * Find uf join id.
2d932085
CW
197 * @param int $version
198 * @dataProvider versionThreeAndFour
6a488035 199 */
2d932085
CW
200 public function testGetUFJoinId($version) {
201 $this->_apiversion = $version;
9099cab3 202 $params = [
6a488035
TO
203 'module' => 'CiviContribute',
204 'entity_table' => 'civicrm_contribution_page',
205 'entity_id' => 1,
206 'weight' => 1,
207 'uf_group_id' => $this->_ufGroupId,
92915c55 208 'is_active' => 1,
9099cab3 209 ];
6a488035 210
e6ff1593 211 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
9099cab3 212 $searchParams = [
6a488035 213 'entity_table' => 'civicrm_contribution_page',
6c6e6187 214 'entity_id' => 1,
92915c55 215 'sequential' => 1,
9099cab3 216 ];
6a488035 217
e6ff1593 218 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__, __FILE__);
ba4a1892
TM
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']);
6a488035
TO
222 }
223
224 /**
d177a2a6 225 * Test civicrm_activity_create() using example code.
2d932085
CW
226 * @param int $version
227 * @dataProvider versionThreeAndFour
6a488035 228 */
2d932085
CW
229 public function testUFJoinCreateExample($version) {
230 $this->_apiversion = $version;
be44cfcb 231 require_once 'api/v3/examples/UFJoin/Create.ex.php';
6a488035
TO
232 $result = UF_join_create_example();
233 $expectedResult = UF_join_create_expectedresult();
234 $this->assertEquals($result, $expectedResult);
235 }
96025800 236
6a488035 237}