Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
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 = civicrm_api('uf_match', 'get', $params); | |
107 | $this->assertEquals($result['is_error'], 1); | |
108 | } | |
109 | ||
110 | /** | |
111 | * fetch uf id by contact id | |
112 | */ | |
113 | public function testGetUFID() { | |
114 | $params = array( | |
115 | 'contact_id' => 69, | |
116 | 'version' => $this->_apiversion, | |
117 | ); | |
118 | $result = civicrm_api('uf_match', 'get', $params); | |
119 | $this->documentMe($params, $result, __FUNCTION__, __FILE__); | |
120 | $this->assertEquals($result['values'][$result['id']]['uf_id'], 42); | |
121 | $this->assertAPISuccess($result); | |
122 | } | |
123 | ||
124 | function testGetUFIDWrongParam() { | |
125 | $params = 'a string'; | |
126 | $result = civicrm_api('uf_match', 'get', $params); | |
127 | $this->assertEquals($result['is_error'], 1); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Test civicrm_activity_create() using example code | |
132 | */ | |
133 | function testUFMatchGetExample() { | |
134 | require_once 'api/v3/examples/UFMatchGet.php'; | |
135 | $result = UF_match_get_example(); | |
136 | $expectedResult = UF_match_get_expectedresult(); | |
137 | $this->assertEquals($result, $expectedResult); | |
138 | } | |
139 | ||
140 | function testCreate() { | |
141 | $result = civicrm_api('uf_match', 'create', $this->_params); | |
142 | $this->assertAPISuccess($result); | |
143 | $this->getAndCheck($this->_params, $result['id'], 'uf_match'); | |
144 | } | |
145 | ||
146 | function testDelete() { | |
147 | $result = civicrm_api('uf_match', 'create', $this->_params); | |
148 | $this->assertEquals(1, civicrm_api('uf_match', 'getcount', array( | |
149 | 'version' => $this->_apiversion, | |
150 | 'id' => $result['id'], | |
151 | ))); | |
152 | civicrm_api('uf_match', 'delete', array( | |
153 | 'version' => $this->_apiversion, | |
154 | 'id' => $result['id'], | |
155 | )); | |
156 | $this->assertEquals(0, civicrm_api('uf_match', 'getcount', array( | |
157 | 'version' => $this->_apiversion, | |
158 | 'id' => $result['id'], | |
159 | ))); | |
160 | } | |
161 | } | |
162 |