Merge pull request #7722 from kcristiano/17593
[civicrm-core.git] / tests / phpunit / api / v3 / UFMatchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Test class for UFGroup API - civicrm_uf_*
30 * @todo Split UFGroup and UFJoin tests
31 *
32 * @package CiviCRM
33 */
34 class api_v3_UFMatchTest extends CiviUnitTestCase {
35 // ids from the uf_group_test.xml fixture
36 protected $_ufGroupId = 11;
37 protected $_ufFieldId;
38 protected $_contactId;
39 protected $_apiversion;
40 protected $_params = array();
41
42
43 protected function setUp() {
44 parent::setUp();
45 $this->_apiversion = 3;
46 $this->quickCleanup(
47 array(
48 'civicrm_group',
49 'civicrm_contact',
50 'civicrm_uf_group',
51 'civicrm_uf_join',
52 'civicrm_uf_match',
53 )
54 );
55 $this->_contactId = $this->individualCreate();
56 $op = new PHPUnit_Extensions_Database_Operation_Insert();
57 $op->execute(
58 $this->_dbconn,
59 $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')
60 );
61
62 $this->_params = array(
63 'contact_id' => $this->_contactId,
64 'uf_id' => '2',
65 'uf_name' => 'blahdyblah@gmail.com',
66 'domain_id' => 1,
67 );
68 }
69
70 public function tearDown() {
71 // Truncate the tables
72 $this->quickCleanup(
73 array(
74 'civicrm_group',
75 'civicrm_contact',
76 'civicrm_uf_group',
77 'civicrm_uf_join',
78 'civicrm_uf_match',
79 )
80 );
81 }
82
83 /**
84 * Fetch contact id by uf id.
85 */
86 public function testGetUFMatchID() {
87 $params = array(
88 'uf_id' => 42,
89 );
90 $result = $this->callAPISuccess('uf_match', 'get', $params);
91 $this->assertEquals($result['values'][$result['id']]['contact_id'], 69);
92 }
93
94 public function testGetUFMatchIDWrongParam() {
95 $params = 'a string';
96 $result = $this->callAPIFailure('uf_match', 'get', $params);
97 }
98
99 /**
100 * Fetch uf id by contact id.
101 */
102 public function testGetUFID() {
103 $params = array(
104 'contact_id' => 69,
105 );
106 $result = $this->callAPIAndDocument('uf_match', 'get', $params, __FUNCTION__, __FILE__);
107 $this->assertEquals($result['values'][$result['id']]['uf_id'], 42);
108 }
109
110 public function testGetUFIDWrongParam() {
111 $params = 'a string';
112 $result = $this->callAPIFailure('uf_match', 'get', $params);
113 }
114
115 /**
116 * Test civicrm_activity_create() using example code
117 */
118 public function testUFMatchGetExample() {
119 require_once 'api/v3/examples/UFMatch/Get.php';
120 $result = UF_match_get_example();
121 $expectedResult = UF_match_get_expectedresult();
122 $this->assertEquals($result, $expectedResult);
123 }
124
125 public function testCreate() {
126 $result = $this->callAPISuccess('uf_match', 'create', $this->_params);
127 $this->getAndCheck($this->_params, $result['id'], 'uf_match');
128 }
129
130 public function testDelete() {
131 $result = $this->callAPISuccess('uf_match', 'create', $this->_params);
132 $this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', array(
133 'id' => $result['id'],
134 )));
135 $this->callAPISuccess('uf_match', 'delete', array(
136 'id' => $result['id'],
137 ));
138 $this->assertEquals(0, $this->callAPISuccess('uf_match', 'getcount', array(
139 'id' => $result['id'],
140 )));
141 }
142
143 }