1<?php
2
3class utf8_basename_test extends DokuWikiTest {
4
5     function test1(){
6        $data = array(
7            array('/this/foo/bar.test.png',         '', 'bar.test.png'),
8            array('\\this\\foo\\bar.test.png',      '', 'bar.test.png'),
9            array('/this\\foo/bar.test.png',        '', 'bar.test.png'),
10            array('/this/foo\\bar.test.png',        '', 'bar.test.png'),
11
12            array('/this/ДокуВики/bar.test.png',    '', 'bar.test.png'),
13            array('\\this\\ДокуВики\\bar.test.png', '', 'bar.test.png'),
14            array('/this\\ДокуВики/bar.test.png',   '', 'bar.test.png'),
15            array('/this/ДокуВики\\bar.test.png',   '', 'bar.test.png'),
16
17            array('/this/foo/ДокуВики.test.png',    '', 'ДокуВики.test.png'),
18            array('\\this\\foo\\ДокуВики.test.png', '', 'ДокуВики.test.png'),
19            array('/this\\foo/ДокуВики.test.png',   '', 'ДокуВики.test.png'),
20            array('/this/foo\\ДокуВики.test.png',   '', 'ДокуВики.test.png'),
21
22            array('/this/foo/bar.test.png',         '.png', 'bar.test'),
23            array('\\this\\foo\\bar.test.png',      '.png', 'bar.test'),
24            array('/this\\foo/bar.test.png',        '.png', 'bar.test'),
25            array('/this/foo\\bar.test.png',        '.png', 'bar.test'),
26
27            array('/this/ДокуВики/bar.test.png',    '.png', 'bar.test'),
28            array('\\this\\ДокуВики\\bar.test.png', '.png', 'bar.test'),
29            array('/this\\ДокуВики/bar.test.png',   '.png', 'bar.test'),
30            array('/this/ДокуВики\\bar.test.png',   '.png', 'bar.test'),
31
32            array('/this/foo/ДокуВики.test.png',    '.png', 'ДокуВики.test'),
33            array('\\this\\foo\\ДокуВики.test.png', '.png', 'ДокуВики.test'),
34            array('/this\\foo/ДокуВики.test.png',   '.png', 'ДокуВики.test'),
35            array('/this/foo\\ДокуВики.test.png',   '.png', 'ДокуВики.test'),
36
37            array('/this/foo/bar.test.png',         '.foo', 'bar.test.png'),
38            array('\\this\\foo\\bar.test.png',      '.foo', 'bar.test.png'),
39            array('/this\\foo/bar.test.png',        '.foo', 'bar.test.png'),
40            array('/this/foo\\bar.test.png',        '.foo', 'bar.test.png'),
41
42            array('/this/ДокуВики/bar.test.png',    '.foo', 'bar.test.png'),
43            array('\\this\\ДокуВики\\bar.test.png', '.foo', 'bar.test.png'),
44            array('/this\\ДокуВики/bar.test.png',   '.foo', 'bar.test.png'),
45            array('/this/ДокуВики\\bar.test.png',   '.foo', 'bar.test.png'),
46
47            array('/this/foo/ДокуВики.test.png',    '.foo', 'ДокуВики.test.png'),
48            array('\\this\\foo\\ДокуВики.test.png', '.foo', 'ДокуВики.test.png'),
49            array('/this\\foo/ДокуВики.test.png',   '.foo', 'ДокуВики.test.png'),
50            array('/this/foo\\ДокуВики.test.png',   '.foo', 'ДокуВики.test.png'),
51
52
53            array('/this/foo/ДокуВики.test.Вик',    '.foo', 'ДокуВики.test.Вик'),
54            array('\\this\\foo\\ДокуВики.test.Вик', '.foo', 'ДокуВики.test.Вик'),
55            array('/this\\foo/ДокуВики.test.Вик',   '.foo', 'ДокуВики.test.Вик'),
56            array('/this/foo\\ДокуВики.test.Вик',   '.foo', 'ДокуВики.test.Вик'),
57
58            array('/this/foo/ДокуВики.test.Вик',    '.Вик', 'ДокуВики.test'),
59            array('\\this\\foo\\ДокуВики.test.Вик', '.Вик', 'ДокуВики.test'),
60            array('/this\\foo/ДокуВики.test.Вик',   '.Вик', 'ДокуВики.test'),
61            array('/this/foo\\ДокуВики.test.Вик',   '.Вик', 'ДокуВики.test'),
62
63            array('bar.test.png', '', 'bar.test.png'),
64            array('bar.test.png', '.png', 'bar.test'),
65
66            array('/bar.test.png', '', 'bar.test.png'),
67            array('/bar.test.png', '.png', 'bar.test'),
68            array('\\bar.test.png', '', 'bar.test.png'),
69            array('\\bar.test.png', '.png', 'bar.test'),
70            array('\\/bar.test.png', '', 'bar.test.png'),
71            array('\\/bar.test.png', '.png', 'bar.test'),
72            array('/\\bar.test.png', '', 'bar.test.png'),
73            array('/\\bar.test.png', '.png', 'bar.test'),
74
75            // PHP's basename does this too:
76            array('foo/',   '', 'foo'),
77            array('foo\\',  '', 'foo'),
78            array('foo\\/', '', 'foo'),
79            array('foo/\\', '', 'foo'),
80            array('foo.png/',   '.png', 'foo'),
81            array('foo.png\\',  '.png', 'foo'),
82            array('foo.png\\/', '.png', 'foo'),
83            array('foo.png/\\', '.png', 'foo'),
84        );
85
86        foreach($data as $test){
87            $this->assertEquals($test[2], \dokuwiki\Utf8\PhpString::basename($test[0], $test[1]), "input: ('".$test[0]."', '".$test[1]."')");
88        }
89     }
90
91}
92