3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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 * Test class for UFGroup API - civicrm_uf_*
30 * @todo Split UFGroup and UFJoin tests
34 class api_v3_UFJoinTest
extends CiviUnitTestCase
{
35 // ids from the uf_group_test.xml fixture
36 protected $_ufGroupId = 11;
37 protected $_ufFieldId;
38 protected $_contactId = 69;
39 protected $_apiversion;
41 protected function setUp() {
43 // Truncate the tables
53 $this->_apiversion
= 3;
54 $op = new PHPUnit_Extensions_Database_Operation_Insert();
57 $this->createFlatXMLDataSet(dirname(__FILE__
) . '/dataset/uf_group_test.xml')
61 public function tearDown() {
62 // Truncate the tables
75 * Find uf join group id.
77 public function testFindUFGroupId() {
79 'module' => 'CiviContribute',
80 'entity_table' => 'civicrm_contribution_page',
83 'uf_group_id' => $this->_ufGroupId
,
86 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
88 $searchParams = array(
89 'entity_table' => 'civicrm_contribution_page',
92 $result = $this->callAPISuccess('uf_join', 'get', $searchParams);
94 foreach ($result['values'] as $key => $value) {
95 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId
);
100 public function testUFJoinEditWrongParamsType() {
101 $params = 'a string';
102 $result = $this->callAPIFailure('uf_join', 'create', $params);
103 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
106 public function testUFJoinEditEmptyParams() {
108 $result = $this->callAPIFailure('uf_join', 'create', $params);
109 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id');
112 public function testUFJoinEditWithoutUFGroupId() {
114 'module' => 'CiviContribute',
115 'entity_table' => 'civicrm_contribution_page',
120 $result = $this->callAPIFailure('uf_join', 'create', $params);
121 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id');
125 * Create/update uf join
127 public function testCreateUFJoin() {
129 'module' => 'CiviContribute',
130 'entity_table' => 'civicrm_contribution_page',
133 'uf_group_id' => $this->_ufGroupId
,
137 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
138 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
139 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
140 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
143 'id' => $ufJoin['id'],
144 'module' => 'CiviContribute',
145 'entity_table' => 'civicrm_contribution_page',
148 'uf_group_id' => $this->_ufGroupId
,
152 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
153 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module']);
154 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id']);
155 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active']);
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');
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');
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');
185 public function testGetUFJoinId() {
187 'module' => 'CiviContribute',
188 'entity_table' => 'civicrm_contribution_page',
191 'uf_group_id' => $this->_ufGroupId
,
195 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
196 $searchParams = array(
197 'entity_table' => 'civicrm_contribution_page',
202 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__
, __FILE__
);
203 $this->assertEquals($result['values'][0]['module'], $params['module']);
204 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id']);
205 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id']);
209 * Test civicrm_activity_create() using example code.
211 public function testUFJoinCreateExample() {
212 require_once 'api/v3/examples/UFJoin/Create.php';
213 $result = UF_join_create_example();
214 $expectedResult = UF_join_create_expectedresult();
215 $this->assertEquals($result, $expectedResult);