File: PluginApi.php

package info (click to toggle)
roundcube 1.6.13%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,888 kB
  • sloc: javascript: 195,591; php: 76,917; sql: 3,150; sh: 2,882; pascal: 1,079; makefile: 234; xml: 93; perl: 73; ansic: 48; python: 21
file content (61 lines) | stat: -rw-r--r-- 1,378 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace Roundcube\Tests\Framework;

use PHPUnit\Framework\TestCase;

/**
 * Test class to test rcube_plugin_api class
 */
class Framework_PluginApi extends TestCase
{
    /**
     * Test get_info()
     */
    function test_get_info()
    {
        $api = \rcube_plugin_api::get_instance();

        $info = $api->get_info('acl');

        $this->assertSame('roundcube', $info['vendor']);
        $this->assertSame('acl', $info['name']);
        $this->assertSame([], $info['require']);
        $this->assertSame('GPL-3.0+', $info['license']);
    }

    /**
     * Test hooks registration, execution and unregistration
     */
    function test_hooks()
    {
        $api = \rcube_plugin_api::get_instance();

        $var = 0;
        $hook_handler = function($args) use (&$var) { $var++; };

        $api->register_hook('test', $hook_handler);

        $api->exec_hook('test', []);

        $this->assertSame(1, $var);

        $api->unregister_hook('test', $hook_handler);

        $api->exec_hook('test', []);

        $this->assertSame(1, $var);
        $this->assertFalse($api->is_processing());
    }

    /**
     * Test tasks registration
     */
    function test_tasks()
    {
        $api = \rcube_plugin_api::get_instance();

        $this->assertTrue($api->register_task('test', 'test'));
        $this->assertTrue($api->is_plugin_task('test'));
    }
}