1f8369d7dSTobias Sarnowski<?php 2f8369d7dSTobias Sarnowski 3*24486f8cSAndreas Gohrclass init_clean_id_test extends DokuWikiTest 4*24486f8cSAndreas Gohr{ 5f8369d7dSTobias Sarnowski 6*24486f8cSAndreas Gohr /** @inheritDoc */ 7*24486f8cSAndreas Gohr function teardown() 8*24486f8cSAndreas Gohr { 9f8369d7dSTobias Sarnowski global $cache_cleanid; 10f8369d7dSTobias Sarnowski $cache_cleanid = array(); 11f8369d7dSTobias Sarnowski } 12f8369d7dSTobias Sarnowski 13*24486f8cSAndreas Gohr /** 14*24486f8cSAndreas Gohr * DataProvider 15*24486f8cSAndreas Gohr * 16*24486f8cSAndreas Gohr * @return Generator|array 17*24486f8cSAndreas Gohr * @see testCleanId 18*24486f8cSAndreas Gohr */ 19*24486f8cSAndreas Gohr public function provideTestData() 20*24486f8cSAndreas Gohr { 21*24486f8cSAndreas Gohr // input, expected, optional options array 22*24486f8cSAndreas Gohr $tests = [ 23*24486f8cSAndreas Gohr ['page', 'page'], 24*24486f8cSAndreas Gohr ['pa_ge', 'pa_ge'], 25*24486f8cSAndreas Gohr ['pa%ge', 'pa_ge'], 26*24486f8cSAndreas Gohr ['pa#ge', 'pa_ge'], 27*24486f8cSAndreas Gohr ['pàge', 'page'], 28*24486f8cSAndreas Gohr ['pagĖ', 'page'], 29*24486f8cSAndreas Gohr ['pa$%^*#ge', 'pa_ge'], 30*24486f8cSAndreas Gohr ['*page*', 'page'], 31*24486f8cSAndreas Gohr ['ښ', 'ښ'], 32*24486f8cSAndreas Gohr ['päge', 'paege'], 33*24486f8cSAndreas Gohr ['foo bar', 'foo_bar'], 34*24486f8cSAndreas Gohr ['PÄGÖ', 'paegoe'], 35*24486f8cSAndreas Gohr ['Faß', 'fass'], 36*24486f8cSAndreas Gohr ['ښ侧化并곦 β', 'ښ侧化并곦_β'], 37*24486f8cSAndreas Gohr ['page:page', 'page:page'], 38*24486f8cSAndreas Gohr ['page;page', 'page:page'], 39*24486f8cSAndreas Gohr ['page:page 1.2', 'page:page_1.2'], 40*24486f8cSAndreas Gohr ['page._#!', 'page'], 41*24486f8cSAndreas Gohr ['._#!page', 'page'], 42*24486f8cSAndreas Gohr ['page._#!page', 'page._page'], 43*24486f8cSAndreas Gohr ['ns._#!:page', 'ns:page'], 44*24486f8cSAndreas Gohr ['ns:._#!page', 'ns:page'], 45*24486f8cSAndreas Gohr ['ns._#!ns:page', 'ns._ns:page'], 46*24486f8cSAndreas Gohr ['ns_:page', 'ns:page'], 47*24486f8cSAndreas Gohr ['page...page', 'page...page'], 48*24486f8cSAndreas Gohr ['page---page', 'page---page'], 49*24486f8cSAndreas Gohr ['page___page', 'page_page'], 50*24486f8cSAndreas Gohr ['page_-.page', 'page_-.page'], 51*24486f8cSAndreas Gohr [':page', 'page'], 52*24486f8cSAndreas Gohr [':ns:page', 'ns:page'], 53*24486f8cSAndreas Gohr ['page:', 'page'], 54*24486f8cSAndreas Gohr ['ns:page:', 'ns:page'], 55f8369d7dSTobias Sarnowski 56*24486f8cSAndreas Gohr // use-slash handling 57*24486f8cSAndreas Gohr ['page/page', 'page_page', ['useslash' => 0]], 58*24486f8cSAndreas Gohr ['page/page', 'page:page', ['useslash' => 1]], 59*24486f8cSAndreas Gohr 60*24486f8cSAndreas Gohr // different sep-char 61*24486f8cSAndreas Gohr ['pa-ge', 'pa-ge', ['sepchar' => '-']], 62*24486f8cSAndreas Gohr ['pa%ge', 'pa-ge', ['sepchar' => '-']], 63*24486f8cSAndreas Gohr 64*24486f8cSAndreas Gohr // no deaccenting 65*24486f8cSAndreas Gohr ['pàge', 'pàge', ['deaccent' => 0]], 66*24486f8cSAndreas Gohr ['pagĖ', 'pagė', ['deaccent' => 0]], 67*24486f8cSAndreas Gohr ['pagĒēĔĕĖėĘęĚě', 'pagēēĕĕėėęęěě', ['deaccent' => 0]], 68*24486f8cSAndreas Gohr ['ښ', 'ښ', ['deaccent' => 0]], 69*24486f8cSAndreas Gohr ['ښ侧化并곦ঝഈ', 'ښ侧化并곦ঝഈ', ['deaccent' => 0]], 70*24486f8cSAndreas Gohr 71*24486f8cSAndreas Gohr // romanize 72*24486f8cSAndreas Gohr ['pàge', 'page', ['deaccent' => 2]], 73*24486f8cSAndreas Gohr ['pagĖ', 'page', ['deaccent' => 2]], 74*24486f8cSAndreas Gohr ['pagĒēĔĕĖėĘęĚě', 'pageeeeeeeeee', ['deaccent' => 2]], 75*24486f8cSAndreas Gohr ['ښ', 'ښ', ['deaccent' => 2]], 76*24486f8cSAndreas Gohr ['ښ侧化并곦ঝഈ', 'ښ侧化并곦ঝഈ', ['deaccent' => 2]], 77*24486f8cSAndreas Gohr 78*24486f8cSAndreas Gohr // deaccent and force ascii 79*24486f8cSAndreas Gohr ['pàge', 'page', ['deaccent' => 1, 'ascii' => true]], 80*24486f8cSAndreas Gohr ['pagĖ', 'page', ['deaccent' => 1, 'ascii' => true]], 81*24486f8cSAndreas Gohr ['pagĒēĔĕĖėĘęĚě', 'pageeeeeeeeee', ['deaccent' => 1, 'ascii' => true]], 82*24486f8cSAndreas Gohr ['ښ', '', ['deaccent' => 1, 'ascii' => true]], 83*24486f8cSAndreas Gohr ['ښ侧化并곦ঝഈ', '', ['deaccent' => 1, 'ascii' => true]], 84*24486f8cSAndreas Gohr 85*24486f8cSAndreas Gohr // romanize and force ascii 86*24486f8cSAndreas Gohr ['pàge', 'page', ['deaccent' => 2, 'ascii' => true]], 87*24486f8cSAndreas Gohr ['pagĖ', 'page', ['deaccent' => 2, 'ascii' => true]], 88*24486f8cSAndreas Gohr ['pagĒēĔĕĖėĘęĚě', 'pageeeeeeeeee', ['deaccent' => 2, 'ascii' => true]], 89*24486f8cSAndreas Gohr ['ښ', '', ['deaccent' => 2, 'ascii' => true]], 90*24486f8cSAndreas Gohr ['ښ侧化并곦ঝഈ', '', ['deaccent' => 2, 'ascii' => true]], 91*24486f8cSAndreas Gohr ]; 92*24486f8cSAndreas Gohr 93*24486f8cSAndreas Gohr foreach ($tests as $test) { 94*24486f8cSAndreas Gohr // defaults 95*24486f8cSAndreas Gohr $sepchar = $test[2]['sepchar'] ?: '_'; 96*24486f8cSAndreas Gohr $deaccent = isset($test[2]['deaccent']) ? $test[2]['deaccent'] : 1; 97*24486f8cSAndreas Gohr $ascii = $test[2]['ascii'] ?: false; 98*24486f8cSAndreas Gohr 99*24486f8cSAndreas Gohr // unless set, test both useslash settings 100*24486f8cSAndreas Gohr if (isset($test[2]['useslash'])) { 101*24486f8cSAndreas Gohr yield([$test[0], $test[1], $ascii, $sepchar, $deaccent, $test[2]['useslash']]); 102*24486f8cSAndreas Gohr } else { 103*24486f8cSAndreas Gohr yield([$test[0], $test[1], $ascii, $sepchar, $deaccent, 0]); 104*24486f8cSAndreas Gohr yield([$test[0], $test[1], $ascii, $sepchar, $deaccent, 1]); 105*24486f8cSAndreas Gohr } 106*24486f8cSAndreas Gohr } 107*24486f8cSAndreas Gohr } 108*24486f8cSAndreas Gohr 109*24486f8cSAndreas Gohr /** 110*24486f8cSAndreas Gohr * @dataProvider provideTestData 111*24486f8cSAndreas Gohr * @param string $input 112*24486f8cSAndreas Gohr * @param string $expected 113*24486f8cSAndreas Gohr * @param bool $ascii 114*24486f8cSAndreas Gohr * @param string $sepchar 115*24486f8cSAndreas Gohr * @param int $deaccent 116*24486f8cSAndreas Gohr * @param int $useslash 117*24486f8cSAndreas Gohr */ 118*24486f8cSAndreas Gohr function testCleanId($input, $expected, $ascii, $sepchar, $deaccent, $useslash) 119*24486f8cSAndreas Gohr { 120f8369d7dSTobias Sarnowski // set dokuwiki defaults 121f8369d7dSTobias Sarnowski global $conf; 122*24486f8cSAndreas Gohr $conf['sepchar'] = $sepchar; 123*24486f8cSAndreas Gohr $conf['deaccent'] = $deaccent; 124*24486f8cSAndreas Gohr $conf['useslash'] = $useslash; 125f8369d7dSTobias Sarnowski 126*24486f8cSAndreas Gohr $result = cleanID($input, $ascii); 127*24486f8cSAndreas Gohr $this->assertEquals($expected, $result); 128f8369d7dSTobias Sarnowski } 129f8369d7dSTobias Sarnowski 130f8369d7dSTobias Sarnowski 131f8369d7dSTobias Sarnowski 132*24486f8cSAndreas Gohr function test_caching_ascii() 133*24486f8cSAndreas Gohr { 13430f3bd15SMichael Grosse global $conf; 13530f3bd15SMichael Grosse $conf['deaccent'] = 0; 13630f3bd15SMichael Grosse $this->assertEquals('pàge', cleanID('pàge', false)); 13730f3bd15SMichael Grosse $this->assertEquals('page', cleanID('pàge', true)); 13830f3bd15SMichael Grosse 13930f3bd15SMichael Grosse $this->assertEquals('page', cleanID('pagĖ', true)); 14030f3bd15SMichael Grosse $this->assertEquals('pagė', cleanID('pagĖ', false)); 14130f3bd15SMichael Grosse } 14230f3bd15SMichael Grosse 143f8369d7dSTobias Sarnowski} 144