From 5dcfb8ef02b9e43c02bdc95ee4447050935f245c Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Sat, 5 Feb 2022 20:06:48 -0500 Subject: [PATCH] quickfix for crash if civigrant not enabled and have admin rights --- CRM/Contact/Form/Search.php | 8 ++++++++ CRM/Core/BAO/Mapping.php | 2 +- tests/phpunit/CRM/Core/InvokeTest.php | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 1345c23309..a87415b5ee 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -148,6 +148,14 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search { protected $_openedPanes = []; + public function __construct($state = NULL, $action = CRM_Core_Action::NONE, $method = 'post', $name = NULL) { + parent::__construct($state, $action, $method, $name); + // Because this is a static variable, reset it in case it got changed elsewhere. + // Should only come up during unit tests. + // Note the only subclass that seems to set this does it in preprocess (custom searches) + self::$_selectorName = 'CRM_Contact_Selector'; + } + /** * Explicitly declare the entity api name. */ diff --git a/CRM/Core/BAO/Mapping.php b/CRM/Core/BAO/Mapping.php index b9d8c7d19a..9ba5d4ce09 100644 --- a/CRM/Core/BAO/Mapping.php +++ b/CRM/Core/BAO/Mapping.php @@ -760,7 +760,7 @@ class CRM_Core_BAO_Mapping extends CRM_Core_DAO_Mapping implements \Civi\Test\Ho } } if (($mappingType == 'Search Builder') || ($exportMode == CRM_Export_Form_Select::GRANT_EXPORT)) { - if (CRM_Core_Permission::check('access CiviGrant')) { + if (method_exists('CRM_Grant_BAO_Grant', 'exportableFields') && CRM_Core_Permission::check('access CiviGrant')) { $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields(); unset($fields['Grant']['grant_contact_id']); if ($mappingType == 'Search Builder') { diff --git a/tests/phpunit/CRM/Core/InvokeTest.php b/tests/phpunit/CRM/Core/InvokeTest.php index 0aae3e48a5..74ec765d21 100644 --- a/tests/phpunit/CRM/Core/InvokeTest.php +++ b/tests/phpunit/CRM/Core/InvokeTest.php @@ -51,4 +51,18 @@ class CRM_Core_InvokeTest extends CiviUnitTestCase { ob_end_clean(); } + public function testOpeningSearchBuilder(): void { + $_SERVER['REQUEST_URI'] = 'civicrm/contact/search/builder?reset=1'; + $_GET['q'] = 'civicrm/contact/search/builder'; + $_GET['reset'] = 1; + + $item = CRM_Core_Invoke::getItem([$_GET['q']]); + ob_start(); + CRM_Core_Invoke::runItem($item); + $contents = ob_get_clean(); + + unset($_GET['reset']); + $this->assertRegExp('/form.+id="Builder" class="CRM_Contact_Form_Search_Builder/', $contents); + } + } -- 2.25.1