xref: /dokuwiki/_test/tests/inc/parser/renderer_resolveinterwiki.test.php (revision 5267006fc0516e8787cbc6a79e55cd4efd3e52c9)
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            array('skype',  'foo @+%/#txt', 'skype:foo @+%/#txt'),
28            //dokuwiki id's
29            array('onlytext', 'foo @+%#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'),
30            array('user', 'foo @+%#txt', DOKU_BASE.'doku.php?id=user:foo#txt'),
31            array('withquery', 'foo @+%#txt', DOKU_BASE.'doku.php?id=anyns:foo&amp;do=edit#txt')
32        );
33
34        foreach($tests as $test) {
35            $url = $Renderer->_resolveInterWiki($test[0], $test[1]);
36
37            $this->assertEquals($test[2], $url);
38        }
39    }
40
41    function testNonexisting() {
42        $Renderer = new Doku_Renderer();
43        $Renderer->interwiki = getInterwiki();
44
45        $shortcut = 'nonexisting';
46        $reference = 'foo @+%/';
47        $url = $Renderer->_resolveInterWiki($shortcut, $reference);
48        $expected = 'http://www.google.com/search?q=foo%20%40%2B%25%2F&amp;btnI=lucky';
49
50        $this->assertEquals($expected, $url);
51    }
52
53}