xref: /dokuwiki/_test/tests/inc/common_ml.test.php (revision c3cc6e05f5349786307d8b1c79f3da75d5fee9de)
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
23826d2766SKlap-in        $expect = DOKU_BASE . $this->script . '?a=b&amp;c=d&amp;q=%26%C3%A4&amp;media=some:img.jpg';
24826d2766SKlap-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
34826d2766SKlap-in        $expect = DOKU_BASE . $this->script . '?a=b&c=d&amp;media=some:img.png';
35826d2766SKlap-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
45826d2766SKlap-in        $expect = DOKU_BASE . $this->script . '?a=b&amp;c=d&amp;media=some:img.gif';
46826d2766SKlap-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
55826d2766SKlap-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.'&amp;tok='.$tok.'&amp;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
69826d2766SKlap-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.'&amp;tok='.$tok.'&amp;media='.$id;
75a3d0aa22SChristopher Smith        $this->assertEquals($expect, ml($id, $args));
76a3d0aa22SChristopher Smith    }
77826d2766SKlap-in
78826d2766SKlap-in    function test_ml_imgresize_array_rootid() {
79826d2766SKlap-in        global $conf;
80826d2766SKlap-in        $conf['useslash']   = 0;
81826d2766SKlap-in        $conf['userewrite'] = 0;
82826d2766SKlap-in
83826d2766SKlap-in        $id      = ':wiki:dokuwiki-128.png';
84826d2766SKlap-in        $cleanid = 'wiki:dokuwiki-128.png';
85826d2766SKlap-in        $w       = 80;
86826d2766SKlap-in        $args    = array('w' => $w);
87826d2766SKlap-in        $tok     = media_get_token($cleanid, $w, 0);
88826d2766SKlap-in
89826d2766SKlap-in        $expect = DOKU_BASE.$this->script.'?w='.$w.'&amp;tok='.$tok.'&amp;media='.$cleanid;
90826d2766SKlap-in        $this->assertEquals($expect, ml($id, $args));
91826d2766SKlap-in    }
92826d2766SKlap-in
934002c084SKlap-in    function test_ml_img_external() {
944002c084SKlap-in        global $conf;
954002c084SKlap-in        $conf['useslash']   = 0;
964002c084SKlap-in        $conf['userewrite'] = 0;
974002c084SKlap-in
984002c084SKlap-in        $ids  = array(
994002c084SKlap-in            'https://example.com/lib/tpl/dokuwiki/images/logo.png',
1004002c084SKlap-in            'http://example.com/lib/tpl/dokuwiki/images/logo.png',
1014002c084SKlap-in            'ftp://example.com/lib/tpl/dokuwiki/images/logo.png'
1024002c084SKlap-in        );
1034002c084SKlap-in
1044002c084SKlap-in        foreach($ids as $id) {
1054002c084SKlap-in            $tok = media_get_token($id, 0, 0);
1064002c084SKlap-in
1074002c084SKlap-in            $expect = DOKU_BASE.$this->script.'?tok='.$tok.'&amp;media='.rawurlencode($id);
1084002c084SKlap-in            $this->assertEquals($expect, ml($id));
1094002c084SKlap-in        }
1104002c084SKlap-in    }
1114002c084SKlap-in
112826d2766SKlap-in    function test_ml_imgresize_array_external() {
113826d2766SKlap-in        global $conf;
114826d2766SKlap-in        $conf['useslash']   = 0;
115826d2766SKlap-in        $conf['userewrite'] = 0;
116826d2766SKlap-in
117826d2766SKlap-in        $ids  = array(
118826d2766SKlap-in            'https://example.com/lib/tpl/dokuwiki/images/logo.png',
119826d2766SKlap-in            'http://example.com/lib/tpl/dokuwiki/images/logo.png',
120826d2766SKlap-in            'ftp://example.com/lib/tpl/dokuwiki/images/logo.png'
121826d2766SKlap-in        );
122826d2766SKlap-in        $w    = 80;
123826d2766SKlap-in        $args = array('w' => $w);
124826d2766SKlap-in
125826d2766SKlap-in        foreach($ids as $id) {
126826d2766SKlap-in            $tok = media_get_token($id, $w, 0);
127*c3cc6e05SAndreas Gohr            $hash = substr(\dokuwiki\PassHash::hmac('md5', $id, auth_cookiesalt()), 0, 6);
128826d2766SKlap-in
1294002c084SKlap-in            $expect = DOKU_BASE.$this->script.'?w='.$w.'&amp;tok='.$tok.'&amp;media='.rawurlencode($id);
130826d2766SKlap-in            $this->assertEquals($expect, ml($id, $args));
131826d2766SKlap-in        }
1324002c084SKlap-in
1334002c084SKlap-in        $h    = 50;
1344002c084SKlap-in        $args = array('h' => $h);
1354002c084SKlap-in        $tok = media_get_token($id, $h, 0);
1364002c084SKlap-in
1374002c084SKlap-in        $expect = DOKU_BASE.$this->script.'?h='.$h.'&amp;tok='.$tok.'&amp;media='.rawurlencode($id);
1384002c084SKlap-in        $this->assertEquals($expect, ml($id, $args));
1394002c084SKlap-in
1404002c084SKlap-in        $w    = 80;
1414002c084SKlap-in        $h    = 50;
1424002c084SKlap-in        $args = array('w' => $w, 'h' => $h);
1434002c084SKlap-in        $tok = media_get_token($id, $w, $h);
1444002c084SKlap-in
1454002c084SKlap-in        $expect = DOKU_BASE.$this->script.'?w='.$w.'&amp;h='.$h.'&amp;tok='.$tok.'&amp;media='.rawurlencode($id);
1464002c084SKlap-in        $this->assertEquals($expect, ml($id, $args));
1474002c084SKlap-in
148826d2766SKlap-in    }
14907a7d227Slisps
15007a7d227Slisps    function test_ml_empty_rev() {
15107a7d227Slisps        global $conf;
15207a7d227Slisps        $conf['useslash'] = 0;
15307a7d227Slisps        $conf['userewrite'] = 0;
15407a7d227Slisps
15507a7d227Slisps        $args = array('a' => 'b', 'c' => 'd', 'rev' => '');
15607a7d227Slisps
15707a7d227Slisps        $expect = DOKU_BASE . $this->script . '?a=b&amp;c=d&amp;media=some:img.jpg';
15807a7d227Slisps        $this->assertEquals($expect, ml('some:img.jpg', $args));
15907a7d227Slisps    }
160a3d0aa22SChristopher Smith}
161