1a3d0aa22SChristopher Smith<?php 2a3d0aa22SChristopher Smith 3c3ff531eSAndreas Gohrclass common_ml_test extends DokuWikiTest { 4a3d0aa22SChristopher Smith 5a3d0aa22SChristopher Smith private $script = 'lib/exe/fetch.php'; 6a3d0aa22SChristopher Smith 7a3d0aa22SChristopher Smith function test_ml_empty() { 8a3d0aa22SChristopher Smith global $conf; 9a3d0aa22SChristopher Smith $conf['useslash'] = 0; 10a3d0aa22SChristopher Smith $conf['userewrite'] = 0; 11a3d0aa22SChristopher Smith $conf['start'] = 'start'; 12a3d0aa22SChristopher Smith 13a3d0aa22SChristopher Smith $this->assertEquals(DOKU_BASE . $this->script . '?media=' , ml()); 14a3d0aa22SChristopher Smith } 15a3d0aa22SChristopher Smith 16a3d0aa22SChristopher Smith function test_ml_args_array() { 17a3d0aa22SChristopher Smith global $conf; 18a3d0aa22SChristopher Smith $conf['useslash'] = 0; 19a3d0aa22SChristopher Smith $conf['userewrite'] = 0; 20a3d0aa22SChristopher Smith 21a3d0aa22SChristopher Smith $args = array('a' => 'b', 'c' => 'd', 'q' => '&ä'); 22a3d0aa22SChristopher Smith 23*826d2766SKlap-in $expect = DOKU_BASE . $this->script . '?a=b&c=d&q=%26%C3%A4&media=some:img.jpg'; 24*826d2766SKlap-in $this->assertEquals($expect, ml('some:img.jpg', $args)); 25a3d0aa22SChristopher Smith } 26a3d0aa22SChristopher Smith 27a3d0aa22SChristopher Smith function test_ml_args_string() { 28a3d0aa22SChristopher Smith global $conf; 29a3d0aa22SChristopher Smith $conf['useslash'] = 0; 30a3d0aa22SChristopher Smith $conf['userewrite'] = 0; 31a3d0aa22SChristopher Smith 32a3d0aa22SChristopher Smith $args = 'a=b&c=d'; 33a3d0aa22SChristopher Smith 34*826d2766SKlap-in $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:img.png'; 35*826d2766SKlap-in $this->assertEquals($expect, ml('some:img.png', $args)); 36a3d0aa22SChristopher Smith } 37a3d0aa22SChristopher Smith 38a3d0aa22SChristopher Smith function test_ml_args_comma_string() { 39a3d0aa22SChristopher Smith global $conf; 40a3d0aa22SChristopher Smith $conf['useslash'] = 0; 41a3d0aa22SChristopher Smith $conf['userewrite'] = 0; 42a3d0aa22SChristopher Smith 43a3d0aa22SChristopher Smith $args = 'a=b,c=d'; 44a3d0aa22SChristopher Smith 45*826d2766SKlap-in $expect = DOKU_BASE . $this->script . '?a=b&c=d&media=some:img.gif'; 46*826d2766SKlap-in $this->assertEquals($expect, ml('some:img.gif', $args)); 47a3d0aa22SChristopher Smith } 48a3d0aa22SChristopher Smith 49a3d0aa22SChristopher Smith 50a3d0aa22SChristopher Smith function test_ml_imgresize_array() { 51a3d0aa22SChristopher Smith global $conf; 52a3d0aa22SChristopher Smith $conf['useslash'] = 0; 53a3d0aa22SChristopher Smith $conf['userewrite'] = 0; 54a3d0aa22SChristopher Smith 55*826d2766SKlap-in $id = 'some:img.png'; 56a3d0aa22SChristopher Smith $w = 80; 57a3d0aa22SChristopher Smith $args = array('w' => $w); 58a3d0aa22SChristopher Smith $tok = media_get_token($id,$w,0); 59a3d0aa22SChristopher Smith 60a3d0aa22SChristopher Smith $expect = DOKU_BASE . $this->script . '?w='.$w.'&tok='.$tok.'&media='.$id; 61a3d0aa22SChristopher Smith $this->assertEquals($expect, ml($id, $args)); 62a3d0aa22SChristopher Smith } 63a3d0aa22SChristopher Smith 64a3d0aa22SChristopher Smith function test_ml_imgresize_string() { 65a3d0aa22SChristopher Smith global $conf; 66a3d0aa22SChristopher Smith $conf['useslash'] = 0; 67a3d0aa22SChristopher Smith $conf['userewrite'] = 0; 68a3d0aa22SChristopher Smith 69*826d2766SKlap-in $id = 'some:img.png'; 70a3d0aa22SChristopher Smith $w = 80; 71a3d0aa22SChristopher Smith $args = 'w='.$w; 72a3d0aa22SChristopher Smith $tok = media_get_token($id,$w,0); 73a3d0aa22SChristopher Smith 74a3d0aa22SChristopher Smith $expect = DOKU_BASE . $this->script . '?w='.$w.'&tok='.$tok.'&media='.$id; 75a3d0aa22SChristopher Smith $this->assertEquals($expect, ml($id, $args)); 76a3d0aa22SChristopher Smith } 77*826d2766SKlap-in 78*826d2766SKlap-in function test_ml_imgresize_array_rootid() { 79*826d2766SKlap-in global $conf; 80*826d2766SKlap-in $conf['useslash'] = 0; 81*826d2766SKlap-in $conf['userewrite'] = 0; 82*826d2766SKlap-in 83*826d2766SKlap-in $id = ':wiki:dokuwiki-128.png'; 84*826d2766SKlap-in $cleanid = 'wiki:dokuwiki-128.png'; 85*826d2766SKlap-in $w = 80; 86*826d2766SKlap-in $args = array('w' => $w); 87*826d2766SKlap-in $tok = media_get_token($cleanid, $w, 0); 88*826d2766SKlap-in 89*826d2766SKlap-in $expect = DOKU_BASE.$this->script.'?w='.$w.'&tok='.$tok.'&media='.$cleanid; 90*826d2766SKlap-in $this->assertEquals($expect, ml($id, $args)); 91*826d2766SKlap-in } 92*826d2766SKlap-in 93*826d2766SKlap-in function test_ml_imgresize_array_external() { 94*826d2766SKlap-in global $conf; 95*826d2766SKlap-in $conf['useslash'] = 0; 96*826d2766SKlap-in $conf['userewrite'] = 0; 97*826d2766SKlap-in 98*826d2766SKlap-in $ids = array( 99*826d2766SKlap-in 'https://example.com/lib/tpl/dokuwiki/images/logo.png', 100*826d2766SKlap-in 'http://example.com/lib/tpl/dokuwiki/images/logo.png', 101*826d2766SKlap-in 'ftp://example.com/lib/tpl/dokuwiki/images/logo.png' 102*826d2766SKlap-in ); 103*826d2766SKlap-in $w = 80; 104*826d2766SKlap-in $args = array('w' => $w); 105*826d2766SKlap-in 106*826d2766SKlap-in foreach($ids as $id) { 107*826d2766SKlap-in $tok = media_get_token($id, $w, 0); 108*826d2766SKlap-in 109*826d2766SKlap-in $expect = DOKU_BASE.$this->script.'?hash='.substr(md5(auth_cookiesalt().$id), 0, 6).'&w='.$w.'&tok='.$tok.'&media='.rawurlencode($id); 110*826d2766SKlap-in $this->assertEquals($expect, ml($id, $args)); 111*826d2766SKlap-in } 112*826d2766SKlap-in } 113a3d0aa22SChristopher Smith} 114