xref: /dokuwiki/_test/tests/inc/parser/renderer_resolveinterwiki.test.php (revision ddb55c702f2393a435c309fd7d4e169acb2675f7)
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    function testDefaults() {
11        $Renderer = new Doku_Renderer();
12        $Renderer->interwiki = getInterwiki();
13        $Renderer->interwiki['scheme'] = '{SCHEME}://example.com';
14        $Renderer->interwiki['withslash'] = '/test';
15        $Renderer->interwiki['onlytext'] = 'onlytext{NAME}'; //with {URL} double urlencoded
16        $Renderer->interwiki['withquery'] = 'anyns:{NAME}?do=edit';
17
18        $tests = array(
19            // shortcut, reference and expected
20            array('wp', 'foo @+%/#txt', 'http://en.wikipedia.org/wiki/foo @+%/#txt'),
21            array('amazon', 'foo @+%/#txt', 'http://www.amazon.com/exec/obidos/ASIN/foo%20%40%2B%25%2F/splitbrain-20/#txt'),
22            array('doku', 'foo @+%/#txt', 'http://www.dokuwiki.org/foo%20%40%2B%25%2F#txt'),
23            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'),
24            array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'),
25            //relative url
26            array('withslash', 'foo @+%/#txt', '/testfoo%20%40%2B%25%2F#txt'),
27            //dokuwiki id's
28            array('onlytext', 'foo @+%#txt', DOKU_BASE.'doku.php?id=onlytextfoo%20%40%2B%25#txt'),
29            array('user', 'foo @+%#txt', DOKU_BASE.'doku.php?id=wiki:users:foo%20%40%2B%25#txt'),
30            array('withquery', 'foo @+%#txt', DOKU_BASE.'doku.php?id=anyns:foo%20%40%2B%25&amp;do=edit#txt')
31        );
32
33        foreach($tests as $test) {
34            $url = $Renderer->_resolveInterWiki($test[0], $test[1]);
35
36            $this->assertEquals($test[2], $url);
37        }
38    }
39
40    function testNonexisting() {
41        $Renderer = new Doku_Renderer();
42        $Renderer->interwiki = getInterwiki();
43
44        $shortcut = 'nonexisting';
45        $reference = 'foo @+%/';
46        $url = $Renderer->_resolveInterWiki($shortcut, $reference);
47        $expected = 'http://www.google.com/search?q=foo%20%40%2B%25%2F&amp;btnI=lucky';
48
49        $this->assertEquals($expected, $url);
50    }
51
52}