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_UFMatchTest
extends CiviUnitTestCase
{
21 * ids from the uf_group_test.xml fixture
24 protected $_ufGroupId = 11;
25 protected $_ufFieldId;
26 protected $_contactId;
27 protected $_params = [];
29 protected function setUp() {
40 $this->_contactId
= $this->individualCreate();
41 $this->loadXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml');
44 'contact_id' => $this->_contactId
,
46 'uf_name' => 'blahdyblah@gmail.com',
51 public function tearDown() {
52 // Truncate the tables
65 * Fetch contact id by uf id.
67 * @dataProvider versionThreeAndFour
69 public function testGetUFMatchID($version) {
70 $this->_apiversion
= $version;
74 $result = $this->callAPISuccess('uf_match', 'get', $params);
75 $this->assertEquals($result['values'][$result['id']]['contact_id'], 69);
79 * Fetch uf id by contact id.
81 * @dataProvider versionThreeAndFour
83 public function testGetUFID($version) {
84 $this->_apiversion
= $version;
88 $result = $this->callAPIAndDocument('uf_match', 'get', $params, __FUNCTION__
, __FILE__
);
89 $this->assertEquals($result['values'][$result['id']]['uf_id'], 42);
93 * Test civicrm_activity_create() using example code
95 * @dataProvider versionThreeAndFour
97 public function testUFMatchGetExample($version) {
98 $this->_apiversion
= $version;
99 require_once 'api/v3/examples/UFMatch/Get.ex.php';
100 $result = UF_match_get_example();
101 $expectedResult = UF_match_get_expectedresult();
102 $this->assertEquals($result, $expectedResult);
106 * @param int $version
107 * @dataProvider versionThreeAndFour
109 public function testCreate($version) {
110 $this->_apiversion
= $version;
111 $result = $this->callAPISuccess('uf_match', 'create', $this->_params
);
112 $this->getAndCheck($this->_params
, $result['id'], 'uf_match');
116 * Test Civi to CMS email sync optional
117 * @param int $version
118 * @dataProvider versionThreeAndFour
120 public function testUFNameMatchSync($version) {
121 $this->_apiversion
= $version;
122 $this->callAPISuccess('uf_match', 'create', $this->_params
);
123 $email1 = substr(sha1(rand()), 0, 7) . '@test.com';
124 $email2 = substr(sha1(rand()), 0, 7) . '@test.com';
126 // Case A: Enable CMS integration
127 Civi
::settings()->set('syncCMSEmail', TRUE);
128 $this->callAPISuccess('email', 'create', [
129 'contact_id' => $this->_contactId
,
133 $ufName = $this->callAPISuccess('uf_match', 'getvalue', [
134 'contact_id' => $this->_contactId
,
135 'return' => 'uf_name',
137 $this->assertEquals($email1, $ufName);
139 // Case B: Disable CMS integration
140 Civi
::settings()->set('syncCMSEmail', FALSE);
141 $this->callAPISuccess('email', 'create', [
142 'contact_id' => $this->_contactId
,
146 $ufName = $this->callAPISuccess('uf_match', 'getvalue', [
147 'contact_id' => $this->_contactId
,
148 'return' => 'uf_name',
150 $this->assertNotEquals($email2, $ufName, 'primary email will not match if changed on disabled CMS integration setting');
151 $this->assertEquals($email1, $ufName);
155 * @param int $version
156 * @dataProvider versionThreeAndFour
158 public function testDelete($version) {
159 $this->_apiversion
= $version;
160 $result = $this->callAPISuccess('uf_match', 'create', $this->_params
);
161 $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', [
162 'id' => $result['id'],
164 $this->callAPISuccess('uf_match', 'delete', [
165 'id' => $result['id'],
167 $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', [
168 'id' => $result['id'],