From 772c924913365ea9be90e667f6d06cdcef3ab4ec Mon Sep 17 00:00:00 2001
From: Michael Hamann <michael@content-space.de>
Date: Sat, 30 Jun 2012 13:37:23 +0200
Subject: [PATCH] Add a test case for nested events, this tests
 8cb3706df5ad54c654bffb76a69ac0ca1006521e

---
 _test/tests/inc/events_nested.test.php | 36 ++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 _test/tests/inc/events_nested.test.php

diff --git a/_test/tests/inc/events_nested.test.php b/_test/tests/inc/events_nested.test.php
new file mode 100644
index 000000000..fe5e395bb
--- /dev/null
+++ b/_test/tests/inc/events_nested.test.php
@@ -0,0 +1,36 @@
+<?php
+
+/**
+ * This tests if event handlers can trigger the same event again.
+ * This is used by plugins that modify cache handling and use metadata
+ * for checking cache validity which triggers another cache use event.
+ */
+class events_nested_test extends DokuWikiTest {
+    function test_nested_events() {
+        global $EVENT_HANDLER;
+        $firstcount = 0;
+        $secondcount = 0;
+
+        $EVENT_HANDLER->register_hook('NESTED_EVENT', 'BEFORE', null,
+            function() use (&$firstcount) {
+                $firstcount++;
+                if ($firstcount == 1) {
+                    $param = array();
+                    trigger_event('NESTED_EVENT', $param);
+                }
+            }
+        );
+
+        $EVENT_HANDLER->register_hook('NESTED_EVENT', 'BEFORE', null,
+            function() use (&$secondcount) {
+                $secondcount++;
+            }
+        );
+
+        $param = array();
+        trigger_event('NESTED_EVENT', $param);
+
+        $this->assertEquals(2, $firstcount);
+        $this->assertEquals(2, $secondcount);
+    }
+}
-- 
GitLab