3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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.
44 protected function setUp() {
45 $this->_apiversion
= 3;
48 // Insert a row in civicrm_group creating option group
49 // from_email_address group
50 $op = new PHPUnit_Extensions_Database_Operation_Insert();
51 $op->execute($this->_dbconn
,
52 $this->createXMLDataSet(
53 dirname(__FILE__
) . '/dataset/group_admins.xml'
57 // Insert a row in civicrm_group creating option group
58 // from_email_address group
59 $op = new PHPUnit_Extensions_Database_Operation_Insert();
60 $op->execute($this->_dbconn
,
61 $this->createXMLDataSet(
62 dirname(__FILE__
) . '/dataset/group_subscribers.xml'
66 // Insert a row in civicrm_group creating option group
67 // from_email_address group
68 $op = new PHPUnit_Extensions_Database_Operation_Insert();
69 $op->execute($this->_dbconn
,
70 $this->createXMLDataSet(
71 dirname(__FILE__
) . '/dataset/group_nesting.xml'
77 * Tears down the fixture, for example, closes a network connection.
78 * This method is called after a test is executed.
81 protected function tearDown() {
82 // Truncate the tables
86 'civicrm_group_nesting',
95 ///////////////// civicrm_group_nesting_get methods
98 * Test civicrm_group_nesting_get.
100 public function testGet() {
102 'parent_group_id' => 1,
103 'child_group_id' => 2,
106 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__
, __FILE__
);
107 // expected data loaded in setUp
109 1 => array('id' => 1,
110 'child_group_id' => 2,
111 'parent_group_id' => 1,
114 $this->assertEquals($expected, $result['values']);
118 * Test civicrm_group_nesting_get with just one
119 * param (child_group_id).
121 public function testGetWithChildGroupId() {
123 'child_group_id' => 4, );
125 $result = $this->callAPISuccess('group_nesting', 'get', $params);
127 // expected data loaded in setUp
129 3 => array('id' => 3,
130 'child_group_id' => 4,
131 'parent_group_id' => 1,
135 'child_group_id' => 4,
136 'parent_group_id' => 2,
140 $this->assertEquals($expected, $result['values']);
144 * Test civicrm_group_nesting_get with just one
145 * param (parent_group_id).
147 public function testGetWithParentGroupId() {
149 'parent_group_id' => 1, );
151 $result = $this->callAPISuccess('group_nesting', 'get', $params);
153 // expected data loaded in setUp
155 1 => array('id' => 1,
156 'child_group_id' => 2,
157 'parent_group_id' => 1,
161 'child_group_id' => 3,
162 'parent_group_id' => 1,
166 'child_group_id' => 4,
167 'parent_group_id' => 1,
171 $this->assertEquals($expected, $result['values']);
175 * Test civicrm_group_nesting_get for no records results.
176 * Success expected. (these tests are of marginal value as are in syntax conformance,
179 public function testGetEmptyResults() {
181 'parent_group_id' => 1,
182 'child_group_id' => 700,
184 $result = $this->callAPISuccess('group_nesting', 'get', $params);
187 ///////////////// civicrm_group_nesting_create methods
190 * Test civicrm_group_nesting_create.
192 public function testCreate() {
193 // groups id=1 and id=2 loaded in setUp
195 'parent_group_id' => 1,
196 'child_group_id' => 3,
199 $result = $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__
, __FILE__
);
201 // we have 4 group nesting records in the example
202 // data, expecting next number to be the id for newly created
204 $this->assertDBState('CRM_Contact_DAO_GroupNesting', $id, $params);
208 * Test civicrm_group_nesting_create with empty parameter array.
211 public function testCreateWithEmptyParams() {
212 $result = $this->callAPIFailure('group_nesting', 'create', array());
215 ///////////////// civicrm_group_nesting_remove methods
218 * Test civicrm_group_nesting_remove.
220 public function testDelete() {
221 // groups id=1 and id=2 loaded in setUp
223 'parent_group_id' => 1,
224 'child_group_id' => 2, );
226 $result = $this->callAPISuccess('group_nesting', 'get', $getparams);
227 $params = array('id' => $result['id']);
228 $result = $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__
, __FILE__
);
229 $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $getparams));
233 * Test civicrm_group_nesting_remove with empty parameter array.
236 public function testDeleteWithEmptyParams() {
237 $result = $this->callAPIFailure('group_nesting', 'delete', array());