commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / api / v3 / GroupNestingTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
30
31 /**
32 * Test class for GroupNesting API - civicrm_group_nesting_*
33 *
34 * @package CiviCRM
35 */
36 class api_v3_GroupNestingTest extends CiviUnitTestCase {
37 protected $_apiversion;
38
39 /**
40 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
42 */
43 protected function setUp() {
44 $this->_apiversion = 3;
45 parent::setUp();
46
47 // Insert a row in civicrm_group creating option group
48 // from_email_address group
49 $op = new PHPUnit_Extensions_Database_Operation_Insert();
50 $op->execute($this->_dbconn,
51 $this->createXMLDataSet(
52 dirname(__FILE__) . '/dataset/group_admins.xml'
53 )
54 );
55
56 // Insert a row in civicrm_group creating option group
57 // from_email_address group
58 $op = new PHPUnit_Extensions_Database_Operation_Insert();
59 $op->execute($this->_dbconn,
60 $this->createXMLDataSet(
61 dirname(__FILE__) . '/dataset/group_subscribers.xml'
62 )
63 );
64
65 // Insert a row in civicrm_group creating option group
66 // from_email_address group
67 $op = new PHPUnit_Extensions_Database_Operation_Insert();
68 $op->execute($this->_dbconn,
69 $this->createXMLDataSet(
70 dirname(__FILE__) . '/dataset/group_nesting.xml'
71 )
72 );
73 }
74
75 /**
76 * Tears down the fixture, for example, closes a network connection.
77 * This method is called after a test is executed.
78 */
79 protected function tearDown() {
80 // Truncate the tables
81 $this->quickCleanup(
82 array(
83 'civicrm_group',
84 'civicrm_group_nesting',
85 'civicrm_contact',
86 'civicrm_uf_group',
87 'civicrm_uf_join',
88 'civicrm_uf_match',
89 )
90 );
91 }
92
93 ///////////////// civicrm_group_nesting_get methods
94
95 /**
96 * Test civicrm_group_nesting_get.
97 */
98 public function testGet() {
99 $params = array(
100 'parent_group_id' => 1,
101 'child_group_id' => 2,
102 );
103
104 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__, __FILE__);
105 // expected data loaded in setUp
106 $expected = array(
107 1 => array(
108 'id' => 1,
109 'child_group_id' => 2,
110 'parent_group_id' => 1,
111 ),
112 );
113
114 $this->assertEquals($expected, $result['values']);
115 }
116
117 /**
118 * Test civicrm_group_nesting_get with just one
119 * param (child_group_id).
120 */
121 public function testGetWithChildGroupId() {
122 $params = array(
123 'child_group_id' => 4,
124 );
125
126 $result = $this->callAPISuccess('group_nesting', 'get', $params);
127
128 // expected data loaded in setUp
129 $expected = array(
130 3 => array(
131 'id' => 3,
132 'child_group_id' => 4,
133 'parent_group_id' => 1,
134 ),
135 4 => array(
136 'id' => 4,
137 'child_group_id' => 4,
138 'parent_group_id' => 2,
139 ),
140 );
141
142 $this->assertEquals($expected, $result['values']);
143 }
144
145 /**
146 * Test civicrm_group_nesting_get with just one
147 * param (parent_group_id).
148 */
149 public function testGetWithParentGroupId() {
150 $params = array(
151 'parent_group_id' => 1,
152 );
153
154 $result = $this->callAPISuccess('group_nesting', 'get', $params);
155
156 // expected data loaded in setUp
157 $expected = array(
158 1 => array(
159 'id' => 1,
160 'child_group_id' => 2,
161 'parent_group_id' => 1,
162 ),
163 2 => array(
164 'id' => 2,
165 'child_group_id' => 3,
166 'parent_group_id' => 1,
167 ),
168 3 => array(
169 'id' => 3,
170 'child_group_id' => 4,
171 'parent_group_id' => 1,
172 ),
173 );
174
175 $this->assertEquals($expected, $result['values']);
176 }
177
178 /**
179 * Test civicrm_group_nesting_get for no records results.
180 * Success expected. (these tests are of marginal value as are in syntax conformance,
181 * don't copy & paste
182 */
183 public function testGetEmptyResults() {
184 $params = array(
185 'parent_group_id' => 1,
186 'child_group_id' => 700,
187 );
188 $result = $this->callAPISuccess('group_nesting', 'get', $params);
189 }
190
191 ///////////////// civicrm_group_nesting_create methods
192
193 /**
194 * Test civicrm_group_nesting_create.
195 */
196 public function testCreate() {
197 // groups id=1 and id=2 loaded in setUp
198 $params = array(
199 'parent_group_id' => 1,
200 'child_group_id' => 3,
201 );
202
203 $result = $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__, __FILE__);
204
205 // we have 4 group nesting records in the example
206 // data, expecting next number to be the id for newly created
207 $id = 5;
208 $this->assertDBState('CRM_Contact_DAO_GroupNesting', $id, $params);
209 }
210
211 /**
212 * Test civicrm_group_nesting_create with empty parameter array.
213 * Error expected.
214 */
215 public function testCreateWithEmptyParams() {
216 $result = $this->callAPIFailure('group_nesting', 'create', array());
217 }
218
219 ///////////////// civicrm_group_nesting_remove methods
220
221 /**
222 * Test civicrm_group_nesting_remove.
223 */
224 public function testDelete() {
225 // groups id=1 and id=2 loaded in setUp
226 $getparams = array(
227 'parent_group_id' => 1,
228 'child_group_id' => 2,
229 );
230
231 $result = $this->callAPISuccess('group_nesting', 'get', $getparams);
232 $params = array('id' => $result['id']);
233 $result = $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__, __FILE__);
234 $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $getparams));
235 }
236
237 /**
238 * Test civicrm_group_nesting_remove with empty parameter array.
239 * Error expected.
240 */
241 public function testDeleteWithEmptyParams() {
242 $result = $this->callAPIFailure('group_nesting', 'delete', array());
243 }
244
245 }