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_UFMatchTest
extends CiviUnitTestCase
{
37 * ids from the uf_group_test.xml fixture
40 protected $_ufGroupId = 11;
41 protected $_ufFieldId;
42 protected $_contactId;
43 protected $_params = [];
45 protected function setUp() {
56 $this->_contactId
= $this->individualCreate();
57 $this->loadXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml');
60 'contact_id' => $this->_contactId
,
62 'uf_name' => 'blahdyblah@gmail.com',
67 public function tearDown() {
68 // Truncate the tables
81 * Fetch contact id by uf id.
83 * @dataProvider versionThreeAndFour
85 public function testGetUFMatchID($version) {
86 $this->_apiversion
= $version;
90 $result = $this->callAPISuccess('uf_match', 'get', $params);
91 $this->assertEquals($result['values'][$result['id']]['contact_id'], 69);
96 * @dataProvider versionThreeAndFour
98 public function testGetUFMatchIDWrongParam($version) {
99 $this->_apiversion
= $version;
100 $params = 'a string';
101 $result = $this->callAPIFailure('uf_match', 'get', $params);
105 * Fetch uf id by contact id.
106 * @param int $version
107 * @dataProvider versionThreeAndFour
109 public function testGetUFID($version) {
110 $this->_apiversion
= $version;
114 $result = $this->callAPIAndDocument('uf_match', 'get', $params, __FUNCTION__
, __FILE__
);
115 $this->assertEquals($result['values'][$result['id']]['uf_id'], 42);
119 * @param int $version
120 * @dataProvider versionThreeAndFour
122 public function testGetUFIDWrongParam($version) {
123 $this->_apiversion
= $version;
124 $params = 'a string';
125 $result = $this->callAPIFailure('uf_match', 'get', $params);
129 * Test civicrm_activity_create() using example code
130 * @param int $version
131 * @dataProvider versionThreeAndFour
133 public function testUFMatchGetExample($version) {
134 $this->_apiversion
= $version;
135 require_once 'api/v3/examples/UFMatch/Get.ex.php';
136 $result = UF_match_get_example();
137 $expectedResult = UF_match_get_expectedresult();
138 $this->assertEquals($result, $expectedResult);
142 * @param int $version
143 * @dataProvider versionThreeAndFour
145 public function testCreate($version) {
146 $this->_apiversion
= $version;
147 $result = $this->callAPISuccess('uf_match', 'create', $this->_params
);
148 $this->getAndCheck($this->_params
, $result['id'], 'uf_match');
152 * Test Civi to CMS email sync optional
153 * @param int $version
154 * @dataProvider versionThreeAndFour
156 public function testUFNameMatchSync($version) {
157 $this->_apiversion
= $version;
158 $this->callAPISuccess('uf_match', 'create', $this->_params
);
159 $email1 = substr(sha1(rand()), 0, 7) . '@test.com';
160 $email2 = substr(sha1(rand()), 0, 7) . '@test.com';
162 // Case A: Enable CMS integration
163 Civi
::settings()->set('syncCMSEmail', TRUE);
164 $this->callAPISuccess('email', 'create', [
165 'contact_id' => $this->_contactId
,
169 $ufName = $this->callAPISuccess('uf_match', 'getvalue', [
170 'contact_id' => $this->_contactId
,
171 'return' => 'uf_name',
173 $this->assertEquals($email1, $ufName);
175 // Case B: Disable CMS integration
176 Civi
::settings()->set('syncCMSEmail', FALSE);
177 $this->callAPISuccess('email', 'create', [
178 'contact_id' => $this->_contactId
,
182 $ufName = $this->callAPISuccess('uf_match', 'getvalue', [
183 'contact_id' => $this->_contactId
,
184 'return' => 'uf_name',
186 $this->assertNotEquals($email2, $ufName, 'primary email will not match if changed on disabled CMS integration setting');
187 $this->assertEquals($email1, $ufName);
191 * @param int $version
192 * @dataProvider versionThreeAndFour
194 public function testDelete($version) {
195 $this->_apiversion
= $version;
196 $result = $this->callAPISuccess('uf_match', 'create', $this->_params
);
197 $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', [
198 'id' => $result['id'],
200 $this->callAPISuccess('uf_match', 'delete', [
201 'id' => $result['id'],
203 $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', [
204 'id' => $result['id'],