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