From a725865da460020ddb9cd1ce82974a5b985702a6 Mon Sep 17 00:00:00 2001 From: eileen <emcnaughton@wikimedia.org> Date: Thu, 17 Sep 2020 12:41:59 +1200 Subject: [PATCH] dev/core#2039 Fix OpenID::add to ensure is_primary is set In my efforts to determine the the non-performant line of code that makes sure IM is set is not required I edited tests to track down when is_primary is not correct & determined it is missing from the add function - same as https://github.com/civicrm/civicrm-core/pull/18489 for IM --- CRM/Core/BAO/OpenID.php | 8 ++++++++ tests/phpunit/api/v3/OpenIDTest.php | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/CRM/Core/BAO/OpenID.php b/CRM/Core/BAO/OpenID.php index 34326a75625..db14b57eec4 100644 --- a/CRM/Core/BAO/OpenID.php +++ b/CRM/Core/BAO/OpenID.php @@ -24,9 +24,16 @@ class CRM_Core_BAO_OpenID extends CRM_Core_DAO_OpenID { * Create or update OpenID record. * * @param array $params + * * @return CRM_Core_DAO_OpenID + * + * @throws \API_Exception + * @throws \CRM_Core_Exception */ public static function add($params) { + if (empty($params['id']) || is_numeric($params['is_primary'] ?? NULL)) { + CRM_Core_BAO_Block::handlePrimary($params, __CLASS__); + } return self::writeRecord($params); } @@ -38,6 +45,7 @@ class CRM_Core_BAO_OpenID extends CRM_Core_DAO_OpenID { * Input parameters to find object. * * @return mixed + * @throws \CRM_Core_Exception */ public static function &getValues($entityBlock) { return CRM_Core_BAO_Block::getValues('openid', $entityBlock); diff --git a/tests/phpunit/api/v3/OpenIDTest.php b/tests/phpunit/api/v3/OpenIDTest.php index a3025e805bc..5c554ab006d 100644 --- a/tests/phpunit/api/v3/OpenIDTest.php +++ b/tests/phpunit/api/v3/OpenIDTest.php @@ -18,6 +18,13 @@ */ class api_v3_OpenIDTest extends CiviUnitTestCase { + /** + * Should location types be checked to ensure primary addresses are correctly assigned after each test. + * + * @var bool + */ + protected $isLocationTypesOnPostAssert = TRUE; + protected $_params; protected $id; protected $_entity; -- GitLab