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