[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> pageutils_clean_id.test.php (source)

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