xref: /dokuwiki/_test/tests/inc/pageutils_clean_id.test.php (revision dcb2204bf0a8e3e25bf4ff8352a71160e846266b)
1<?php
2
3class init_clean_id_test extends DokuWikiTest {
4
5    function teardown() {
6        global $cache_cleanid;
7        $cache_cleanid = array();
8    }
9
10    function test_default(){
11        // we test multiple cases here
12        // format: $id, $ascii, $correct_output
13        $tests   = array();
14
15        // set dokuwiki defaults
16        global $conf;
17        $conf['sepchar'] = '_';
18        $conf['deaccent'] = 1;
19
20        $tests[] = array('page',false,'page');
21        $tests[] = array('pa_ge',false,'pa_ge');
22        $tests[] = array('pa%ge',false,'pa_ge');
23        $tests[] = array('pa#ge',false,'pa_ge');
24        $tests[] = array('pàge',false,'page');
25        $tests[] = array('pagĖ',false,'page');
26        $tests[] = array('pa$%^*#ge',false,'pa_ge');
27        $tests[] = array('*page*',false,'page');
28        $tests[] = array('ښ',false,'ښ');
29        $tests[] = array('päge',false,'paege');
30        $tests[] = array('foo bar',false,'foo_bar');
31        $tests[] = array('PÄGÖ',false,'paegoe');
32        $tests[] = array('Faß','false','fass');
33        $tests[] = array('ښ侧化并곦  β',false,'ښ侧化并곦_β');
34        $tests[] = array('page:page',false,'page:page');
35        $tests[] = array('page;page',false,'page:page');
36        $tests[] = array('page:page 1.2',false,'page:page_1.2');
37
38        $tests[] = array('page._#!','false','page');
39        $tests[] = array('._#!page','false','page');
40        $tests[] = array('page._#!page','false','page._page');
41        $tests[] = array('ns._#!:page','false','ns:page');
42        $tests[] = array('ns:._#!page','false','ns:page');
43        $tests[] = array('ns._#!ns:page','false','ns._ns:page');
44        $tests[] = array('ns_:page',false,'ns:page');
45        $tests[] = array('page...page','false','page...page');
46        $tests[] = array(':page',false,'page');
47        $tests[] = array(':ns:page',false,'ns:page');
48        $tests[] = array('page:',false,'page');
49        $tests[] = array('ns:page:',false,'ns:page');
50
51        $conf['useslash'] = 0;
52        $tests[] = array('page/page',false,'page_page');
53
54        foreach($tests as $test){
55            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
56        }
57
58        $conf['useslash'] = 1;
59        $tests = array();
60        $tests[] = array('page/page',false,'page:page');
61
62        $this->teardown();
63
64        foreach($tests as $test){
65            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
66        }
67    }
68
69    function test_sepchar(){
70        // we test multiple cases here
71        // format: $id, $ascii, $correct_output
72        $tests   = array();
73
74        global $conf;
75        $conf['sepchar'] = '-';
76        $conf['deaccent'] = 1;
77
78        $tests[] = array('pa-ge',false,'pa-ge');
79        $tests[] = array('pa%ge',false,'pa-ge');
80
81        foreach($tests as $test){
82            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
83        }
84    }
85
86    function test_deaccent_keep(){
87        // we test multiple cases here
88        // format: $id, $ascii, $correct_output
89        $tests   = array();
90
91        global $conf;
92        $conf['sepchar'] = '_';
93        $conf['deaccent'] = 0;
94
95        $tests[] = array('pàge',false,'pàge');
96        $tests[] = array('pagĖ',false,'pagė');
97        $tests[] = array('pagĒēĔĕĖėĘęĚě',false,'pagēēĕĕėėęęěě');
98        $tests[] = array('ښ',false,'ښ');
99        $tests[] = array('ښ侧化并곦ঝഈβ',false,'ښ侧化并곦ঝഈβ');
100
101        foreach($tests as $test){
102            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
103        }
104    }
105
106    function test_deaccent_romanize(){
107        // we test multiple cases here
108        // format: $id, $ascii, $correct_output
109        $tests   = array();
110
111        global $conf;
112        $conf['sepchar'] = '_';
113        $conf['deaccent'] = 2;
114
115        $tests[] = array('pàge',false,'page');
116        $tests[] = array('pagĖ',false,'page');
117        $tests[] = array('pagĒēĔĕĖėĘęĚě',false,'pageeeeeeeeee');
118        $tests[] = array('ښ',false,'ښ');
119        $tests[] = array('ښ侧化并곦ঝഈβ',false,'ښ侧化并곦ঝഈβ');
120
121        foreach($tests as $test){
122            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
123        }
124    }
125
126    function test_deaccent_ascii(){
127        // we test multiple cases here
128        // format: $id, $ascii, $correct_output
129        $tests   = array();
130
131        global $conf;
132        $conf['sepchar'] = '_';
133        $conf['deaccent'] = 0;
134
135        $tests[] = array('pàge',true,'page');
136        $tests[] = array('pagĖ',true,'page');
137        $tests[] = array('pagĒēĔĕĖėĘęĚě',true,'pageeeeeeeeee');
138        $tests[] = array('ښ',true,'');
139        $tests[] = array('ښ侧化并곦ঝഈβ',true,'');
140
141        foreach($tests as $test){
142            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
143        }
144
145        $conf['deaccent'] = 1;
146
147        foreach($tests as $test){
148            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
149        }
150
151        $conf['deaccent'] = 2;
152
153        foreach($tests as $test){
154            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
155        }
156    }
157
158}
159//Setup VIM: ex: et ts=4 :
160