Skip to content

Commit

Permalink
transformed untf8_ test to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-mel committed Apr 3, 2012
1 parent 65a30a9 commit 2807b5c
Show file tree
Hide file tree
Showing 8 changed files with 23,238 additions and 0 deletions.
78 changes: 78 additions & 0 deletions _testing/unittests/inc/utf8_correctidx.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
// use no mbstring help here
if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1);
require_once DOKU_INC.'inc/utf8.php';

class utf8_correctidx_test extends PHPUnit_Framework_TestCase {


function test_singlebyte(){
// we test multiple cases here - format: in, offset, length, out
$tests = array();

// single byte, should return current index
$tests[] = array('aaживπά우리をあöä',0,false,0);
$tests[] = array('aaживπά우리をあöä',1,false,1);
$tests[] = array('aaживπά우리をあöä',1,true,1);

foreach($tests as $test){
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]);
}
}

function test_twobyte(){
// we test multiple cases here - format: in, offset, length, out
$tests = array();

// two byte, should move to boundary, expect even number
$tests[] = array('aaживπά우리をあöä',2,false,2);
$tests[] = array('aaживπά우리をあöä',3,false,2);
$tests[] = array('aaживπά우리をあöä',4,false,4);

$tests[] = array('aaживπά우리をあöä',2,true,2);
$tests[] = array('aaживπά우리をあöä',3,true,4);
$tests[] = array('aaживπά우리をあöä',4,true,4);

foreach($tests as $test){
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]);
}
}

function test_threebyte(){
// we test multiple cases here - format: in, offset, length, out
$tests = array();

// three byte, should move to boundary 10 or 13
$tests[] = array('aaживπά우리をあöä',10,false,10);
$tests[] = array('aaживπά우리をあöä',11,false,10);
$tests[] = array('aaживπά우리をあöä',12,false,10);
$tests[] = array('aaживπά우리をあöä',13,false,13);

$tests[] = array('aaживπά우리をあöä',10,true,10);
$tests[] = array('aaживπά우리をあöä',11,true,13);
$tests[] = array('aaживπά우리をあöä',12,true,13);
$tests[] = array('aaживπά우리をあöä',13,true,13);

foreach($tests as $test){
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]);
}
}

function test_bounds(){
// we test multiple cases here - format: in, offset, length, out
$tests = array();

// bounds checking
$tests[] = array('aaживπά우리をあöä',-2,false,0);
$tests[] = array('aaживπά우리をあöä',128,false,29);

$tests[] = array('aaживπά우리をあöä',-2,true,0);
$tests[] = array('aaживπά우리をあöä',128,true,29);

foreach($tests as $test){
$this->assertEquals(utf8_correctIdx($test[0],$test[1],$test[2]),$test[3]);
}
}

}
//Setup VIM: ex: et ts=4 :
72 changes: 72 additions & 0 deletions _testing/unittests/inc/utf8_html.test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

require_once DOKU_INC.'inc/utf8.php';

// use no mbstring help here
if(!defined('UTF8_NOMBSTRING')) define('UTF8_NOMBSTRING',1);

class utf8_html_test extends PHPUnit_Framework_TestCase {

function test_from_1byte(){
$in = 'a';
$out = 'a';
$this->assertEquals(utf8_tohtml($in),$out);
}

function test_from_2byte(){
$in = "\xc3\xbc";
$out = '&#252;';
$this->assertEquals(utf8_tohtml($in),$out);
}

function test_from_3byte(){
$in = "\xe2\x99\x8a";
$out = '&#x264a;';
$this->assertEquals(utf8_tohtml($in),$out);
}

function test_from_4byte(){
$in = "\xf4\x80\x80\x81";
$out = '&#x100001;';
$this->assertEquals(utf8_tohtml($in),$out);
}

function test_to_1byte(){
$out = 'a';
$in = 'a';
$this->assertEquals(utf8_unhtml($in),$out);
}

function test_to_2byte(){
$out = "\xc3\xbc";
$in = '&#252;';
$this->assertEquals(utf8_unhtml($in),$out);
}

function test_to_3byte(){
$out = "\xe2\x99\x8a";
$in = '&#x264a;';
$this->assertEquals(utf8_unhtml($in),$out);
}

function test_to_4byte(){
$out = "\xf4\x80\x80\x81";
$in = '&#x100001;';
$this->assertEquals(utf8_unhtml($in),$out);
}

function test_without_entities(){
$out = '&amp;#38;&amp;#38;';
$in = '&amp;#38;&#38;amp;#38;';
$this->assertEquals(utf8_unhtml($in),$out);
}

function test_with_entities(){
$out = '&#38;&amp;#38;';
$in = '&amp;#38;&#38;amp;#38;';
$this->assertEquals(utf8_unhtml($in,HTML_ENTITIES),$out);
}

}

//Setup VIM: ex: et ts=4 :
Loading

0 comments on commit 2807b5c

Please sign in to comment.