diff --git a/_test/tests/inc/common_wl.test.php b/_test/tests/inc/common_wl.test.php new file mode 100644 index 0000000000000000000000000000000000000000..2e34dcae3c4aa3eec9919a625a49c7e316bf5543 --- /dev/null +++ b/_test/tests/inc/common_wl.test.php @@ -0,0 +1,148 @@ +<?php + +class common_wl_test extends DokuWikiTest { + + function test_wl_empty() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + $conf['start'] = 'start'; + + $this->assertEquals(DOKU_BASE . DOKU_SCRIPT . '?id=start' , wl()); + } + + function test_wl_empty_rewrite1() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 1; + $conf['start'] = 'start'; + + $this->assertEquals(DOKU_BASE . 'start' , wl()); + } + + function test_wl_empty_rewrite2() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 2; + $conf['start'] = 'start'; + + $this->assertEquals(DOKU_BASE . DOKU_SCRIPT . '/start' , wl()); + } + + function test_wl_id() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some'; + $this->assertEquals($expect, wl('some')); + } + + function test_wl_id_ns() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:some'; + $this->assertEquals($expect, wl('some:some')); + } + + function test_wl_id_ns_start() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:'; + $this->assertEquals($expect, wl('some:')); + } + + function test_wl_args_array() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $args = array('a' => 'b', 'c' => 'd', 'q' => '&ä'); + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:&a=b&c=d&q=%26%C3%A4'; + $this->assertEquals($expect, wl('some:', $args)); + } + + function test_wl_args_string() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $args = 'a=b&c=d'; + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:&a=b&c=d'; + $this->assertEquals($expect, wl('some:', $args)); + } + + function test_wl_args_comma_string() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $args = 'a=b,c=d'; + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:&a=b&c=d'; + $this->assertEquals($expect, wl('some:', $args)); + } + + function test_wl_abs() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $expect = DOKU_URL . DOKU_SCRIPT . '?id=some:'; + $this->assertEquals($expect, wl('some:', '', true)); + } + + function test_wl_sep() { + global $conf; + $conf['useslash'] = 0; + $conf['userewrite'] = 0; + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:&a=b&c=d'; + $this->assertEquals($expect, wl('some:', 'a=b,c=d', false, '&')); + } + + function test_wl_useslash() { + global $conf; + $conf['useslash'] = 1; + $conf['userewrite'] = 0; + + $expect = DOKU_BASE . DOKU_SCRIPT . '?id=some:&a=b&c=d'; + $this->assertEquals($expect, wl('some:', 'a=b,c=d', false, '&')); + } + + function test_wl_useslash_rewrite1() { + global $conf; + $conf['useslash'] = 1; + $conf['userewrite'] = 1; + + $expect = DOKU_BASE . 'some/?a=b&c=d'; + $this->assertEquals($expect, wl('some:', 'a=b,c=d', false, '&')); + } + + function test_wl_useslash_rewrite1_sub_page() { + global $conf; + $conf['useslash'] = 1; + $conf['userewrite'] = 1; + + $expect = DOKU_BASE . 'some/one?a=b&c=d'; + $this->assertEquals($expect, wl('some:one', 'a=b,c=d', false, '&')); + } + + function test_wl_useslash_rewrite2() { + global $conf; + $conf['useslash'] = 1; + $conf['userewrite'] = 2; + + $expect = DOKU_BASE . DOKU_SCRIPT . '/some/one?a=b&c=d'; + $this->assertEquals($expect, wl('some:one', 'a=b,c=d', false, '&')); + } + + + +} \ No newline at end of file diff --git a/inc/common.php b/inc/common.php index 6ea536c44f54cc9e1d400a8693beeb8873a0da1e..cd0780730b3380c742047c9211377699a8c58324 100644 --- a/inc/common.php +++ b/inc/common.php @@ -342,16 +342,18 @@ function idfilter($id,$ue=true){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function wl($id='',$more='',$abs=false,$sep='&'){ +function wl($id='',$urlParameters='',$absolute=false,$separator='&'){ global $conf; - if(is_array($more)){ - $more = buildURLparams($more,$sep); + if(is_array($urlParameters)){ + $urlParameters = buildURLparams($urlParameters,$separator); }else{ - $more = str_replace(',',$sep,$more); + $urlParameters = str_replace(',',$separator,$urlParameters); } - - $id = idfilter($id); - if($abs){ + if ($id === '') { + $id = $conf['start']; + } + $id = idfilter($id); + if($absolute){ $xlink = DOKU_URL; }else{ $xlink = DOKU_BASE; @@ -359,16 +361,16 @@ function wl($id='',$more='',$abs=false,$sep='&'){ if($conf['userewrite'] == 2){ $xlink .= DOKU_SCRIPT.'/'.$id; - if($more) $xlink .= '?'.$more; + if($urlParameters) $xlink .= '?'.$urlParameters; }elseif($conf['userewrite']){ $xlink .= $id; - if($more) $xlink .= '?'.$more; + if($urlParameters) $xlink .= '?'.$urlParameters; }elseif($id){ $xlink .= DOKU_SCRIPT.'?id='.$id; - if($more) $xlink .= $sep.$more; + if($urlParameters) $xlink .= $separator.$urlParameters; }else{ $xlink .= DOKU_SCRIPT; - if($more) $xlink .= '?'.$more; + if($urlParameters) $xlink .= '?'.$urlParameters; } return $xlink;