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