3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test class for UFGroup API - civicrm_uf_*
33 * @todo Split UFGroup and UFJoin tests
37 class api_v3_UFJoinTest
extends CiviUnitTestCase
{
38 // ids from the uf_group_test.xml fixture
39 protected $_ufGroupId = 11;
40 protected $_ufFieldId;
41 protected $_contactId = 69;
42 protected $_apiversion;
44 protected function setUp() {
46 // Truncate the tables
56 $this->_apiversion
= 3;
57 $op = new PHPUnit_Extensions_Database_Operation_Insert();
60 $this->createFlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
64 public function tearDown() {
65 // Truncate the tables
78 * Find uf join group id.
80 public function testFindUFGroupId() {
82 'module' => 'CiviContribute',
83 'entity_table' => 'civicrm_contribution_page',
86 'uf_group_id' => $this->_ufGroupId
,
89 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
91 $searchParams = array(
92 '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
);
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');
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');
115 public function testUFJoinEditWithoutUFGroupId() {
117 'module' => 'CiviContribute',
118 'entity_table' => 'civicrm_contribution_page',
123 $result = $this->callAPIFailure('uf_join', 'create', $params);
124 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id');
128 * Create/update uf join
130 public function testCreateUFJoin() {
132 'module' => 'CiviContribute',
133 'entity_table' => 'civicrm_contribution_page',
136 'uf_group_id' => $this->_ufGroupId
,
140 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
141 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
142 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
143 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
146 'id' => $ufJoin['id'],
147 'module' => 'CiviContribute',
148 'entity_table' => 'civicrm_contribution_page',
151 'uf_group_id' => $this->_ufGroupId
,
155 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
156 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']);
157 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']);
158 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active']);
162 public function testFindUFJoinWrongParamsType() {
163 $params = 'a string';
164 $result = $this->callAPIFailure('uf_join', 'create', $params);
165 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
168 public function testFindUFJoinEmptyParams() {
169 $result = $this->callAPIFailure('uf_join', 'create', array());
170 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id');
173 public function testFindUFJoinWithoutUFGroupId() {
175 'module' => 'CiviContribute',
176 'entity_table' => 'civicrm_contribution_page',
181 $result = $this->callAPIFailure('uf_join', 'create', $params);
182 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id');
188 public function testGetUFJoinId() {
190 'module' => 'CiviContribute',
191 'entity_table' => 'civicrm_contribution_page',
194 'uf_group_id' => $this->_ufGroupId
,
198 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
199 $searchParams = array(
200 'entity_table' => 'civicrm_contribution_page',
205 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__
, __FILE__
);
206 $this->assertEquals($result['values'][0]['module'], $params['module']);
207 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id']);
208 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id']);
212 * Test civicrm_activity_create() using example code.
214 public function testUFJoinCreateExample() {
215 require_once 'api/v3/examples/UFJoin/Create.php';
216 $result = UF_join_create_example();
217 $expectedResult = UF_join_create_expectedresult();
218 $this->assertEquals($result, $expectedResult);