12d6df795SGerrit Uitslag<?php 22d6df795SGerrit Uitslag 3de369923SAndreas Gohruse dokuwiki\test\mock\Doku_Renderer; 42d6df795SGerrit Uitslag 52d6df795SGerrit Uitslag/** 62d6df795SGerrit Uitslag * Tests for Doku_Renderer::_resolveInterWiki() 72d6df795SGerrit Uitslag */ 836340418SAndreas Gohrclass Test_resolveInterwiki extends DokuWikiTest { 92d6df795SGerrit Uitslag 102d6df795SGerrit Uitslag function testDefaults() { 112d6df795SGerrit Uitslag $Renderer = new Doku_Renderer(); 122d6df795SGerrit Uitslag $Renderer->interwiki = getInterwiki(); 132d6df795SGerrit Uitslag $Renderer->interwiki['scheme'] = '{SCHEME}://example.com'; 142345e871SGerrit Uitslag $Renderer->interwiki['withslash'] = '/test'; 156496c33fSGerrit Uitslag $Renderer->interwiki['onlytext'] = ':onlytext{NAME}'; //with {URL} double urlencoded 166496c33fSGerrit Uitslag $Renderer->interwiki['withquery'] = ':anyns:{NAME}?do=edit'; 170cfb5a30SPatrick Brown //this was the only link with host/port/path/query. Keep it here for regression 180cfb5a30SPatrick Brown $Renderer->interwiki['coral'] = 'http://{HOST}.{PORT}.nyud.net:8090{PATH}?{QUERY}'; 192d6df795SGerrit Uitslag 202d6df795SGerrit Uitslag $tests = array( 212d6df795SGerrit Uitslag // shortcut, reference and expected 2217e17ae2SPatrick Brown array('wp', 'foo [\\]^`{|}~@+#%?/#txt', 'https://en.wikipedia.org/wiki/foo %5B%5C%5D%5E%60%7B%7C%7D~@+%23%25?/#txt'), 233b82d1eeSAndreas Gohr array('amazon', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.amazon.com/dp/foo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F?tag=splitbrain-20#txt'), 2417e17ae2SPatrick Brown array('doku', 'foo [\\]^`{|}~@+#%?/#txt', 'https://www.dokuwiki.org/foo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F#txt'), 25ccee93d9SPatrick Brown array('coral', 'http://example.com:83/path/naar/?query=foo%20%40%2B%25%3F%2F', 'http://example.com.83.nyud.net:8090/path/naar/?query=foo%20%40%2B%25%3F%2F'), 262345e871SGerrit Uitslag array('scheme', 'ftp://foo @+%/#txt', 'ftp://example.com#txt'), 272d6df795SGerrit Uitslag //relative url 2817e17ae2SPatrick Brown array('withslash', 'foo [\\]^`{|}~@+#%?/#txt', '/testfoo%20%5B%5C%5D%5E%60%7B%7C%7D~%40%2B%23%25%3F%2F#txt'), 2917e17ae2SPatrick Brown array('skype', 'foo [\\]^`{|}~@+#%?/#txt', 'skype:foo %5B%5C%5D%5E%60%7B%7C%7D~@+%23%25?/#txt'), 302d6df795SGerrit Uitslag //dokuwiki id's 3117e17ae2SPatrick Brown array('onlytext', 'foo [\\]^`{|}~@+#%/#txt', DOKU_BASE.'doku.php?id=onlytextfoo#txt'), 3217e17ae2SPatrick Brown array('user', 'foo [\\]^`{|}~@+#%/#txt', DOKU_BASE.'doku.php?id=user:foo#txt'), 3317e17ae2SPatrick Brown array('withquery', 'foo [\\]^`{|}~@+#%/#txt', DOKU_BASE.'doku.php?id=anyns:foo&do=edit#txt') 342d6df795SGerrit Uitslag ); 352d6df795SGerrit Uitslag 362d6df795SGerrit Uitslag foreach($tests as $test) { 372d6df795SGerrit Uitslag $url = $Renderer->_resolveInterWiki($test[0], $test[1]); 382d6df795SGerrit Uitslag 392d6df795SGerrit Uitslag $this->assertEquals($test[2], $url); 402d6df795SGerrit Uitslag } 412d6df795SGerrit Uitslag } 422d6df795SGerrit Uitslag 432d6df795SGerrit Uitslag function testNonexisting() { 442d6df795SGerrit Uitslag $Renderer = new Doku_Renderer(); 452d6df795SGerrit Uitslag $Renderer->interwiki = getInterwiki(); 462d6df795SGerrit Uitslag 472d6df795SGerrit Uitslag $shortcut = 'nonexisting'; 482d6df795SGerrit Uitslag $reference = 'foo @+%/'; 492d6df795SGerrit Uitslag $url = $Renderer->_resolveInterWiki($shortcut, $reference); 502d6df795SGerrit Uitslag 51*abde5980SPhy $this->assertEquals('', $url); 52*abde5980SPhy $this->assertEquals('', $shortcut); 532d6df795SGerrit Uitslag } 542d6df795SGerrit Uitslag 552d6df795SGerrit Uitslag} 56