xref: /dokuwiki/_test/tests/inc/pageutils_clean_id.test.php (revision 02ea0357f6a255b0f65c967112e6a6d9ec1fa116)
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
47        $conf['useslash'] = 0;
48        $tests[] = array('page/page',false,'page_page');
49
50        foreach($tests as $test){
51            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
52        }
53
54        $conf['useslash'] = 1;
55        $tests = array();
56        $tests[] = array('page/page',false,'page:page');
57
58        $this->teardown();
59
60        foreach($tests as $test){
61            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
62        }
63    }
64
65    function test_sepchar(){
66        // we test multiple cases here
67        // format: $id, $ascii, $correct_output
68        $tests   = array();
69
70        global $conf;
71        $conf['sepchar'] = '-';
72        $conf['deaccent'] = 1;
73
74        $tests[] = array('pa-ge',false,'pa-ge');
75        $tests[] = array('pa%ge',false,'pa-ge');
76
77        foreach($tests as $test){
78            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
79        }
80    }
81
82    function test_deaccent_keep(){
83        // we test multiple cases here
84        // format: $id, $ascii, $correct_output
85        $tests   = array();
86
87        global $conf;
88        $conf['sepchar'] = '_';
89        $conf['deaccent'] = 0;
90
91        $tests[] = array('pàge',false,'pàge');
92        $tests[] = array('pagĖ',false,'pagė');
93        $tests[] = array('pagĒēĔĕĖėĘęĚě',false,'pagēēĕĕėėęęěě');
94        $tests[] = array('ښ',false,'ښ');
95        $tests[] = array('ښ侧化并곦ঝഈβ',false,'ښ侧化并곦ঝഈβ');
96
97        foreach($tests as $test){
98            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
99        }
100    }
101
102    function test_deaccent_romanize(){
103        // we test multiple cases here
104        // format: $id, $ascii, $correct_output
105        $tests   = array();
106
107        global $conf;
108        $conf['sepchar'] = '_';
109        $conf['deaccent'] = 2;
110
111        $tests[] = array('pàge',false,'page');
112        $tests[] = array('pagĖ',false,'page');
113        $tests[] = array('pagĒēĔĕĖėĘęĚě',false,'pageeeeeeeeee');
114        $tests[] = array('ښ',false,'ښ');
115        $tests[] = array('ښ侧化并곦ঝഈβ',false,'ښ侧化并곦ঝഈβ');
116
117        foreach($tests as $test){
118            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
119        }
120    }
121
122    function test_deaccent_ascii(){
123        // we test multiple cases here
124        // format: $id, $ascii, $correct_output
125        $tests   = array();
126
127        global $conf;
128        $conf['sepchar'] = '_';
129        $conf['deaccent'] = 0;
130
131        $tests[] = array('pàge',true,'page');
132        $tests[] = array('pagĖ',true,'page');
133        $tests[] = array('pagĒēĔĕĖėĘęĚě',true,'pageeeeeeeeee');
134        $tests[] = array('ښ',true,'');
135        $tests[] = array('ښ侧化并곦ঝഈβ',true,'');
136
137        foreach($tests as $test){
138            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
139        }
140
141        $conf['deaccent'] = 1;
142
143        foreach($tests as $test){
144            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
145        }
146
147        $conf['deaccent'] = 2;
148
149        foreach($tests as $test){
150            $this->assertEquals(cleanID($test[0],$test[1]),$test[2]);
151        }
152    }
153
154}
155//Setup VIM: ex: et ts=4 :
156