From 52202a203b7fa4f11615d9e13527a1136074797e Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 13 Jul 2016 17:18:14 +1000 Subject: [PATCH] Switch to throwing errrors rather than soft validation --- CRM/Contact/BAO/Group.php | 10 +++------- tests/phpunit/api/v3/GroupTest.php | 4 ++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index def29b8dbc..f55505fd72 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -387,15 +387,11 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { if (isset($params['parents'])) { if (is_array($params['parents'])) { foreach ($params['parents'] as $parent => $dc) { - if (!CRM_Utils_Type::validate($parent, 'Integer', FALSE)) { - unset($params['parents'][$parent]); - } + CRM_Utils_Type::validate($parent, 'Integer'); } } else { - if (!CRM_Utils_Type::validate($params['parents'], 'Integer', FALSE)) { - unset($params['parents']); - } + CRM_Utils_Type::validate($params['parents'], 'Integer'); } } $group = new CRM_Contact_BAO_Group(); @@ -453,7 +449,7 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { if (!empty($params['parents'])) { foreach ($params['parents'] as $parentId => $dnc) { - if (CRM_Utils_Type::validate($parentId, 'Integer', FALSE)) { + if (CRM_Utils_Type::validate($parentId, 'Integer')) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } diff --git a/tests/phpunit/api/v3/GroupTest.php b/tests/phpunit/api/v3/GroupTest.php index 77bc349636..192c345541 100644 --- a/tests/phpunit/api/v3/GroupTest.php +++ b/tests/phpunit/api/v3/GroupTest.php @@ -180,6 +180,8 @@ class api_v3_GroupTest extends CiviUnitTestCase { 'is_active' => 1, 'parents' => "(SELECT api_key FROM civicrm_contact where id = 1)", ); + $this->callAPIFailure('group', 'create', $params); + unset($params['parents']); $this->callAPISuccess('group', 'create', $params); $group1 = $this->callAPISuccess('group', 'get', array( 'title' => 'Test illegal Group', @@ -190,6 +192,8 @@ class api_v3_GroupTest extends CiviUnitTestCase { $params['parents'] = array(); $params['parents'][$this->_groupID] = 'test Group'; $params['parents']["(SELECT api_key FROM civicrm_contact where id = 1)"] = "Test"; + $group2 = $this->callAPIFailure('group', 'create', $params); + unset($params['parents']["(SELECT api_key FROM civicrm_contact where id = 1)"]); $group2 = $this->callAPISuccess('group', 'create', $params); $this->assertEquals(count($group2['values'][$group2['id']]['parents']), 1); } -- 2.25.1