3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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')
66 public function tearDown() {
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
,
139 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
140 $this->assertEquals($ufJoin['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
141 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
142 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
145 'id' => $ufJoin['id'],
146 'module' => 'CiviContribute',
147 'entity_table' => 'civicrm_contribution_page',
150 'uf_group_id' => $this->_ufGroupId
,
154 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
155 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module'], 'In line ' . __LINE__
);
156 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
157 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__
);
161 public function testFindUFJoinWrongParamsType() {
162 $params = 'a string';
163 $result = $this->callAPIFailure('uf_join', 'create', $params);
164 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__
);
167 public function testFindUFJoinEmptyParams() {
168 $result = $this->callAPIFailure('uf_join', 'create', array());
169 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id', 'In line ' . __LINE__
);
172 public function testFindUFJoinWithoutUFGroupId() {
174 'module' => 'CiviContribute',
175 'entity_table' => 'civicrm_contribution_page',
180 $result = $this->callAPIFailure('uf_join', 'create', $params);
181 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__
);
187 public function testGetUFJoinId() {
189 'module' => 'CiviContribute',
190 'entity_table' => 'civicrm_contribution_page',
193 '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'], 'In line ' . __LINE__
);
205 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__
);
206 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id'], 'In line ' . __LINE__
);
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);