3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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;
38 public $_eNoticeCompliant = True;
41 * Sets up the fixture, for example, opens a network connection.
42 * This method is called before a test is executed.
46 protected function setUp() {
47 $this->_apiversion
= 3;
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'
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'
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'
79 * Tears down the fixture, for example, closes a network connection.
80 * This method is called after a test is executed.
84 protected function tearDown() {
85 // Truncate the tables
89 'civicrm_group_nesting',
98 ///////////////// civicrm_group_nesting_get methods
101 * Test civicrm_group_nesting_get.
103 public function testGet() {
105 'parent_group_id' => 1,
106 'child_group_id' => 2,
109 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__
, __FILE__
);
110 // expected data loaded in setUp
112 1 => array('id' => 1,
113 'child_group_id' => 2,
114 'parent_group_id' => 1,
117 $this->assertEquals($expected, $result['values']);
121 * Test civicrm_group_nesting_get with just one
122 * param (child_group_id).
124 public function testGetWithChildGroupId() {
126 'child_group_id' => 4, );
128 $result = $this->callAPISuccess('group_nesting', 'get', $params);
130 // expected data loaded in setUp
132 3 => array('id' => 3,
133 'child_group_id' => 4,
134 'parent_group_id' => 1,
138 'child_group_id' => 4,
139 'parent_group_id' => 2,
143 $this->assertEquals($expected, $result['values']);
147 * Test civicrm_group_nesting_get with just one
148 * param (parent_group_id).
150 public function testGetWithParentGroupId() {
152 'parent_group_id' => 1, );
154 $result = $this->callAPISuccess('group_nesting', 'get', $params);
156 // expected data loaded in setUp
158 1 => array('id' => 1,
159 'child_group_id' => 2,
160 'parent_group_id' => 1,
164 'child_group_id' => 3,
165 'parent_group_id' => 1,
169 'child_group_id' => 4,
170 'parent_group_id' => 1,
174 $this->assertEquals($expected, $result['values']);
178 * Test civicrm_group_nesting_get for no records results.
179 * Success expected. (these tests are of marginal value as are in syntax conformance,
182 public function testGetEmptyResults() {
184 'parent_group_id' => 1,
185 'child_group_id' => 700,
187 $result = $this->callAPISuccess('group_nesting', 'get', $params);
190 ///////////////// civicrm_group_nesting_create methods
193 * Test civicrm_group_nesting_create.
195 public function testCreate() {
196 // groups id=1 and id=2 loaded in setUp
198 'parent_group_id' => 1,
199 'child_group_id' => 3,
202 $result = $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__
, __FILE__
);
204 // we have 4 group nesting records in the example
205 // data, expecting next number to be the id for newly created
207 $this->assertDBState('CRM_Contact_DAO_GroupNesting', $id, $params);
211 * Test civicrm_group_nesting_create with empty parameter array.
214 public function testCreateWithEmptyParams() {
215 $result = $this->callAPIFailure('group_nesting', 'create', array());
218 ///////////////// civicrm_group_nesting_remove methods
221 * Test civicrm_group_nesting_remove.
223 public function testDelete() {
224 // groups id=1 and id=2 loaded in setUp
226 'parent_group_id' => 1,
227 'child_group_id' => 2, );
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));
236 * Test civicrm_group_nesting_remove with empty parameter array.
239 public function testDeleteWithEmptyParams() {
240 $result = $this->callAPIFailure('group_nesting', 'delete', array());