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