3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test class for GroupNesting API - civicrm_group_nesting_*
36 class api_v3_GroupNestingTest
extends CiviUnitTestCase
{
37 protected $_apiversion;
40 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
45 protected function setUp() {
46 $this->_apiversion
= 3;
49 // Insert a row in civicrm_group creating option group
50 // from_email_address group
51 $op = new PHPUnit_Extensions_Database_Operation_Insert();
52 $op->execute($this->_dbconn
,
53 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
54 dirname(__FILE__
) . '/dataset/group_admins.xml'
58 // Insert a row in civicrm_group creating option group
59 // from_email_address group
60 $op = new PHPUnit_Extensions_Database_Operation_Insert();
61 $op->execute($this->_dbconn
,
62 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
63 dirname(__FILE__
) . '/dataset/group_subscribers.xml'
67 // Insert a row in civicrm_group creating option group
68 // from_email_address group
69 $op = new PHPUnit_Extensions_Database_Operation_Insert();
70 $op->execute($this->_dbconn
,
71 new PHPUnit_Extensions_Database_DataSet_XMLDataSet(
72 dirname(__FILE__
) . '/dataset/group_nesting.xml'
78 * Tears down the fixture, for example, closes a network connection.
79 * This method is called after a test is executed.
83 protected function tearDown() {
84 // Truncate the tables
88 'civicrm_group_nesting',
97 ///////////////// civicrm_group_nesting_get methods
100 * Test civicrm_group_nesting_get.
102 public function testGet() {
104 'parent_group_id' => 1,
105 'child_group_id' => 2,
108 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__
, __FILE__
);
109 // expected data loaded in setUp
111 1 => array('id' => 1,
112 'child_group_id' => 2,
113 'parent_group_id' => 1,
116 $this->assertEquals($expected, $result['values']);
120 * Test civicrm_group_nesting_get with just one
121 * param (child_group_id).
123 public function testGetWithChildGroupId() {
125 'child_group_id' => 4, );
127 $result = $this->callAPISuccess('group_nesting', 'get', $params);
129 // expected data loaded in setUp
131 3 => array('id' => 3,
132 'child_group_id' => 4,
133 'parent_group_id' => 1,
137 'child_group_id' => 4,
138 'parent_group_id' => 2,
142 $this->assertEquals($expected, $result['values']);
146 * Test civicrm_group_nesting_get with just one
147 * param (parent_group_id).
149 public function testGetWithParentGroupId() {
151 'parent_group_id' => 1, );
153 $result = $this->callAPISuccess('group_nesting', 'get', $params);
155 // expected data loaded in setUp
157 1 => array('id' => 1,
158 'child_group_id' => 2,
159 'parent_group_id' => 1,
163 'child_group_id' => 3,
164 'parent_group_id' => 1,
168 'child_group_id' => 4,
169 'parent_group_id' => 1,
173 $this->assertEquals($expected, $result['values']);
177 * Test civicrm_group_nesting_get for no records results.
178 * Success expected. (these tests are of marginal value as are in syntax conformance,
181 public function testGetEmptyResults() {
183 'parent_group_id' => 1,
184 'child_group_id' => 700,
186 $result = $this->callAPISuccess('group_nesting', 'get', $params);
189 ///////////////// civicrm_group_nesting_create methods
192 * Test civicrm_group_nesting_create.
194 public function testCreate() {
195 // groups id=1 and id=2 loaded in setUp
197 'parent_group_id' => 1,
198 'child_group_id' => 3,
201 $result = $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__
, __FILE__
);
203 // we have 4 group nesting records in the example
204 // data, expecting next number to be the id for newly created
206 $this->assertDBState('CRM_Contact_DAO_GroupNesting', $id, $params);
210 * Test civicrm_group_nesting_create with empty parameter array.
213 public function testCreateWithEmptyParams() {
214 $result = $this->callAPIFailure('group_nesting', 'create', array());
217 ///////////////// civicrm_group_nesting_remove methods
220 * Test civicrm_group_nesting_remove.
222 public function testDelete() {
223 // groups id=1 and id=2 loaded in setUp
225 'parent_group_id' => 1,
226 'child_group_id' => 2, );
228 $result = $this->callAPISuccess('group_nesting', 'get', $getparams);
229 $params = array('id' => $result['id']);
230 $result = $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__
, __FILE__
);
231 $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $getparams));
235 * Test civicrm_group_nesting_remove with empty parameter array.
238 public function testDeleteWithEmptyParams() {
239 $result = $this->callAPIFailure('group_nesting', 'delete', array());