3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Test class for UFGroup API - civicrm_uf_*
30 * @todo Split UFGroup and UFJoin tests
35 class api_v3_UFJoinTest
extends CiviUnitTestCase
{
36 // ids from the uf_group_test.xml fixture
37 protected $_ufGroupId = 11;
38 protected $_ufFieldId;
39 protected $_contactId = 69;
40 protected $_apiversion;
42 protected function setUp() {
44 // Truncate the tables
54 $this->_apiversion
= 3;
55 $op = new PHPUnit_Extensions_Database_Operation_Insert();
58 $this->createFlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
62 public function tearDown() {
63 // Truncate the tables
76 * Find uf join group id.
78 public function testFindUFGroupId() {
80 'module' => 'CiviContribute',
81 'entity_table' => 'civicrm_contribution_page',
84 'uf_group_id' => $this->_ufGroupId
,
87 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
89 $searchParams = array(
90 'entity_table' => 'civicrm_contribution_page',
93 $result = $this->callAPISuccess('uf_join', 'get', $searchParams);
95 foreach ($result['values'] as $key => $value) {
96 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId
);
101 public function testUFJoinEditWrongParamsType() {
102 $params = 'a string';
103 $result = $this->callAPIFailure('uf_join', 'create', $params);
104 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
107 public function testUFJoinEditEmptyParams() {
109 $result = $this->callAPIFailure('uf_join', 'create', $params);
110 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id');
113 public function testUFJoinEditWithoutUFGroupId() {
115 'module' => 'CiviContribute',
116 'entity_table' => 'civicrm_contribution_page',
121 $result = $this->callAPIFailure('uf_join', 'create', $params);
122 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id');
126 * Create/update uf join
128 public function testCreateUFJoin() {
130 'module' => 'CiviContribute',
131 'entity_table' => 'civicrm_contribution_page',
134 'uf_group_id' => $this->_ufGroupId
,
138 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
139 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
140 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
141 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
144 'id' => $ufJoin['id'],
145 'module' => 'CiviContribute',
146 'entity_table' => 'civicrm_contribution_page',
149 'uf_group_id' => $this->_ufGroupId
,
153 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
154 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']);
155 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']);
156 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active']);
160 public function testFindUFJoinWrongParamsType() {
161 $params = 'a string';
162 $result = $this->callAPIFailure('uf_join', 'create', $params);
163 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
166 public function testFindUFJoinEmptyParams() {
167 $result = $this->callAPIFailure('uf_join', 'create', array());
168 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id');
171 public function testFindUFJoinWithoutUFGroupId() {
173 'module' => 'CiviContribute',
174 'entity_table' => 'civicrm_contribution_page',
179 $result = $this->callAPIFailure('uf_join', 'create', $params);
180 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id');
186 public function testGetUFJoinId() {
188 'module' => 'CiviContribute',
189 'entity_table' => 'civicrm_contribution_page',
192 'uf_group_id' => $this->_ufGroupId
,
196 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
197 $searchParams = array(
198 'entity_table' => 'civicrm_contribution_page',
203 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__
, __FILE__
);
204 $this->assertEquals($result['values'][0]['module'], $params['module']);
205 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id']);
206 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id']);
210 * Test civicrm_activity_create() using example code.
212 public function testUFJoinCreateExample() {
213 require_once 'api/v3/examples/UFJoin/Create.php';
214 $result = UF_join_create_example();
215 $expectedResult = UF_join_create_expectedresult();
216 $this->assertEquals($result, $expectedResult);