tests/events/ - Add some assertions for 'civi.region.render'
authorTim Otten <totten@civicrm.org>
Sat, 25 Sep 2021 07:28:31 +0000 (00:28 -0700)
committerTim Otten <totten@civicrm.org>
Sat, 25 Sep 2021 19:38:04 +0000 (12:38 -0700)
tests/events/civi_region_render.evch.php [new file with mode: 0644]

diff --git a/tests/events/civi_region_render.evch.php b/tests/events/civi_region_render.evch.php
new file mode 100644 (file)
index 0000000..b374ff6
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+return new class() extends \Civi\Test\EventCheck implements \Civi\Test\HookInterface {
+
+  private $validSnippetTypes = [
+    'callback',
+    'jquery',
+    'markup',
+    'script',
+    'scriptFile',
+    'scriptUrl',
+    'settings',
+    'style',
+    'styleFile',
+    'styleUrl',
+    'template',
+  ];
+
+  private $validRegion = '/^[A-Za-z0-9\\-]+$/';
+
+  /**
+   * Ensure that the hook data is always well-formed.
+   */
+  public function on_civi_region_render(\Civi\Core\Event\GenericHookEvent $e) {
+    $this->assertTrue($e->region instanceof \CRM_Core_Region);
+    /** @var \CRM_Core_Region $region */
+    $region = $e->region;
+    $this->assertRegexp($this->validRegion, $region->_name);
+    foreach ($region->getAll() as $snippet) {
+      $this->assertContains($snippet['type'], $this->validSnippetTypes);
+    }
+  }
+
+};