hook_civicrm_links - Add exception for `pledge.selector.row` (`is_active`)
authorTim Otten <totten@civicrm.org>
Tue, 3 Oct 2023 04:34:21 +0000 (21:34 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 3 Oct 2023 04:44:59 +0000 (21:44 -0700)
tests/events/hook_civicrm_links.evch.php

index f3a40c1c91378ff84c237122e33ec8e21cfa54a7..cd1329fee0ef38d992907dca0f676d0a81eb821f 100644 (file)
@@ -5,6 +5,12 @@ use Civi\Test\HookInterface;
 
 return new class() extends EventCheck implements HookInterface {
 
+  // There are several properties named "$grandfatherdXyz". These mark itmes which
+  // pass through hook_civicrm_links but deviate from the plain interpretation of the docs.
+  // Auditing or cleaning each would be its own separate project. Please feel free to
+  // do that audit and figure how to normalize it. But for now, the goal of this file is
+  // to limit the chaos - and prevent new/un-documented deviations.
+
   /**
    * These are $objectNames that deviate from the normal "CamelCase" convention.
    * They're allowed for backward-compatibility.
@@ -31,6 +37,16 @@ return new class() extends EventCheck implements HookInterface {
     'basic.CRM_Core_BAO_MessageTemplate.page::CRM_Core_BAO_MessageTemplate',
   ];
 
+  /**
+   * These variants have anomalous keys that are not documented and do not
+   * appear in most flavors of "hook_civicrm_links".
+   *
+   * @var \string[][]
+   */
+  protected $grandfatheredInvalidKeys = [
+    'pledge.selector.row' => ['is_active'],
+  ];
+
   /**
    * These variants have majorly deviant data in $links.
    * They are protected by pre-existing unit-tests.
@@ -110,9 +126,12 @@ return new class() extends EventCheck implements HookInterface {
         $this->assertTrue((bool) preg_match(';^fa-[-a-z0-9]+$;', $link['icon']), "$msg: Icon ({$link['icon']}) should be FontAwesome icon class");
       }
 
-      $expectKeys = ['name', 'url', 'qs', 'title', 'extra', 'bit', 'ref', 'class', 'weight', 'accessKey', 'icon'];
+      $expectKeys = array_merge(
+        ['name', 'url', 'qs', 'title', 'extra', 'bit', 'ref', 'class', 'weight', 'accessKey', 'icon'],
+        $this->grandfatheredInvalidKeys[$op] ?? []
+      );
       $extraKeys = array_diff(array_keys($link), $expectKeys);
-      $this->assertEquals([], $extraKeys, "$msg: Link has unrecognized keys: " . json_encode($extraKeys));
+      $this->assertEquals([], $extraKeys, "$msg: Link has unrecognized keys: " . json_encode(array_values($extraKeys)));
     }
   }