Action schedule API modifications
[civicrm-core.git] / tests / phpunit / api / v3 / UFJoinTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28
29
30
31require_once 'CiviTest/CiviUnitTestCase.php';
32
33/**
34 * Test class for UFGroup API - civicrm_uf_*
35 * @todo Split UFGroup and UFJoin tests
36 *
37 * @package CiviCRM
38 */
39class 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;
45 public $_eNoticeCompliant = TRUE;
46 protected function setUp() {
47 parent::setUp();
48 // Truncate the tables
49 $this->quickCleanup(
50 array(
51 'civicrm_group',
52 'civicrm_contact',
53 'civicrm_uf_group',
54 'civicrm_uf_join',
55 'civicrm_uf_match',
56 )
57 );
58 $this->_apiversion = 3;
59 $op = new PHPUnit_Extensions_Database_Operation_Insert;
60 $op->execute(
61 $this->_dbconn,
62 new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml')
63 );
64
65 // FIXME: something NULLs $GLOBALS['_HTML_QuickForm_registered_rules'] when the tests are ran all together
66 $GLOBALS['_HTML_QuickForm_registered_rules'] = array(
67 'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'),
68 'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
69 'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
70 'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
71 'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'),
72 'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
73 'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
74 'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
75 'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
76 'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
77 'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
78 'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'),
79 'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php'),
80 );
81 // FIXME: …ditto for $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']
82 $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'] = array(
83 'group' => array('HTML/QuickForm/group.php', 'HTML_QuickForm_group'),
84 'hidden' => array('HTML/QuickForm/hidden.php', 'HTML_QuickForm_hidden'),
85 'reset' => array('HTML/QuickForm/reset.php', 'HTML_QuickForm_reset'),
86 'checkbox' => array('HTML/QuickForm/checkbox.php', 'HTML_QuickForm_checkbox'),
87 'file' => array('HTML/QuickForm/file.php', 'HTML_QuickForm_file'),
88 'image' => array('HTML/QuickForm/image.php', 'HTML_QuickForm_image'),
89 'password' => array('HTML/QuickForm/password.php', 'HTML_QuickForm_password'),
90 'radio' => array('HTML/QuickForm/radio.php', 'HTML_QuickForm_radio'),
91 'button' => array('HTML/QuickForm/button.php', 'HTML_QuickForm_button'),
92 'submit' => array('HTML/QuickForm/submit.php', 'HTML_QuickForm_submit'),
93 'select' => array('HTML/QuickForm/select.php', 'HTML_QuickForm_select'),
94 'hiddenselect' => array('HTML/QuickForm/hiddenselect.php', 'HTML_QuickForm_hiddenselect'),
95 'text' => array('HTML/QuickForm/text.php', 'HTML_QuickForm_text'),
96 'textarea' => array('HTML/QuickForm/textarea.php', 'HTML_QuickForm_textarea'),
97 'fckeditor' => array('HTML/QuickForm/fckeditor.php', 'HTML_QuickForm_FCKEditor'),
98 'tinymce' => array('HTML/QuickForm/tinymce.php', 'HTML_QuickForm_TinyMCE'),
99 'dojoeditor' => array('HTML/QuickForm/dojoeditor.php', 'HTML_QuickForm_dojoeditor'),
100 'link' => array('HTML/QuickForm/link.php', 'HTML_QuickForm_link'),
101 'advcheckbox' => array('HTML/QuickForm/advcheckbox.php', 'HTML_QuickForm_advcheckbox'),
102 'date' => array('HTML/QuickForm/date.php', 'HTML_QuickForm_date'),
103 'static' => array('HTML/QuickForm/static.php', 'HTML_QuickForm_static'),
104 'header' => array('HTML/QuickForm/header.php', 'HTML_QuickForm_header'),
105 'html' => array('HTML/QuickForm/html.php', 'HTML_QuickForm_html'),
106 'hierselect' => array('HTML/QuickForm/hierselect.php', 'HTML_QuickForm_hierselect'),
107 'autocomplete' => array('HTML/QuickForm/autocomplete.php', 'HTML_QuickForm_autocomplete'),
108 'xbutton' => array('HTML/QuickForm/xbutton.php', 'HTML_QuickForm_xbutton'),
109 'advmultiselect' => array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect'),
110 );
111 }
112
113 function tearDown() {
114 // Truncate the tables
115 $this->quickCleanup(
116 array(
117 'civicrm_group',
118 'civicrm_contact',
119 'civicrm_uf_group',
120 'civicrm_uf_join',
121 'civicrm_uf_match',
122 )
123 );
124 }
125
126 /**
127 * find uf join group id
128 */
129 public function testFindUFGroupId() {
130 $params = array(
131 'module' => 'CiviContribute',
132 'entity_table' => 'civicrm_contribution_page',
133 'entity_id' => 1,
134 'weight' => 1,
135 'uf_group_id' => $this->_ufGroupId,
e6ff1593 136 'is_active' => 1, );
137 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
6a488035
TO
138
139 $searchParams = array(
140 'entity_table' => 'civicrm_contribution_page',
e6ff1593 141 'entity_id' => 1, );
142 $result = $this->callAPISuccess('uf_join', 'get', $searchParams);
6a488035
TO
143
144 foreach ($result['values'] as $key => $value) {
145 $this->assertEquals($value['uf_group_id'], $this->_ufGroupId, 'In line ' . __LINE__);
146 }
147 }
148
149
150 public function testUFJoinEditWrongParamsType() {
151 $params = 'a string';
d0e1eff2 152 $result = $this->callAPIFailure('uf_join', 'create', $params);
6a488035
TO
153 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__);
154 }
155
156 public function testUFJoinEditEmptyParams() {
157 $params = array();
d0e1eff2
CW
158 $result = $this->callAPIFailure('uf_join', 'create', $params);
159 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id', 'In line ' . __LINE__);
6a488035
TO
160 }
161
162 public function testUFJoinEditWithoutUFGroupId() {
163 $params = array(
164 'module' => 'CiviContribute',
165 'entity_table' => 'civicrm_contribution_page',
166 'entity_id' => 1,
167 'weight' => 1,
e6ff1593 168 'is_active' => 1, );
d0e1eff2 169 $result = $this->callAPIFailure('uf_join', 'create', $params);
6a488035
TO
170 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__);
171 }
172
173 /**
174 * create/update uf join
175 */
176 public function testCreateUFJoin() {
177 $params = array(
178 'module' => 'CiviContribute',
179 'entity_table' => 'civicrm_contribution_page',
180 'entity_id' => 1,
181 'weight' => 1,
182 'uf_group_id' => $this->_ufGroupId,
e6ff1593 183 'is_active' => 1, 'sequential' => 1,
6a488035 184 );
e6ff1593 185 $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__);
6a488035
TO
186 $this->assertEquals($ufJoin['values'][0]['module'], $params['module'], 'In line ' . __LINE__);
187 $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__);
188 $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__);
189
190 $params = array(
191 'id' => $ufJoin['id'],
192 'module' => 'CiviContribute',
193 'entity_table' => 'civicrm_contribution_page',
194 'entity_id' => 1,
195 'weight' => 1,
196 'uf_group_id' => $this->_ufGroupId,
e6ff1593 197 'is_active' => 0, 'sequential' => 1,
6a488035 198 );
e6ff1593 199 $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params);
6a488035
TO
200 $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module'], 'In line ' . __LINE__);
201 $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__);
202 $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__);
203 }
204
205
206 public function testFindUFJoinWrongParamsType() {
207 $params = 'a string';
d0e1eff2 208 $result = $this->callAPIFailure('uf_join', 'create', $params);
6a488035
TO
209 $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__);
210 }
211
212 public function testFindUFJoinEmptyParams() {
d0e1eff2
CW
213 $result = $this->callAPIFailure('uf_join', 'create', array());
214 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: module, weight, uf_group_id', 'In line ' . __LINE__);
6a488035
TO
215 }
216
217 public function testFindUFJoinWithoutUFGroupId() {
218 $params = array(
219 'module' => 'CiviContribute',
220 'entity_table' => 'civicrm_contribution_page',
221 'entity_id' => 1,
222 'weight' => 1,
223 'is_active' => 1,
6a488035 224 );
d0e1eff2 225 $result = $this->callAPIFailure('uf_join', 'create', $params);
6a488035
TO
226 $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__);
227 }
228
229 /**
230 * find uf join id
231 */
232 public function testGetUFJoinId() {
233 $params = array(
234 'module' => 'CiviContribute',
235 'entity_table' => 'civicrm_contribution_page',
236 'entity_id' => 1,
237 'weight' => 1,
238 'uf_group_id' => $this->_ufGroupId,
e6ff1593 239 'is_active' => 1, );
6a488035 240
e6ff1593 241 $ufJoin = $this->callAPISuccess('uf_join', 'create', $params);
6a488035
TO
242 $searchParams = array(
243 'entity_table' => 'civicrm_contribution_page',
e6ff1593 244 'entity_id' => 1, 'sequential' => 1,
6a488035
TO
245 );
246
e6ff1593 247 $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__, __FILE__);
6a488035
TO
248 $this->assertEquals($result['values'][0]['module'], $params['module'], 'In line ' . __LINE__);
249 $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__);
250 $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id'], 'In line ' . __LINE__);
251 }
252
253 /**
254 * Test civicrm_activity_create() using example code
255 */
256 function testUFJoinCreateExample() {
257 require_once 'api/v3/examples/UFJoinCreate.php';
258 $result = UF_join_create_example();
259 $expectedResult = UF_join_create_expectedresult();
260 $this->assertEquals($result, $expectedResult);
261 }
262}
263