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