xref: /dokuwiki/_test/tests/inc/events_nested.test.php (revision 8d6ec7dd27c536bbaf7d7c0c4f5f99ae20860f3b)
1<?php
2
3/**
4 * This tests if event handlers can trigger the same event again.
5 * This is used by plugins that modify cache handling and use metadata
6 * for checking cache validity which triggers another cache use event.
7 */
8class events_nested_test extends DokuWikiTest {
9    function test_nested_events() {
10        global $EVENT_HANDLER;
11        $firstcount = 0;
12        $secondcount = 0;
13
14        $EVENT_HANDLER->register_hook('NESTED_EVENT', 'BEFORE', null,
15            function() use (&$firstcount) {
16                $firstcount++;
17                if ($firstcount == 1) {
18                    $param = array();
19                    trigger_event('NESTED_EVENT', $param);
20                }
21            }
22        );
23
24        $EVENT_HANDLER->register_hook('NESTED_EVENT', 'BEFORE', null,
25            function() use (&$secondcount) {
26                $secondcount++;
27            }
28        );
29
30        $param = array();
31        trigger_event('NESTED_EVENT', $param);
32
33        $this->assertEquals(2, $firstcount);
34        $this->assertEquals(2, $secondcount);
35    }
36}
37