diff options
author | Christian Schneider | 2007-10-11 00:39:30 +0000 |
---|---|---|
committer | Christian Schneider | 2007-10-11 00:39:30 +0000 |
commit | 35fe33f7364329dacf415c950bff01b6de9ef88e (patch) | |
tree | b0e6b018b50038ca20266723c53750268f508df5 /tests | |
parent | 1f95711ff3e9697cd85a54545ab42e5fd3611317 (diff) | |
download | itools-35fe33f7364329dacf415c950bff01b6de9ef88e.tar.gz itools-35fe33f7364329dacf415c950bff01b6de9ef88e.tar.bz2 itools-35fe33f7364329dacf415c950bff01b6de9ef88e.zip |
Populated release branch
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/it.t | 204 | ||||
-rwxr-xr-x | tests/it_html.t | 99 | ||||
-rwxr-xr-x | tests/it_url.t | 70 | ||||
-rwxr-xr-x | tests/it_xml.t | 70 | ||||
-rwxr-xr-x | tests/itjs.t | 44 |
5 files changed, 487 insertions, 0 deletions
diff --git a/tests/it.t b/tests/it.t new file mode 100755 index 0000000..e399c72 --- /dev/null +++ b/tests/it.t @@ -0,0 +1,204 @@ +#!/www/server/bin/php -qC +<?php + +# Tests for it.class + +require 'searchlib/search_test.class'; + +function match( $regex, $string, $exp, $name ) +{ + $GLOBALS['TEST_MORE_LEVEL'] = 1; + $pass = is( it::match( $regex, $string ), $exp, $name ); + if( !$pass ) { + diag( " regex given: $regex" ); + diag( " regex converted: " . it::convertregex( $regex ) ); + } + $GLOBALS['TEST_MORE_LEVEL'] = 0; +} + +match( + 'b', 'aaaabaaaa', + 'b', + 'simple regex' + ); +match( + 'a/b', ' a/b ', + 'a/b', + 'regex with /' +); +match( + 'aa(bb)aa(cc)aa(dd)qq', 'aabbaaccaaddqq', + array( 'bb', 'cc', 'dd' ), + 'return array of captures' + ); +match( + '\bblah\b', ' blah ', + 'blah', + 'match \b at spaces' + ); +match( + '\bblah\b', 'blah', + 'blah', + 'match \b at end of string' + ); +match( + '\bblah\b', 'ablahc', + false, + 'don\'t match \b at word chars' + ); +match( + '\bblah\b', 'Üblahä', + false, + 'don\'t match \b at umlaute in latin1' + ); +match( + '\Bblah\B', ' blah ', + false, + 'don\'t match \B at spaces' + ); +match( + '\Bblah\B', 'blah', + false, + 'don\'t match \B at end of string' + ); +match( + '\Bblah\B', 'ablahc', + 'blah', + 'match \B at word chars' + ); +match( + '\Bblah\B', 'Üblahä', + 'blah', + 'match \B at umlaute in latin1' + ); +match( + '\w+', ' |#Üblahä ', + 'Üblahä', + 'include umlaute in \w' + ); +match( + '\W+', ' |#Üblahä ', + ' |#', + 'don\'t include umlaute in \W' + ); + +eval( '$escapedwordregex = "' . it::convertregex( '\w' ) . '";' ); +$escapedwordregex = preg_replace( '|[\\\\/]|', '', $escapedwordregex ); + +match( + '\\\\w+', $escapedwordregex, + false, + 'don\'t parse \w in \\\\w at beginning (no match)' + ); +match( + 'aaa\\\\w+', ' aaa\www ', + 'aaa\www', + 'don\'t parse \w in \\\\w at beginning (match)' + ); +match( + 'aaa\\\\w+', 'aaa' . $escapedwordregex, + false, + 'don\'t parse \w in \\\\w after chars (no match)' + ); +match( + 'aaa\\\\w+', ' aaa\www ', + 'aaa\www', + 'don\'t parse \w in \\\\w after chars (match)' + ); +match( + '\\\\\\\\w+', '\\' . $escapedwordregex, + false, + 'don\'t parse \w in \\\\\\\w (no match)' + ); +match( + '\\\\\\\\w+', ' \\\\www ', + '\\\\www', + 'don\'t parse \\\\\\\\w as \w (match)' + ); +match( + '[\w]+', '[[[]]]---', + false, + 'replace \w in [\w] correctly (no match)' + ); +match( + '[\w]+', ' \\\\aword[[[]]] ', + 'aword', + 'replace \w in [\w] correctly (match)' + ); +match( + '[\\\\w]+', ' blabergna ', + false, + 'don\'t parse \w in [\\\\w] (no match)' + ); +match( + '[\\\\w]+', ' \\\\worda[[[]', + '\\\\w', + 'don\'t parse \w in [\\\\w] (match)' + ); +match( + '[a\W]+', 'bbbbbbb a a%$+ accccc', + ' a a%$+ a', + '\W in []' + ); +match( + '\\\\\\w+', ' \Üblahä ', + '\Üblahä', + 'parse \w in \\\\\\w at beginning' + ); +match( + 'aaa\\\\\\w+', ' aaa\Üblahä ', + 'aaa\Üblahä', + 'parse \w in \\\\\\w after chars' + ); +is( + it::replace( + array( + 'regex1' => 'repl1', + 'regex2' => 'repl2', + 'regex3' => 'repl3' ), + 'regex2 regex1 regex3' ), + 'repl2 repl1 repl3', + 'test tr regex function' + ); +is( + it::match( '\w+', 'word1 wörd2 word_3', array('all' => true )), + array( 'word1', 'wörd2', 'word_3' ), + "test match_all function" + ); +match( + 'aBcD', ' aBcD ', + 'aBcD', + "caseinsensitive is default" + ); +match( + 'ö', 'Ö', + 'Ö', + 'match umlaute in latin1 case insensitive' + ); +is( + it::match( 'abc', "aBc", array('casesensitive' => 1 )), + false, + "set case sensitivity by parameter" + ); + +is( + it::match( '\w+', 'word1 wörd2 word_3', array('all' => 1 )), + array( 'word1', 'wörd2', 'word_3' ), + "test all=>1 without captures" + ); +is( + it::match( '\w+\s+(\d+)', 'word1 12 wörd2 3 word_3 4', array('all' => 1 )), + array( '12', '3', '4' ), + "test all=>1 with one capture" + ); +is( + it::match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', array('all' => 1 )), + array( array( 'word1', '12' ), array( 'wörd2', '3' ), array( 'word_3', '4' ) ), + "test all=>1 with captures" + ); +is( + it::match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', array('all' => 1, 'pattern_order' => 1 )), + array( array( 'word1', 'wörd2', 'word_3' ), array( '12', '3', '4' ) ), + "test all=>1,pattern_order=>1" + ); +?> diff --git a/tests/it_html.t b/tests/it_html.t new file mode 100755 index 0000000..cd934be --- /dev/null +++ b/tests/it_html.t @@ -0,0 +1,99 @@ +#!/www/server/bin/php -qC +<?php + +# Tests for html.class + +require 'searchlib/search_test.class'; + +# Traditional html generation +new it_html(array('htmltype' => "html")); + +is( + a(array('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => ""), "bar"), + '<a href="&foo" true empty="">bar</a>', + "tag with attributes" +); + +is( + div(), + "<div></div>\n", + "empty script tag" +); + +is( + img(array('src' => "foo.png")), + '<img src="foo.png">', + "empty link tag" +); + +is( + tag('link'), + "<link>\n", + "empty link tag" +); + +is( + tag('link', "foo"), + "<link>foo</link>\n", + "link tag with data" +); + +# XML generation +unset($GLOBALS['it_html']); +new it_html(array('htmltype' => "xhtml", 'tags' => "xmltest")); + +is( + xmltest(), + "<xmltest />\n", + "empty xmltest tag" +); + +is( + xmltest("foo"), + "<xmltest>foo</xmltest>\n", + "empty xmltest tag" +); + +is( + xmltest(array('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => "")), + '<xmltest href="&foo" true="true" empty="" />' . "\n", + "xmltest tag with attributes" +); + +# Inheriting and extending it_html +class myhtml extends it_html +{ +function myimg($args) +{ + array_unshift($args, array('alt' => "ALT", 'bar' => "BAR")); + + return parent::img($args); +} +} + +unset($GLOBALS['it_html']); +new myhtml(array('htmltype' => "html")); + +is( + myimg(array('src' => "foo.gif", 'alt' => "foo")), + '<img alt="foo" bar="BAR" src="foo.gif">', + "it_html inheritance" +); + +is( + it_html::sanitize(' <p><a href="http://www.flickr.com/people/swisspics/">swisspics</a> posted < < ä & yesterday <b>a <i>photo</i></b> <b><i>tag missmatch</b></i>:</p><br><br /> + +<p><a href="javascript:window.close()" title="Wolken"><img src="http://farm1.static.flickr.com/177/377214376_bcba167a7d_m.jpg" width="240" height="180" alt="Wolken" style="border: 1px solid #ddd;" /></a></p> +'), + ' <a href="http://www.flickr.com/people/swisspics/">swisspics</a> posted < < ä & yesterday a <i>photo</i> <i>tag missmatch</i>:<br /><br /> <p><img src="http://farm1.static.flickr.com/177/377214376_bcba167a7d_m.jpg" alt="" /></p> ', + 'it_html::sanitize tag soup' +); + +is( + U("/foo.html", array('bar' => array('gna' => 42, 'qux' => array('quux' => "<Zürich>", 'gnöp' => "fasel")))), + '/foo.html?bar[gna]=42&bar[qux][quux]=%3CZ%FCrich%3E&bar[qux][gn%F6p]=fasel', + 'U() with nested arrays' +); + + +?> diff --git a/tests/it_url.t b/tests/it_url.t new file mode 100755 index 0000000..bc63bcb --- /dev/null +++ b/tests/it_url.t @@ -0,0 +1,70 @@ +#!/www/server/bin/php -qC +<?php + +# Tests for url.class, currently only constructor's parser + +require 'searchlib/search_test.class'; + +# Create object and parse url +$url = new it_url('HTTP://falcon:joshua@www.Relog.CH:80/default.asp'); + +plan(9); + +is( + $url->url, + 'http://www.relog.ch/', + '$url->url' +); + +is( + $url->protocol, + 'http', + '$url->protocol' +); + +is( + $url->hostname, + 'relog.ch', + '$url->hostname' +); + +is( + $url->realhostname, + 'www.relog.ch', + '$url->realhostname' +); + +is( + $url->port, + 80, + '$url->port' +); + +is( + $url->path, + '', + '$url->path' +); + +is( + $url->user, + 'falcon', + '$url->user' +); + +is( + $url->pass, + 'joshua', + '$url->pass' +); + +# and now check for path +$url = new it_url('HTTP://falcon:joshua@www.Relog.CH:80/foo/bar.html'); + +is( + $url->path, + 'foo/bar.html', + '$url->path' +); + +?> diff --git a/tests/it_xml.t b/tests/it_xml.t new file mode 100755 index 0000000..5651fbe --- /dev/null +++ b/tests/it_xml.t @@ -0,0 +1,70 @@ +#!/www/server/bin/php -qC +<?php + +# Tests for xml.class + +require 'searchlib/search_test.class'; + +function match($xmldata, $expected, $name, $prefix = "") +{ + $classname = $prefix ? ($prefix . "_xml") : "it_xml"; + $varname = $prefix . "foo"; + $xml = new $classname("<root>$xmldata</root>"); + + is( + preg_replace('/[#\s]+/', " ", print_r($xml->$varname, true)), + $expected, + $name + ); +} + +match( + '<foo />', + 'foo Object ( ) ', + 'empty tag' +); + +match( + '<foo /><foo />', + 'Array ( [0] => foo Object ( ) [1] => foo Object ( ) ) ', + 'multiple empty tags converted to array' +); + +match( + '<foo title="Zürich">Stüssihofstadt</foo>', + 'foo Object ( [attr] => Array ( [title] => Zürich ) [val] => Stüssihofstadt ) ', + 'simple tag with latin1 content and attribute' +); + +match( + '<foo><ns:a.b.-c ns2:d.e-f="value" /></foo>', + 'foo Object ( [a_b__c] => a_b__c Object ( [attr] => Array ( [d_e_f] => value ) ) ) ', + 'Tags and attributes with name space and special characters' +); + +# Test inheritance +class my_xml extends it_xml +{ + +function my_xml($xmldata) +{ + parent::it_xml($xmldata); + + # Code which should be executed in root and only there + $this->qux = new it_xml; + $this->qux->val = "qux"; + + if (is_object($this->myfoo)) + $this->myfoo->inheritbaseclass = is_a($this->myfoo, "my_xml"); +} + +} + +match( + '<myfoo />', + 'myfoo Object ( [inheritbaseclass] => ) ', + 'Inheritance and constructor (critical for e.g. tel_xmlentry)', + 'my' +); + +?> diff --git a/tests/itjs.t b/tests/itjs.t new file mode 100755 index 0000000..4b4b0c8 --- /dev/null +++ b/tests/itjs.t @@ -0,0 +1,44 @@ +#!/www/server/bin/php -qC +<?php + +# Tests for itjs.class, currently only itjs::serialize() + +require 'searchlib/search_test.class'; + +is( + itjs::serialize(array()), + '[]', + 'empty array' +); + +is( + itjs::serialize(array(0, "0")), + '[0, 0]', + 'number 0' +); + +is( + itjs::serialize(array(null, "", false)), + '["", "", false]', + 'null, empty string, false' +); + +is( + itjs::serialize(array(42, "42", 42.5, "042")), + '[42, 42, "42.5", "042"]', + 'numbers' +); + +is( + itjs::serialize(array('foo' => "bar", "qux", 42 => "quux")), + "{foo:\"bar\",\n'0':\"qux\",\n'42':\"quux\"}", + 'key-value pairs' +); + +is( + itjs::serialize(array('foo' => array('bar' => array("qux", 42)))), + '{foo:{bar:["qux", 42]}}', + 'nested arrays' +); + +?> |