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