aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/plugins/PluginAddlinkTest.php
blob: a2f25becbf4793a9657556151c55c908b7a18560 (plain) (blame)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php

/**
 * PluginPlayvideosTest.php
 */

require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
require_once 'application/Router.php';

/**
 * Class PluginAddlinkTest
 * Unit test for the Addlink toolbar plugin
 */
class PluginAddlinkTest extends PHPUnit_Framework_TestCase
{
    /**
     * Reset plugin path.
     */
    function setUp()
    {
        PluginManager::$PLUGINS_PATH = 'plugins';
    }

    /**
     * Test render_header hook while logged in.
     */
    function testAddlinkHeaderLoggedIn()
    {
        $str = 'stuff';
        $data = array($str => $str);
        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
        $data['_LOGGEDIN_'] = true;

        $data = hook_addlink_toolbar_render_header($data);
        $this->assertEquals($str, $data[$str]);
        $this->assertEquals(1, count($data['fields_toolbar']));

        $data = array($str => $str);
        $data['_PAGE_'] = $str;
        $data['_LOGGEDIN_'] = true;
        $data = hook_addlink_toolbar_render_header($data);
        $this->assertEquals($str, $data[$str]);
        $this->assertArrayNotHasKey('fields_toolbar', $data);
    }

    /**
     * Test render_header hook while logged out.
     */
    function testAddlinkHeaderLoggedOut()
    {
        $str = 'stuff';
        $data = array($str => $str);
        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
        $data['_LOGGEDIN_'] = false;

        $data = hook_addlink_toolbar_render_header($data);
        $this->assertEquals($str, $data[$str]);
        $this->assertArrayNotHasKey('fields_toolbar', $data);
    }

    /**
     * Test render_includes hook while logged in.
     */
    function testAddlinkIncludesLoggedIn()
    {
        $str = 'stuff';
        $data = array($str => $str);
        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
        $data['_LOGGEDIN_'] = true;

        $data = hook_addlink_toolbar_render_includes($data);
        $this->assertEquals($str, $data[$str]);
        $this->assertEquals(1, count($data['css_files']));

        $str = 'stuff';
        $data = array($str => $str);
        $data['_PAGE_'] = $str;
        $data['_LOGGEDIN_'] = true;

        $data = hook_addlink_toolbar_render_includes($data);
        $this->assertEquals($str, $data[$str]);
        $this->assertArrayNotHasKey('css_files', $data);
    }

    /**
     * Test render_includes hook.
     * Should not affect css files while logged out.
     */
    function testAddlinkIncludesLoggedOut()
    {
        $str = 'stuff';
        $data = array($str => $str);
        $data['_PAGE_'] = Router::$PAGE_LINKLIST;
        $data['_LOGGEDIN_'] = false;

        $data = hook_addlink_toolbar_render_includes($data);
        $this->assertEquals($str, $data[$str]);
        $this->assertArrayNotHasKey('css_files', $data);
    }
}