1<?php
2
3require_once dirname(__FILE__) . '/../IckeNavigation.php';
4
5/**
6 * @group template_icke-template
7 * @group templates
8 */
9class IckeTemplateNavigationTest extends DokuWikiTest {
10
11    public function testLoadNavigation() {
12        $config = 'user:%USER%:dashboard ,, allgemeines:, fachwissen:, projekt:,kunde:, ,hilfe:';
13
14        $_SERVER['REMOTE_USER'] = '';
15        plugin_disable('translation');
16
17        $navigation = new IckeNavigation();
18        $actual = $navigation->loadNavigation($config);
19        $expected = array(
20            new IckeNavigationSeparator(),
21            new IckeNavigationItem('allgemeines:', 'allgemeines:start', false),
22            new IckeNavigationItem('fachwissen:', 'fachwissen:start', false),
23            new IckeNavigationItem('projekt:', 'projekt:start', false),
24            new IckeNavigationItem('kunde:', 'kunde:start', false),
25            new IckeNavigationSeparator(),
26            new IckeNavigationItem('hilfe:', 'hilfe:start', false)
27        );
28
29        $this->assertEquals($expected, $actual);
30    }
31
32    public function testLoadNavigationUser() {
33        $config = 'user:%USER%:dashboard ,, allgemeines:, fachwissen:, projekt:,kunde:, ,hilfe:';
34
35        $_SERVER['REMOTE_USER'] = 'user';
36        plugin_disable('translation');
37
38        $navigation = new IckeNavigation();
39        $actual = $navigation->loadNavigation($config);
40        $expected = array(
41            new IckeNavigationItem('user:%USER%:dashboard', 'user:user:dashboard', false),
42            new IckeNavigationSeparator(),
43            new IckeNavigationItem('allgemeines:', 'allgemeines:start', false),
44            new IckeNavigationItem('fachwissen:', 'fachwissen:start', false),
45            new IckeNavigationItem('projekt:', 'projekt:start', false),
46            new IckeNavigationItem('kunde:', 'kunde:start', false),
47            new IckeNavigationSeparator(),
48            new IckeNavigationItem('hilfe:', 'hilfe:start', false)
49        );
50
51        $this->assertEquals($expected, $actual);
52    }
53
54    public function testLoadNavigationTranslation() {
55        $config = 'user:%USER%:dashboard ,, allgemeines:, fachwissen:, projekt:,kunde:, ,hilfe:';
56
57        $_SERVER['REMOTE_USER'] = '';
58        plugin_enable('translation');
59
60        $_SESSION[DOKU_COOKIE]['translationlc'] = 'en';
61        $this->touchWiki('en:allgemeines:start');
62        $this->touchWiki('en:fachwissen:start');
63        $this->touchWiki('en:projekt:start');
64        $this->touchWiki('en:kunde:start');
65        $this->touchWiki('en:hilfe:start');
66
67        $navigation = new IckeNavigation();
68        $actual = $navigation->loadNavigation($config);
69        $expected = array(
70            new IckeNavigationSeparator(),
71            new IckeNavigationItem('allgemeines:', 'en:allgemeines:start', false),
72            new IckeNavigationItem('fachwissen:', 'en:fachwissen:start', false),
73            new IckeNavigationItem('projekt:', 'en:projekt:start', false),
74            new IckeNavigationItem('kunde:', 'en:kunde:start', false),
75            new IckeNavigationSeparator(),
76            new IckeNavigationItem('hilfe:', 'en:hilfe:start', false)
77        );
78
79        $this->assertEquals($expected, $actual);
80    }
81
82    private function touchWiki($id) {
83        io_mkdir_p(wikiFN($id));
84        touch(wikiFN($id));
85    }
86
87    public function testNavigationItemClassNS() {
88        $_SESSION[DOKU_COOKIE]['translationlc'] = 'en';
89        $item = new IckeNavigationItem('allgemeines:', 'allgemeines:start', false);
90        $this->assertEquals('allgemeines', $item->class);
91    }
92
93    public function testNavigationItemClassPage() {
94        $_SESSION[DOKU_COOKIE]['translationlc'] = 'en';
95        $item = new IckeNavigationItem('allgemeines', 'allgemeines', false);
96        $this->assertEquals('allgemeines', $item->class);
97    }
98
99    public function testNavigationItemClassNested() {
100        $_SESSION[DOKU_COOKIE]['translationlc'] = 'en';
101        $item = new IckeNavigationItem('user:%USER%:dashboard', 'user:name:dashboard', false);
102        $this->assertEquals('user', $item->class);
103    }
104
105
106}
107