From d128501c04aa7aa23258addaf8fa03f620870cb0 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Thu, 26 Apr 2018 17:15:38 +0100 Subject: [PATCH] dev/core#81 (NFC) Fix warnings in custom group create --- CRM/Core/BAO/CustomGroup.php | 32 ++++++++++++------------ tests/phpunit/api/v3/CustomGroupTest.php | 13 ++++++++++ 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 9093fc3a10a6..bb5d77df17a9 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -60,37 +60,37 @@ public static function create(&$params) { $group->title = $params['title']; } - if (in_array($params['extends'][0], - array( - 'ParticipantRole', - 'ParticipantEventName', - 'ParticipantEventType', - ) - )) { + $extends = CRM_Utils_Array::value('extends', $params, []); + $extendsEntity = CRM_Utils_Array::value(0, $extends); + + $participantEntities = array( + 'ParticipantRole', + 'ParticipantEventName', + 'ParticipantEventType', + ); + + if (in_array($extendsEntity, $participantEntities)) { $group->extends = 'Participant'; } else { - $group->extends = $params['extends'][0]; + $group->extends = $extendsEntity; } $group->extends_entity_column_id = 'null'; - if ( - $params['extends'][0] == 'ParticipantRole' || - $params['extends'][0] == 'ParticipantEventName' || - $params['extends'][0] == 'ParticipantEventType' + if (in_array($extendsEntity, $participantEntities) ) { - $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $params['extends'][0], 'value', 'name'); + $group->extends_entity_column_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $extendsEntity, 'value', 'name'); } //this is format when form get submit. - $extendsChildType = CRM_Utils_Array::value(1, $params['extends']); + $extendsChildType = CRM_Utils_Array::value(1, $extends); //lets allow user to pass direct child type value, CRM-6893 if (!empty($params['extends_entity_column_value'])) { $extendsChildType = $params['extends_entity_column_value']; } if (!CRM_Utils_System::isNull($extendsChildType)) { $extendsChildType = implode(CRM_Core_DAO::VALUE_SEPARATOR, $extendsChildType); - if (CRM_Utils_Array::value(0, $params['extends']) == 'Relationship') { + if (CRM_Utils_Array::value(0, $extends) == 'Relationship') { $extendsChildType = str_replace(array('_a_b', '_b_a'), array( '', '', @@ -211,7 +211,7 @@ public static function create(&$params) { $params['id'], 'table_name' ); - CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($params['extends'][0])); + CRM_Core_BAO_SchemaHandler::changeFKConstraint($table, self::mapTableName($extendsEntity)); } $transaction->commit(); diff --git a/tests/phpunit/api/v3/CustomGroupTest.php b/tests/phpunit/api/v3/CustomGroupTest.php index d2611e1fc011..f5b8d570263f 100644 --- a/tests/phpunit/api/v3/CustomGroupTest.php +++ b/tests/phpunit/api/v3/CustomGroupTest.php @@ -373,4 +373,17 @@ public function testGetCustomGroupSuccess() { } } + public function testUpdateCustomGroup() { + $customGroup = $this->customGroupCreate(); + $customGroupId = $customGroup['id']; + + //update is_active + $params = ['id' => $customGroupId, 'is_active' => 0]; + $result = $this->callAPISuccess('CustomGroup', 'create', $params); + $result = array_shift($result['values']); + + $this->assertEquals(0, $result['is_active']); + $this->customGroupDelete($customGroupId); + } + }