quickfix for crash if civigrant not enabled and have admin rights
authordemeritcowboy <demeritcowboy@hotmail.com>
Sun, 6 Feb 2022 01:06:48 +0000 (20:06 -0500)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Wed, 9 Feb 2022 16:38:36 +0000 (11:38 -0500)
CRM/Contact/Form/Search.php
CRM/Core/BAO/Mapping.php
tests/phpunit/CRM/Core/InvokeTest.php

index 1345c233094d99becf1c01bd21f1d09aeeaa603b..a87415b5eee66d2df2f7be0fed7635e588c3394c 100644 (file)
@@ -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.
    */
index b9d8c7d19ac4f5856c3d4390b1b8b78eb8157672..9ba5d4ce09e3185a8dcd884751e0cc8fc041c623 100644 (file)
@@ -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') {
index 0aae3e48a55b2372cc67801ca91db974a14b0c2a..74ec765d2123c980a4cafab1ba89ce3e210c2a33 100644 (file)
@@ -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);
+  }
+
 }