From ec7846f5be0e4b875725281feb939d5f48113579 Mon Sep 17 00:00:00 2001 From: jitendrapurohit Date: Wed, 10 Aug 2016 18:49:24 +0530 Subject: [PATCH] CRM-19209 - Fix create group without selecting parent --- CRM/Contact/BAO/Group.php | 2 +- tests/phpunit/api/v3/GroupTest.php | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 5257b5e742..b2b689d238 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -384,7 +384,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { // CRM-19068. // Validate parents parameter when creating group. - if (isset($params['parents'])) { + if (!empty($params['parents'])) { if (is_array($params['parents'])) { foreach ($params['parents'] as $parent => $dc) { CRM_Utils_Type::validate($parent, 'Integer'); diff --git a/tests/phpunit/api/v3/GroupTest.php b/tests/phpunit/api/v3/GroupTest.php index 192c345541..75aaf8fb0e 100644 --- a/tests/phpunit/api/v3/GroupTest.php +++ b/tests/phpunit/api/v3/GroupTest.php @@ -128,14 +128,16 @@ class api_v3_GroupTest extends CiviUnitTestCase { } /** - * Test Group create with Group Type + * Test Group create with Group Type and Parent */ - public function testgroupCreateWithGroupType() { + public function testGroupCreateWithTypeAndParent() { $params = array( 'name' => 'Test Group type', 'title' => 'Test Group Type', 'description' => 'Test Group with Group Type', 'is_active' => 1, + //check for empty parent + 'parents' => "", 'visibility' => 'Public Pages', 'group_type' => array(1, 2), ); @@ -144,14 +146,21 @@ class api_v3_GroupTest extends CiviUnitTestCase { $group = $result['values'][$result['id']]; $this->assertEquals($group['name'], "Test Group type"); $this->assertEquals($group['is_active'], 1); + $this->assertEquals($group['parents'], ""); $this->assertEquals($group['group_type'], $params['group_type']); - $this->groupDelete($result['id']); - //assert single value for group_type - $params['group_type'] = 2; + //assert single value for group_type and parent + $params = array_merge($params, array( + 'name' => 'Test Group 2', + 'title' => 'Test Group 2', + 'group_type' => 2, + 'parents' => $result['id'], + ) + ); $result = $this->callAPISuccess('Group', 'create', $params); $group = $result["values"][$result['id']]; $this->assertEquals($group['group_type'], array($params['group_type'])); + $this->assertEquals($group['parents'], $params['parents']); } public function testGetNonExistingGroup() { -- 2.25.1