xref: /dokuwiki/_test/tests/Extension/EventTest.php (revision 98640fd3947e9ff996e1c9206b5f845465794486)
1*98640fd3SAndreas Gohr<?php
2*98640fd3SAndreas Gohr
3*98640fd3SAndreas Gohrnamespace dokuwiki\test\Extension;
4*98640fd3SAndreas Gohr
5*98640fd3SAndreas Gohruse dokuwiki\Extension\Event;
6*98640fd3SAndreas Gohr
7*98640fd3SAndreas Gohrclass EventTest extends \DokuWikiTest
8*98640fd3SAndreas Gohr{
9*98640fd3SAndreas Gohr    static public function staticFunc(&$data)
10*98640fd3SAndreas Gohr    {
11*98640fd3SAndreas Gohr        $data['test'] = strtoupper($data['test']);
12*98640fd3SAndreas Gohr    }
13*98640fd3SAndreas Gohr
14*98640fd3SAndreas Gohr    public function dynamicFunc(&$data)
15*98640fd3SAndreas Gohr    {
16*98640fd3SAndreas Gohr        $data['test'] = strtoupper($data['test']);
17*98640fd3SAndreas Gohr    }
18*98640fd3SAndreas Gohr
19*98640fd3SAndreas Gohr    public function testGlobal()
20*98640fd3SAndreas Gohr    {
21*98640fd3SAndreas Gohr        $data = 'test';
22*98640fd3SAndreas Gohr        $result = Event::createAndTrigger('TESTTRIGGER', $data, 'strtoupper');
23*98640fd3SAndreas Gohr        $this->assertEquals('TEST', $result);
24*98640fd3SAndreas Gohr    }
25*98640fd3SAndreas Gohr
26*98640fd3SAndreas Gohr    public function testDynamic()
27*98640fd3SAndreas Gohr    {
28*98640fd3SAndreas Gohr        $data = ['test' => 'test'];
29*98640fd3SAndreas Gohr        Event::createAndTrigger('TESTTRIGGER', $data, [$this, 'dynamicFunc']);
30*98640fd3SAndreas Gohr        $this->assertEquals(['test' => 'TEST'], $data);
31*98640fd3SAndreas Gohr    }
32*98640fd3SAndreas Gohr
33*98640fd3SAndreas Gohr    public function testStatic()
34*98640fd3SAndreas Gohr    {
35*98640fd3SAndreas Gohr        $data = ['test' => 'test'];
36*98640fd3SAndreas Gohr        Event::createAndTrigger('TESTTRIGGER', $data, self::class . '::staticFunc');
37*98640fd3SAndreas Gohr        $this->assertEquals(['test' => 'TEST'], $data);
38*98640fd3SAndreas Gohr
39*98640fd3SAndreas Gohr        $data = ['test' => 'test'];
40*98640fd3SAndreas Gohr        Event::createAndTrigger('TESTTRIGGER', $data, [self::class, 'staticFunc']);
41*98640fd3SAndreas Gohr        $this->assertEquals(['test' => 'TEST'], $data);
42*98640fd3SAndreas Gohr    }
43*98640fd3SAndreas Gohr}
44