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 //ToDo: Check needed, is double slash in path desired 24 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'), 25 array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'), 26 //relative url 27 array('withslash', 'foo @+%/#txt', '/testfoo%20%40%2B%25%2F#txt'), 28 //dokuwiki id's 29 array('onlytext', 'foo @+%#txt', '/tmp/doku.php?id=onlytextfoo%20%40%2B%25#txt'), 30 array('user', 'foo @+%#txt', '/tmp/doku.php?id=wiki:users:foo%20%40%2B%25#txt'), 31 array('withquery', 'foo @+%#txt', '/tmp/doku.php?id=anyns:foo%20%40%2B%25&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&btnI=lucky'; 49 50 $this->assertEquals($expected, $url); 51 } 52 53}