3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
31 require_once 'CiviTest/CiviUnitTestCase.php';
34 * Test class for UFGroup API - civicrm_uf_*
35 * @todo Split UFGroup and UFJoin tests
39 class api_v3_UFJoinTest
extends CiviUnitTestCase
{
40 // ids from the uf_group_test.xml fixture
41 protected $_ufGroupId = 11;
42 protected $_ufFieldId;
43 protected $_contactId = 69;
44 protected $_apiversion;
46 protected function setUp() {
48 // Truncate the tables
58 $this->_apiversion
= 3;
59 $op = new PHPUnit_Extensions_Database_Operation_Insert
;
62 $this->createFlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
67 // Truncate the tables
80 * find uf join group id
82 public function testFindUFGroupId() {
84 'module' => 'CiviContribute',
85 'entity_table' => 'civicrm_contribution_page',
88 'uf_group_id' => $this->_ufGroupId
,
90 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
92 $searchParams = array(
93 'entity_table' => 'civicrm_contribution_page',
95 $result = $this->callAPISuccess('uf_join', 'get', $searchParams);
97 foreach ($result['values'] as $key => $value) {
98 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId
, 'In line ' . __LINE__
);
103 public function testUFJoinEditWrongParamsType() {
104 $params = 'a string';
105 $result = $this->callAPIFailure('uf_join', 'create', $params);
106 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
109 public function testUFJoinEditEmptyParams() {
111 $result = $this->callAPIFailure('uf_join', 'create', $params);
112 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id', 'In line ' . __LINE__
);
115 public function testUFJoinEditWithoutUFGroupId() {
117 'module' => 'CiviContribute',
118 'entity_table' => 'civicrm_contribution_page',
122 $result = $this->callAPIFailure('uf_join', 'create', $params);
123 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__
);
127 * create/update uf join
129 public function testCreateUFJoin() {
131 'module' => 'CiviContribute',
132 'entity_table' => 'civicrm_contribution_page',
135 'uf_group_id' => $this->_ufGroupId
,
136 'is_active' => 1, 'sequential' => 1,
138 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
139 $this->assertEquals($ufJoin['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
140 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
141 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
144 'id' => $ufJoin['id'],
145 'module' => 'CiviContribute',
146 'entity_table' => 'civicrm_contribution_page',
149 'uf_group_id' => $this->_ufGroupId
,
150 'is_active' => 0, 'sequential' => 1,
152 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
153 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
154 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
155 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
159 public function testFindUFJoinWrongParamsType() {
160 $params = 'a string';
161 $result = $this->callAPIFailure('uf_join', 'create', $params);
162 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
165 public function testFindUFJoinEmptyParams() {
166 $result = $this->callAPIFailure('uf_join', 'create', array());
167 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id', 'In line ' . __LINE__
);
170 public function testFindUFJoinWithoutUFGroupId() {
172 'module' => 'CiviContribute',
173 'entity_table' => 'civicrm_contribution_page',
178 $result = $this->callAPIFailure('uf_join', 'create', $params);
179 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__
);
185 public function testGetUFJoinId() {
187 'module' => 'CiviContribute',
188 'entity_table' => 'civicrm_contribution_page',
191 'uf_group_id' => $this->_ufGroupId
,
194 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
195 $searchParams = array(
196 'entity_table' => 'civicrm_contribution_page',
197 'entity_id' => 1, 'sequential' => 1,
200 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__
, __FILE__
);
201 $this->assertEquals($result['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
202 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
203 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id'], 'In line ' . __LINE__
);
207 * Test civicrm_activity_create() using example code
209 function testUFJoinCreateExample() {
210 require_once 'api/v3/examples/UFJoin/Create.php';
211 $result = UF_join_create_example();
212 $expectedResult = UF_join_create_expectedresult();
213 $this->assertEquals($result, $expectedResult);