xref: /dokuwiki/_test/tests/inc/parser/renderer_resolveinterwiki.test.php (revision 2d6df7955d82d34f7a58b289fa04755c5ab9146e)
1<?php
2
3require_once DOKU_INC . 'inc/parser/renderer.php';
4
5/**
6 * Tests for Doku_Renderer::_resolveInterWiki()
7 */
8class Test_resolveInterwiki extends PHPUnit_Framework_TestCase {
9
10
11    function testDefaults() {
12        $Renderer = new Doku_Renderer();
13        $Renderer->interwiki = getInterwiki();
14        $Renderer->interwiki['scheme'] = '{SCHEME}://example.com';
15        $Renderer->interwiki['slash'] = '/test';
16        $Renderer->interwiki['onlytext'] = 'onlytext';
17
18         //var_dump($Renderer->interwiki);
19
20        $tests = array(
21            // shortcut, reference and expected
22            array('wp', 'foo @+%/', 'http://en.wikipedia.org/wiki/foo @+%/'),
23            array('amazon', 'foo @+%/', 'http://www.amazon.com/exec/obidos/ASIN/foo%20%40%2B%25%2F/splitbrain-20/'),
24            array('doku', 'foo @+%/', 'http://www.dokuwiki.org/foo%20%40%2B%25%2F'),
25            //ToDo: Check needed, is double slash in path desired
26            array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%2F', 'http://example.com.83.nyud.net:8090//path/naar/?query=foo%20%40%2B%25%2F'),
27            array('scheme', 'ftp://foo @+%/', 'ftp://example.com'),
28            //relative url
29            array('slash', 'foo @+%/', '/testfoo%20%40%2B%25%2F'),
30            //dokuwiki id's
31            array('onlytext', 'foo @+%/', 'onlytextfoo%20%40%2B%25%2F'),
32            array('user', 'foo @+%/', 'wiki:users:foo%20%40%2B%25%2F')
33        );
34
35        foreach($tests as $test) {
36            $url = $Renderer->_resolveInterWiki($test[0], $test[1]);
37
38            $this->assertEquals($test[2], $url);
39        }
40    }
41
42    function testNonexisting() {
43        $Renderer = new Doku_Renderer();
44        $Renderer->interwiki = getInterwiki();
45
46        $shortcut = 'nonexisting';
47        $reference = 'foo @+%/';
48        $url = $Renderer->_resolveInterWiki($shortcut, $reference);
49        $expected = 'http://www.google.com/search?q=foo%20%40%2B%25%2F&amp;btnI=lucky';
50
51        $this->assertEquals($expected, $url);
52    }
53
54}