1<?php
2
3class parserutils_get_renderer_test extends DokuWikiTest {
4
5    private $plugin_controller;
6
7    // test default behaviour / usual settings
8    function test_p_get_renderer_normal() {
9        global $conf;
10
11        $old_conf = $conf;
12        $conf['renderer_xhtml'] = 'xhtml';
13
14        $this->assertInstanceOf('Doku_Renderer_xhtml', p_get_renderer('xhtml'));
15
16        $conf = $old_conf;
17    }
18
19    // test get a renderer plugin
20    function test_p_get_renderer_plugin() {
21        global $conf;
22        global $plugin_controller;
23
24        $old_conf = $conf;
25        $conf['renderer_xhtml'] = 'get_renderer_test';
26        $this->plugin_controller = $plugin_controller;
27        $plugin_controller = $this;
28
29        $this->assertInstanceOf('renderer_plugin_test', p_get_renderer('xhtml'));
30
31        $conf = $old_conf;
32        $plugin_controller = $this->plugin_controller;
33    }
34
35    // test fallback succeeds
36    function test_p_get_renderer_fallback() {
37        global $conf;
38
39        $old_conf = $conf;
40        $conf['renderer_xhtml'] = 'badvalue';
41
42        $this->assertInstanceOf('Doku_Renderer_xhtml', p_get_renderer('xhtml'));
43
44        $conf = $old_conf;
45    }
46
47    // test fallback fails
48    function test_p_get_renderer_fallback_fail() {
49        global $conf;
50
51        $old_conf = $conf;
52        $conf['renderer_junk'] = 'badvalue';
53
54        $this->assertNull(p_get_renderer('junk'));
55
56        $conf = $old_conf;
57    }
58
59    // wrapper function for the fake plugin controller, return $this for the fake syntax of this test
60    function load($type,$name,$new=false,$disabled=false){
61        if ($name == 'get_renderer_test') {
62            return new renderer_plugin_test();
63        } else {
64            return $this->plugin_controller->load($type, $name, $new, $disabled);
65        }
66    }
67 }
68
69require_once DOKU_INC . 'inc/parser/xhtml.php';
70
71class renderer_plugin_test extends Doku_Renderer_xhtml {
72
73    function canRender($format) {
74      return ($format=='xhtml');
75    }
76
77}
78
79// vim:ts=4:sw=4:et:
80