3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 * Test class for GroupNesting API - civicrm_group_nesting_*
34 class api_v3_GroupNestingTest
extends CiviUnitTestCase
{
35 protected $_apiversion;
38 * Sets up the fixture, for example, opens a network connection.
39 * This method is called before a test is executed.
41 protected function setUp() {
42 $this->_apiversion
= 3;
45 // Insert a row in civicrm_group creating option group
46 // from_email_address group
47 $op = new PHPUnit_Extensions_Database_Operation_Insert();
48 $op->execute($this->_dbconn
,
49 $this->createXMLDataSet(
50 dirname(__FILE__
) . '/dataset/group_admins.xml'
54 // Insert a row in civicrm_group creating option group
55 // from_email_address group
56 $op = new PHPUnit_Extensions_Database_Operation_Insert();
57 $op->execute($this->_dbconn
,
58 $this->createXMLDataSet(
59 dirname(__FILE__
) . '/dataset/group_subscribers.xml'
63 // Insert a row in civicrm_group creating option group
64 // from_email_address group
65 $op = new PHPUnit_Extensions_Database_Operation_Insert();
66 $op->execute($this->_dbconn
,
67 $this->createXMLDataSet(
68 dirname(__FILE__
) . '/dataset/group_nesting.xml'
74 * Tears down the fixture, for example, closes a network connection.
75 * This method is called after a test is executed.
77 protected function tearDown() {
78 // Truncate the tables
82 'civicrm_group_nesting',
91 ///////////////// civicrm_group_nesting_get methods
94 * Test civicrm_group_nesting_get.
96 public function testGet() {
98 'parent_group_id' => 1,
99 'child_group_id' => 2,
102 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__
, __FILE__
);
103 // expected data loaded in setUp
107 'child_group_id' => 2,
108 'parent_group_id' => 1,
112 $this->assertEquals($expected, $result['values']);
116 * Test civicrm_group_nesting_get with just one
117 * param (child_group_id).
119 public function testGetWithChildGroupId() {
121 'child_group_id' => 4,
124 $result = $this->callAPISuccess('group_nesting', 'get', $params);
126 // expected data loaded in setUp
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,
152 $result = $this->callAPISuccess('group_nesting', 'get', $params);
154 // expected data loaded in setUp
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,
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());