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.
43 protected function setUp() {
44 $this->_apiversion
= 3;
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'
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'
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'
76 * Tears down the fixture, for example, closes a network connection.
77 * This method is called after a test is executed.
79 protected function tearDown() {
80 // Truncate the tables
84 'civicrm_group_nesting',
93 ///////////////// civicrm_group_nesting_get methods
96 * Test civicrm_group_nesting_get.
98 public function testGet() {
100 'parent_group_id' => 1,
101 'child_group_id' => 2,
104 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__
, __FILE__
);
105 // expected data loaded in setUp
109 'child_group_id' => 2,
110 '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,
126 $result = $this->callAPISuccess('group_nesting', 'get', $params);
128 // expected data loaded in setUp
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,
154 $result = $this->callAPISuccess('group_nesting', 'get', $params);
156 // expected data loaded in setUp
160 'child_group_id' => 2,
161 'parent_group_id' => 1,
165 'child_group_id' => 3,
166 'parent_group_id' => 1,
170 'child_group_id' => 4,
171 'parent_group_id' => 1,
175 $this->assertEquals($expected, $result['values']);
179 * Test civicrm_group_nesting_get for no records results.
180 * Success expected. (these tests are of marginal value as are in syntax conformance,
183 public function testGetEmptyResults() {
185 'parent_group_id' => 1,
186 'child_group_id' => 700,
188 $result = $this->callAPISuccess('group_nesting', 'get', $params);
191 ///////////////// civicrm_group_nesting_create methods
194 * Test civicrm_group_nesting_create.
196 public function testCreate() {
197 // groups id=1 and id=2 loaded in setUp
199 'parent_group_id' => 1,
200 'child_group_id' => 3,
203 $result = $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__
, __FILE__
);
205 // we have 4 group nesting records in the example
206 // data, expecting next number to be the id for newly created
208 $this->assertDBState('CRM_Contact_DAO_GroupNesting', $id, $params);
212 * Test civicrm_group_nesting_create with empty parameter array.
215 public function testCreateWithEmptyParams() {
216 $result = $this->callAPIFailure('group_nesting', 'create', array());
219 ///////////////// civicrm_group_nesting_remove methods
222 * Test civicrm_group_nesting_remove.
224 public function testDelete() {
225 // groups id=1 and id=2 loaded in setUp
227 'parent_group_id' => 1,
228 'child_group_id' => 2,
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));
238 * Test civicrm_group_nesting_remove with empty parameter array.
241 public function testDeleteWithEmptyParams() {
242 $result = $this->callAPIFailure('group_nesting', 'delete', array());