Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
31 | require_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 | */ | |
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; | |
b7c9bc4c | 45 | |
6a488035 TO |
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, | |
bbfd46a5 | 62 | $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/uf_group_test.xml') |
6a488035 | 63 | ); |
6a488035 TO |
64 | } |
65 | ||
66 | function tearDown() { | |
67 | // Truncate the tables | |
68 | $this->quickCleanup( | |
69 | array( | |
70 | 'civicrm_group', | |
71 | 'civicrm_contact', | |
72 | 'civicrm_uf_group', | |
73 | 'civicrm_uf_join', | |
74 | 'civicrm_uf_match', | |
75 | ) | |
76 | ); | |
77 | } | |
78 | ||
79 | /** | |
100fef9d | 80 | * Find uf join group id |
6a488035 TO |
81 | */ |
82 | public function testFindUFGroupId() { | |
83 | $params = array( | |
84 | 'module' => 'CiviContribute', | |
85 | 'entity_table' => 'civicrm_contribution_page', | |
86 | 'entity_id' => 1, | |
87 | 'weight' => 1, | |
88 | 'uf_group_id' => $this->_ufGroupId, | |
e6ff1593 | 89 | 'is_active' => 1, ); |
90 | $ufJoin = $this->callAPISuccess('uf_join', 'create', $params); | |
6a488035 TO |
91 | |
92 | $searchParams = array( | |
93 | 'entity_table' => 'civicrm_contribution_page', | |
e6ff1593 | 94 | 'entity_id' => 1, ); |
95 | $result = $this->callAPISuccess('uf_join', 'get', $searchParams); | |
6a488035 TO |
96 | |
97 | foreach ($result['values'] as $key => $value) { | |
98 | $this->assertEquals($value['uf_group_id'], $this->_ufGroupId, 'In line ' . __LINE__); | |
99 | } | |
100 | } | |
101 | ||
102 | ||
103 | public function testUFJoinEditWrongParamsType() { | |
104 | $params = 'a string'; | |
d0e1eff2 | 105 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
6a488035 TO |
106 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); |
107 | } | |
108 | ||
109 | public function testUFJoinEditEmptyParams() { | |
110 | $params = array(); | |
d0e1eff2 CW |
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__); | |
6a488035 TO |
113 | } |
114 | ||
115 | public function testUFJoinEditWithoutUFGroupId() { | |
116 | $params = array( | |
117 | 'module' => 'CiviContribute', | |
118 | 'entity_table' => 'civicrm_contribution_page', | |
119 | 'entity_id' => 1, | |
120 | 'weight' => 1, | |
e6ff1593 | 121 | 'is_active' => 1, ); |
d0e1eff2 | 122 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
6a488035 TO |
123 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__); |
124 | } | |
125 | ||
126 | /** | |
100fef9d | 127 | * Create/update uf join |
6a488035 TO |
128 | */ |
129 | public function testCreateUFJoin() { | |
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, 'sequential' => 1, |
6a488035 | 137 | ); |
e6ff1593 | 138 | $ufJoin = $this->callAPIAndDocument('uf_join', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
139 | $this->assertEquals($ufJoin['values'][0]['module'], $params['module'], 'In line ' . __LINE__); |
140 | $this->assertEquals($ufJoin['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__); | |
141 | $this->assertEquals($ufJoin['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__); | |
142 | ||
143 | $params = array( | |
144 | 'id' => $ufJoin['id'], | |
145 | 'module' => 'CiviContribute', | |
146 | 'entity_table' => 'civicrm_contribution_page', | |
147 | 'entity_id' => 1, | |
148 | 'weight' => 1, | |
149 | 'uf_group_id' => $this->_ufGroupId, | |
e6ff1593 | 150 | 'is_active' => 0, 'sequential' => 1, |
6a488035 | 151 | ); |
e6ff1593 | 152 | $ufJoinUpdated = $this->callAPISuccess('uf_join', 'create', $params); |
6a488035 TO |
153 | $this->assertEquals($ufJoinUpdated['values'][0]['module'], $params['module'], 'In line ' . __LINE__); |
154 | $this->assertEquals($ufJoinUpdated['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__); | |
155 | $this->assertEquals($ufJoinUpdated['values'][0]['is_active'], $params['is_active'], 'In line ' . __LINE__); | |
156 | } | |
157 | ||
158 | ||
159 | public function testFindUFJoinWrongParamsType() { | |
160 | $params = 'a string'; | |
d0e1eff2 | 161 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
6a488035 TO |
162 | $this->assertEquals($result['error_message'], 'Input variable `params` is not an array', 'In line ' . __LINE__); |
163 | } | |
164 | ||
165 | public function testFindUFJoinEmptyParams() { | |
d0e1eff2 CW |
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', 'In line ' . __LINE__); | |
6a488035 TO |
168 | } |
169 | ||
170 | public function testFindUFJoinWithoutUFGroupId() { | |
171 | $params = array( | |
172 | 'module' => 'CiviContribute', | |
173 | 'entity_table' => 'civicrm_contribution_page', | |
174 | 'entity_id' => 1, | |
175 | 'weight' => 1, | |
176 | 'is_active' => 1, | |
6a488035 | 177 | ); |
d0e1eff2 | 178 | $result = $this->callAPIFailure('uf_join', 'create', $params); |
6a488035 TO |
179 | $this->assertEquals($result['error_message'], 'Mandatory key(s) missing from params array: uf_group_id', 'In line ' . __LINE__); |
180 | } | |
181 | ||
182 | /** | |
100fef9d | 183 | * Find uf join id |
6a488035 TO |
184 | */ |
185 | public function testGetUFJoinId() { | |
186 | $params = array( | |
187 | 'module' => 'CiviContribute', | |
188 | 'entity_table' => 'civicrm_contribution_page', | |
189 | 'entity_id' => 1, | |
190 | 'weight' => 1, | |
191 | 'uf_group_id' => $this->_ufGroupId, | |
e6ff1593 | 192 | 'is_active' => 1, ); |
6a488035 | 193 | |
e6ff1593 | 194 | $ufJoin = $this->callAPISuccess('uf_join', 'create', $params); |
6a488035 TO |
195 | $searchParams = array( |
196 | 'entity_table' => 'civicrm_contribution_page', | |
e6ff1593 | 197 | 'entity_id' => 1, 'sequential' => 1, |
6a488035 TO |
198 | ); |
199 | ||
e6ff1593 | 200 | $result = $this->callAPIAndDocument('uf_join', 'get', $searchParams, __FUNCTION__, __FILE__); |
6a488035 TO |
201 | $this->assertEquals($result['values'][0]['module'], $params['module'], 'In line ' . __LINE__); |
202 | $this->assertEquals($result['values'][0]['uf_group_id'], $params['uf_group_id'], 'In line ' . __LINE__); | |
203 | $this->assertEquals($result['values'][0]['entity_id'], $params['entity_id'], 'In line ' . __LINE__); | |
204 | } | |
205 | ||
206 | /** | |
207 | * Test civicrm_activity_create() using example code | |
208 | */ | |
209 | function testUFJoinCreateExample() { | |
3ec6e38d | 210 | require_once 'api/v3/examples/UFJoin/Create.php'; |
6a488035 TO |
211 | $result = UF_join_create_example(); |
212 | $expectedResult = UF_join_create_expectedresult(); | |
213 | $this->assertEquals($result, $expectedResult); | |
214 | } | |
215 | } | |
216 |