00001 <?php
00002
00003 lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
00004 lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
00006
00012 class Textfilter_Test extends LifeTypeTestCase
00013 {
00014 function setup()
00015 {
00016 $this->tf = new Textfilter();
00017 }
00018
00022 function testSlugify()
00023 {
00024
00025 $config =& Config::getConfig();
00026 $sep = $config->getValue( "urlize_word_separator", URLIZE_WORD_SEPARATOR_DEFAULT );
00027
00028 $tests = Array(
00029 "simple" => "simple",
00030 "two words" => "two{$sep}words",
00031 "two spaces" => "two{$sep}spaces",
00032 " leadingblanks" => "leadingblanks",
00033 "trailingblanks " => "trailingblanks",
00034 "!@#extraseparators'''" => "extraseparators",
00035 "<a>html</a><b>is</b><h1>not</h1><p>allowed</p>"
00036 => "htmlisnotallowed",
00037 "unclosed < html</a><b >shouldn't </b>be<h1> <p>stripped</p>"
00038 => "unclosed{$sep}htmlshouldn{$sep}t{$sep}be{$sep}stripped",
00039 "SOME uppercase CHARAcTERS" => "some{$sep}uppercase{$sep}characters" );
00040
00041
00042 foreach( $tests as $input => $output ) {
00043 $result = $this->tf->slugify( $input );
00044 $this->assertEquals( $output, $result );
00045 }
00046 }
00047
00051 function testDomainize()
00052 {
00053
00054 $config =& Config::getConfig();
00055 $sep = $config->getValue( "urlize_word_separator", URLIZE_WORD_SEPARATOR_DEFAULT );
00056
00057
00058 $tests = Array(
00059 "TesT BlOg" => "test{$sep}blog",
00060 "test-blog" => "test{$sep}blog",
00061 "test_blog" => "test{$sep}blog",
00062 "test.blog" => "test.blog",
00063 "??test//blog" => "test{$sep}blog",
00064 "==================test blog" => "test{$sep}blog",
00065 "this.has.dots_and-hyphens----and spaces " => "this.has.dots{$sep}and{$sep}hyphens{$sep}and{$sep}spaces"
00066 );
00067
00068 foreach( $tests as $input => $output ) {
00069 $result = $this->tf->domainize( $input );
00070 $this->assertEquals( $output, $result, "input was: $input" );
00071 }
00072 }
00073
00077 function testUrlize()
00078 {
00079
00080 $config =& Config::getConfig();
00081 $sep = $config->getValue( "urlize_word_separator", URLIZE_WORD_SEPARATOR_DEFAULT );
00082
00083
00084 $tests = Array(
00085 "teSt blog" => "test{$sep}blog",
00086 "test-blog" => "test-blog",
00087 "test_blog" => "test_blog",
00088 "test.blog" => "test.blog",
00089 "??test//blog" => "test{$sep}blog",
00090 "==================test blog" => "test{$sep}blog",
00091 "this.has.dots_and-hyphens----and spaces " => "this.has.dots_and-hyphens{$sep}and{$sep}spaces",
00092 "multiple__underscores______" => "multiple__underscores______"
00093 );
00094
00095 foreach( $tests as $input => $output ) {
00096 $result = $this->tf->urlize( $input );
00097 $this->assertEquals( $output, $result, "input was: $input" );
00098 }
00099 }
00100
00101
00105 function testHtmlDecode()
00106 {
00107
00108
00109 $tests = Array(
00110 "&" => "&",
00111 "test" => "test",
00112 "áé" => "αι",
00113 "äÜ" => "δά"
00114 );
00115
00116 foreach( $tests as $input => $output ) {
00117
00118 $this->assertEquals( $output, TextFilter::htmlDecode( $input ), "Error htmlDecode()-ing string: $input" );
00119
00120 $this->assertEquals( $output, Textfilter::htmlDecode( TextFilter::filterHTMLEntities( $output )));
00121 }
00122 }
00123 }
00124 ?>