xref: /dokuwiki/_test/tests/inc/safefn.test.php (revision 5a0eec47d375f076d810160503bdd303f8cf62a0)
1<?php
2// use no mbstring help here
3if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1);
4require_once DOKU_INC.'inc/utf8.php';
5require_once DOKU_INC.'inc/SafeFN.class.php';
6
7class safeFN_test extends DokuWikiTest {
8
9
10    function test1(){
11        // we test multiple cases here - format: string, repl, additional, test
12        $tests   = array();
13        $tests[] = array('äa.txt', '%5g]a.txt');
14        $tests[] = array('ä.', '%5g].');
15        $tests[] = array('asciistring','asciistring');
16        $tests[] = array('ascii-_/.string','ascii-_/.string');
17        $tests[] = array('AName','%x%1a]ame');
18        $tests[] = array('A Name','%x%0%1a]ame');
19        $tests[] = array('Another...Name','%x]nother...%1a]ame');
20        $tests[] = array('Aß∂ƒName','%x%5b%6oy%aa%1a]ame');
21        $tests[] = array('A%ß-∂_.ƒName','%x%%5b]-%6oy]_.%aa%1a]ame');
22        $tests[] = array('A%%ß-∂_.ƒName','%x%%%5b]-%6oy]_.%aa%1a]ame');
23        $tests[] = array('데이터도 함께 복원됩니다. 강력한','%zf4%13dg%15ao%zhg%0%164o%yig%0%11at%138w%zk9%zag%zb8].%0%xyt%10cl%164c]');
24        $tests[] = array('совместимая','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr]');
25        $tests[] = array('нехватка_файлового_пространства_на_сервере_p0-squid.some.domain.1270211897.txt.gz','%t9%t1%th%sy%sw%te%t6%sw]_%tg%sw%t5%t7%ta%sy%ta%sz%ta]_%tb%tc%ta%td%te%tc%sw%t9%td%te%sy%sw]_%t9%sw]_%td%t1%tc%sy%t1%tc%t1]_p0-squid.some.domain.1270211897.txt.gz');
26
27        $tests[] = array('name[1]','name[1]');
28        $tests[] = array('Name[1]','%1a]ame[1]');
29        $tests[] = array('Name[A]','%1a]ame[%x]]');
30
31        foreach($tests as $test){
32            list($utf8,$safe) = $test;
33            $this->assertEquals(SafeFN::encode($utf8),$safe);
34            $this->assertEquals(SafeFN::decode($safe),$utf8);
35        }
36    }
37
38    function test2(){
39        $tests[] = array('совместимая','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr');
40
41        foreach($tests as $test){
42            list($utf8,$safe) = $test;
43            $this->assertEquals(SafeFN::decode($safe),$utf8);
44        }
45    }
46
47}
48//Setup VIM: ex: et ts=4 :
49