3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 * Ensure we can create a survey join which is less common than event or contribution
163 public function testCreateSurveyUFJoin() {
165 'module' => 'CiviCampaign',
166 'entity_table' => 'civicrm_survey',
169 'uf_group_id' => $this->_ufGroupId
,
173 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__
, __FILE__
);
174 $this->assertEquals($ufJoin['values'][0]['module'], $params['module']);
175 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id']);
176 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active']);
179 public function testFindUFJoinWrongParamsType() {
180 $params = 'a string';
181 $result = $this->callAPIFailure('uf_join', 'create', $params);
182 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array');
185 public function testFindUFJoinEmptyParams() {
186 $result = $this->callAPIFailure('uf_join', 'create', array());
187 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id');
190 public function testFindUFJoinWithoutUFGroupId() {
192 'module' => 'CiviContribute',
193 'entity_table' => 'civicrm_contribution_page',
198 $result = $this->callAPIFailure('uf_join', 'create', $params);
199 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id');
205 public function testGetUFJoinId() {
207 'module' => 'CiviContribute',
208 'entity_table' => 'civicrm_contribution_page',
211 'uf_group_id' => $this->_ufGroupId
,
215 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
216 $searchParams = array(
217 'entity_table' => 'civicrm_contribution_page',
222 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__
, __FILE__
);
223 $this->assertEquals($result['values'][0]['module'], $params['module']);
224 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id']);
225 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id']);
229 * Test civicrm_activity_create() using example code.
231 public function testUFJoinCreateExample() {
232 require_once 'api/v3/examples/UFJoin/Create.php';
233 $result = UF_join_create_example();
234 $expectedResult = UF_join_create_expectedresult();
235 $this->assertEquals($result, $expectedResult);