CRM-15333 - CRM_Utils_HookTest - Verify that return values are properly merged.
authorTim Otten <totten@civicrm.org>
Fri, 19 Sep 2014 16:22:46 +0000 (12:22 -0400)
committerTim Otten <totten@civicrm.org>
Fri, 19 Sep 2014 16:33:31 +0000 (12:33 -0400)
tests/phpunit/CRM/Utils/HookTest.php

index a9b678b32dd0acfa5a2f69ca3d901a005ea653c6..22c165b346eca266f83616ea9f4e18fa05430b86 100644 (file)
@@ -18,6 +18,8 @@ class CRM_Utils_HookTest extends CiviUnitTestCase {
       'hooktesta',
       'hooktestb',
       'hooktestc',
+      'hooktestd',
+      'hookteste',
     );
     // our goal is to test a helper in CRM_Utils_Hook, but we need a concrete class
     $this->hook = new CRM_Utils_Hook_UnitTests();
@@ -48,6 +50,21 @@ class CRM_Utils_HookTest extends CiviUnitTestCase {
       $this->log
     );
   }
+
+  /**
+   * Verify that the results of runHooks() are correctly merged
+   */
+  function testRunHooks_merge() {
+    $result = $this->hook->runHooks($this->fakeModules, 'civicrm_testRunHooks_merge', 0, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject, CRM_Utils_Hook::$_nullObject);
+    $this->assertEquals(
+      array(
+        'from-module-a1',
+        'from-module-a2',
+        'from-module-e',
+      ),
+      $result
+    );
+  }
 }
 
 /* --- Library of test hook implementations ---- */
@@ -78,3 +95,21 @@ function hooktestb_civicrm_testRunHooks_inner() {
   $test = CRM_Utils_HookTest::$activeTest;
   $test->log[] = 'b-inner';
 }
+
+function hooktesta_civicrm_testRunHooks_merge() {
+  return array('from-module-a1', 'from-module-a2');
+}
+
+// OMIT: function hooktestb_civicrm_testRunHooks_merge
+
+function hooktestc_civicrm_testRunHooks_merge() {
+  return array();
+}
+
+function hooktestd_civicrm_testRunHooks_merge() {
+  return NULL;
+}
+
+function hookteste_civicrm_testRunHooks_merge() {
+  return array('from-module-e');
+}