Mass update tests to use callAPIFailure
[civicrm-core.git] / tests / phpunit / api / v3 / UFMatchTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29
30
31
32 require_once 'CiviTest/CiviUnitTestCase.php';
33
34 /**
35 * Test class for UFGroup API - civicrm_uf_*
36 * @todo Split UFGroup and UFJoin tests
37 *
38 * @package CiviCRM
39 */
40 class api_v3_UFMatchTest extends CiviUnitTestCase {
41 // ids from the uf_group_test.xml fixture
42 protected $_ufGroupId = 11;
43 protected $_ufFieldId;
44 protected $_contactId;
45 protected $_apiversion;
46 protected $_params = array();
47
48 public $_eNoticeCompliant = TRUE;
49
50 protected function setUp() {
51 parent::setUp();
52 $this->_apiversion = 3;
53 $this->quickCleanup(
54 array(
55 'civicrm_group',
56 'civicrm_contact',
57 'civicrm_uf_group',
58 'civicrm_uf_join',
59 'civicrm_uf_match',
60 )
61 );
62 $this->_contactId = $this->individualCreate();
63 $op = new PHPUnit_Extensions_Database_Operation_Insert;
64 $op->execute(
65 $this->_dbconn,
66 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')
67 );
68
69 $this->_params = array(
70 'contact_id' => $this->_contactId,
71 'uf_id' => '2',
72 'uf_name' => 'blahdyblah@gmail.com',
73 'version' => '3',
74 'domain_id' => 1,
75 );
76 }
77
78 function tearDown() {
79 // Truncate the tables
80 $this->quickCleanup(
81 array(
82 'civicrm_group',
83 'civicrm_contact',
84 'civicrm_uf_group',
85 'civicrm_uf_join',
86 'civicrm_uf_match',
87 )
88 );
89 }
90
91 /**
92 * fetch contact id by uf id
93 */
94 public function testGetUFMatchID() {
95 $params = array(
96 'uf_id' => 42,
97 'version' => $this->_apiversion,
98 );
99 $result = civicrm_api('uf_match', 'get', $params);
100 $this->assertEquals($result['values'][$result['id']]['contact_id'], 69);
101 $this->assertAPISuccess($result);
102 }
103
104 function testGetUFMatchIDWrongParam() {
105 $params = 'a string';
106 $result = $this->callAPIFailure('uf_match', 'get', $params);
107 }
108
109 /**
110 * fetch uf id by contact id
111 */
112 public function testGetUFID() {
113 $params = array(
114 'contact_id' => 69,
115 'version' => $this->_apiversion,
116 );
117 $result = civicrm_api('uf_match', 'get', $params);
118 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
119 $this->assertEquals($result['values'][$result['id']]['uf_id'], 42);
120 $this->assertAPISuccess($result);
121 }
122
123 function testGetUFIDWrongParam() {
124 $params = 'a string';
125 $result = $this->callAPIFailure('uf_match', 'get', $params);
126 }
127
128 /**
129 * Test civicrm_activity_create() using example code
130 */
131 function testUFMatchGetExample() {
132 require_once 'api/v3/examples/UFMatchGet.php';
133 $result = UF_match_get_example();
134 $expectedResult = UF_match_get_expectedresult();
135 $this->assertEquals($result, $expectedResult);
136 }
137
138 function testCreate() {
139 $result = civicrm_api('uf_match', 'create', $this->_params);
140 $this->assertAPISuccess($result);
141 $this->getAndCheck($this->_params, $result['id'], 'uf_match');
142 }
143
144 function testDelete() {
145 $result = civicrm_api('uf_match', 'create', $this->_params);
146 $this->assertEquals(1, civicrm_api('uf_match', 'getcount', array(
147 'version' => $this->_apiversion,
148 'id' => $result['id'],
149 )));
150 civicrm_api('uf_match', 'delete', array(
151 'version' => $this->_apiversion,
152 'id' => $result['id'],
153 ));
154 $this->assertEquals(0, civicrm_api('uf_match', 'getcount', array(
155 'version' => $this->_apiversion,
156 'id' => $result['id'],
157 )));
158 }
159 }
160