From d59a4921188753dbe4c0161081755a28112c3ef6 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Thu, 22 Mar 2012 18:18:42 +0000 Subject: Branch itools/devel-utf8 created --- devel-utf8/tests/autoprepend.t | 38 ++++++ devel-utf8/tests/exec.t | 23 ++++ devel-utf8/tests/getopt.t | 29 +++++ devel-utf8/tests/it.t | 285 +++++++++++++++++++++++++++++++++++++++++ devel-utf8/tests/it_dbi.t | 254 ++++++++++++++++++++++++++++++++++++ devel-utf8/tests/it_html.t | 159 +++++++++++++++++++++++ devel-utf8/tests/it_text.t | 18 +++ devel-utf8/tests/it_url.t | 135 +++++++++++++++++++ devel-utf8/tests/it_xml.t | 120 +++++++++++++++++ devel-utf8/tests/itjs.t | 50 ++++++++ 10 files changed, 1111 insertions(+) create mode 100755 devel-utf8/tests/autoprepend.t create mode 100755 devel-utf8/tests/exec.t create mode 100755 devel-utf8/tests/getopt.t create mode 100755 devel-utf8/tests/it.t create mode 100755 devel-utf8/tests/it_dbi.t create mode 100755 devel-utf8/tests/it_html.t create mode 100755 devel-utf8/tests/it_text.t create mode 100755 devel-utf8/tests/it_url.t create mode 100755 devel-utf8/tests/it_xml.t create mode 100755 devel-utf8/tests/itjs.t (limited to 'devel-utf8/tests') diff --git a/devel-utf8/tests/autoprepend.t b/devel-utf8/tests/autoprepend.t new file mode 100755 index 0000000..bf40605 --- /dev/null +++ b/devel-utf8/tests/autoprepend.t @@ -0,0 +1,38 @@ +#!/www/server/bin/php -qC +statictext = array( + '_' => array("de" => "Deutsch", "en" => "English"), + 'foo' => array("de" => "bar {v1}", "en" => "qux {v1}"), +); + +is( + T('foo'), + "bar {v1}", + "simple T()" +); + +is( + T('foo', 'en'), + "qux {v1}", + "simple T() with language" +); + +is( + T('foo', array('v1' => "gna "gna "gna 'gna')), "gna\n", "exec with argument"); +is(it::shell_command("echo {arg}", array('arg' => 'gna07,-:blah')), "echo gna07,-:blah", "don't quote arguments with only whitelistes characters"); +is(it::shell_command("echo {arg}", array('arg' => '2>&1')), "echo '2>&1'", "quote arguments with dangerous characters"); +is(it::shell_command("echo {arg}", array('arg' => '')), "echo ''", "quote empty arguments"); + +foreach (array("", "C", "de_CH", "de_CH.utf8") as $locale) { + setlocale(LC_ALL, $locale); + $arg = "preüpost"; + if (it::match('utf8', $locale)) + $arg = utf8_encode($arg); + is(it::exec("echo " . $arg), $arg . "\n", "exec with umlaut (locale '$locale')"); + is(it::exec("echo {arg}", array('arg' => $arg)), $arg . "\n", "exec with argument and umlaut (locale '$locale')"); +} + +is(it::_exec_quotevalue(""), "''", "empty arg needs quotes"); +is(it::_exec_quotevalue("*"), "'*'", "special chars need quotes"); +is(it::_exec_quotevalue("Aabcdef0123456789"), "Aabcdef0123456789", "simple case. tel:debug_getdata needs unquoted vals"); diff --git a/devel-utf8/tests/getopt.t b/devel-utf8/tests/getopt.t new file mode 100755 index 0000000..7a84588 --- /dev/null +++ b/devel-utf8/tests/getopt.t @@ -0,0 +1,29 @@ +#!/www/server/bin/php -qC + "blah gnaber", " (umlaute)" => "pre üäpost") as $variant => $testarg) { + getopt_ok(array('-a', $testarg), $testarg, "Short version" . $variant); + getopt_ok(array('--argument', $testarg), $testarg, "Long version with space" . $variant); + getopt_ok(array("--argument=$testarg"), $testarg, "Long version with equal" . $variant); +} + +$_SERVER['argv'] = array('doesnotexist.php', '-0'); +$zero_opts = it::getopt($GLOBALS['usage']); +ok($zero_opts['zero'], '-0'); + diff --git a/devel-utf8/tests/it.t b/devel-utf8/tests/it.t new file mode 100755 index 0000000..1a308ec --- /dev/null +++ b/devel-utf8/tests/it.t @@ -0,0 +1,285 @@ +#!/www/server/bin/php -qC + '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(utf8_encode('aöBÜ'), utf8_encode("AÖbü"), array('utf8' => true)), + utf8_encode('AÖbü'), + "match utf-8 umlaute in case insensitive" +); + +$oldcharset = ini_get('default_charset'); +ini_set('default_charset', 'utf-8'); +match( + utf8_encode('aöBÜ'), utf8_encode('AÖbü'), + utf8_encode('AÖbü'), + "match utf-8 umlaute in case insensitive using default_charset" +); +is( + it::match('aöBÜ', 'AÖbü', array('utf8' => false)), + 'AÖbü', + "non-utf-8 override with default_charset=utf-8" +); +match( + '\w+', utf8_encode('Müller'), + utf8_encode('Müller'), + '\w matches umlaut in utf-8 mode' +); +match( + 'M.ller', utf8_encode('Müller'), + utf8_encode('Müller'), + '. matches umlaut in utf-8 mode' +); +ini_set('default_charset', $oldcharset); + +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" + ); + +is(it::replace(array('a' => "1", 'b' => "2"), "ab"), "12"); +is(it::replace(array('!' => "x"), "!"), "x"); +is(it::replace(array('\w' => "x"), "oö"), "xx"); +is(it::replace(array('[[:alpha:]]' => "x"), "ö"), "x"); +is(it::replace(array('\w' => "x", '#' => "!"), "#ö"), "!x"); +is(it::replace(array('#' => "!", '\w' => "x"), "#ö"), "!x"); +is(it::replace(array('ö' => "x"), "Ö"), "x"); +is(it::replace(array('a' => "1"), "aaa", array('limit' => 1)), "1aa"); + +# it::filter_keys tests + +$data = array('a' => 1, 'b' => 2, 'c' => 3); +is(it::filter_keys($data, 'a'), array('a' => 1), "select one key"); +is(it::filter_keys($data, array('a', 'b')), array('a' => 1, 'b' => 2), "select two keys with array"); +is(it::filter_keys($data, 'a,b'), array('a' => 1, 'b' => 2), "select two keys with string"); +is( + array_keys(it::filter_keys($data, 'b,a')), + array('a', 'b'), + "keep order of data array per default"); +is( + array_keys(it::filter_keys($data, 'b,a', array('reorder' => true))), + array('b', 'a'), + "reorder with given key order"); + +# it::date tests + +is(it::date('date', '2011-10-25'), '25.10.2011', 'parse date string with strtotime'); +is(it::date('date', '2011-10-25 + 3 days'), '28.10.2011', 'some date arithmetic'); +is(it::date('datetime', time()), it::date('datetime'), 'recognize int as timestamp'); +is(it::date('datetime', time()*1.0), it::date('datetime'), 'recognize float as timestamp'); +is(it::date('datetime', time() . ''), it::date('datetime'), 'recognize digit string as timestamp'); +is(it::date('datetime', '@' . time()), it::date('datetime'), 'recognize strtotime timestamp format'); +is(it::date('datetime', 10), it::date('datetime', "10"), 'numeric and string give same result'); +is(it::date('datetime', 10.0), it::date('datetime', "10"), '... as long as num is properly truncated'); +is(it::date('datetime', 10.5), it::date('datetime', "10"), '... with one digit after point'); +is(it::date('datetime', 10.56), it::date('datetime', "10"), '... with two digits after point'); +is(it::date('datetime', 1000000), it::date('datetime', "1000000"), '... large nummer'); +is(it::date('datetime', 1000000.543), it::date('datetime', "1000000"), '... large nummer and point'); +is(it::date('time', "10.5"), "10:05", 'interpret string with points with strtotime'); +is(it::date('time', "10.05"), "10:05", 'interpret string with points with strtotime'); + +?> diff --git a/devel-utf8/tests/it_dbi.t b/devel-utf8/tests/it_dbi.t new file mode 100755 index 0000000..4a58188 --- /dev/null +++ b/devel-utf8/tests/it_dbi.t @@ -0,0 +1,254 @@ +#!/www/server/bin/php -qC + "lib_search_ch", 'safety' => 0); +$dbi = new it_dbi($db); +$dbi->query('create temporary table it_dbi_test ( + ID int not null auto_increment, + x int, + foo varchar(42), + primary key(ID) +);'); + +$record = new it_dbi($db + array('table' => "it_dbi_test")); + +$record->insert(array('x' => 42, 'foo' => null)); +$record->insert(array('foo' => "bar")); +$record->insert(array('x' => 64738, 'foo' => "q'uux")); + +is( + $record->ID, + 3, + "auto_increment" +); + +$record->read(1); +is( + array($record->_key, $record->x, $record->foo), + array(1, 42, null), + "read" +); + +is( + $record->select(), + 3, + "select without parameters select all" +); + +is( + $record->select(array('foo <>' => ""), "LIMIT 1"), + 1, + "select with multiple parameters (LIMIT part)" +); +is( + $record->foo, + "bar", + "select with multiple parameters (foo part)" +); +is( + $record->select(array('ID IN' => array(2,3))), + 2, + "select with IN" +); +is( + $record->select(array('ID NI' => array(2,3))), + 2, + "select with NI" +); +is( + $record->select(array('ID NOT IN' => array(2,3))), + 1, + "select with NOT IN" +); +is( + $record->select(array('ID IN' => array())), + 0, + "select with empty IN" +); +is( + $record->select(array('ID NOT IN' => array())), + 3, + "select with empty NOT IN" +); + +it_dbi::createclass(array('table' => "it_dbi_test", 'forcecreate' => true)); + +$record = new it_dbi_test; +is( + $record->x, + null, + "constructor of created class without argument" +); + +$record = new it_dbi_test(2); +is( + $record->ID, + 2, + "constructor of created class with id parameter" +); + +$record = new it_dbi_test(array('x >' => 0), "ORDER BY x DESC"); +is( + $record->x, + 64738, + "constructor of created class with multiple select parameters" +); + +$record = new it_dbi_test(array('foo' => 'bar')); +is( + $record->ID, + 2, + "constructor of created class with single array parameter" +); + +$record = new it_dbi($db + array('table' => "it_dbi_test")); +is( + $record->x, + null, + "constructor without parameters" +); + +$record = new it_dbi($db + array('table' => "it_dbi_test"), array('x >' => 0), "ORDER BY x DESC"); +is( + $record->x, + 64738, + "constructor with multiple select parameters" +); + +$record->select(array('x' => 64738)); +is( + array($record->_key, $record->x, $record->foo), + array(3, 64738, "q'uux"), + "select" +); + +$record->update(array('x' => 17)); +is( + array($record->_key, $record->x, $record->foo), + array(3, 17, "q'uux"), + "update" +); + +is( + $record->update(array('x' => 18), array('x' => 17)), + 1, + "return affected rows", +); + +is( + $record->update(array('x' => 18), array('x' => 17)), + 0, + "return zero affected rows", +); + +$record->update(array('-x' => 'RAND() * 10')); +isnt( + array($record->_key, $record->x, $record->foo), + array(3, 17, "q'uux"), + "update with function" +); + +$rand = $record->x; +is ( + $record->_set(array('x' => $rand, 'foo' => "bar")), + "SET `foo`='bar'", + 'update: _set optimization' +); + +$record->update(array('foo' => "bar")); +$record->select(array('foo' => "bar")); +$record->iterate(); +is( + array($record->_key, $record->x, $record->foo), + array(2, null, "bar"), + "iterate record 2" +); +$record->update(array('foo' => "qux")); +$record->iterate(); +is( + array($record->_key, $record->x, $record->foo), + array(3, $rand, "bar"), + "iterate record 3" +); +$record->update(array('foo' => "quux")); + +$record->read(2); +is( + array($record->_key, isset($record->x), $record->foo), + array(2, false, "qux"), + "iterate update record 2" +); + +$record->read(3); +is( + array($record->_key, $record->x, $record->foo), + array(3, $rand, "quux"), + "iterate update record 3" +); + +is( + gettype($record->_key) . "/" . gettype($record->x) . "/" . gettype($record->_data['x']) . "/" . gettype($record->foo), + "integer/integer/integer/string", + "automatic type detection" +); + +$count = 0; +foreach (new it_dbi_test as $id => $record) +{ + $count++; + is($record->_key, $id, "Iterator id $id"); +} +is($count, 3, "Iterator without select"); + +$count = 0; +foreach (new it_dbi_test(array('foo <>' => "")) as $id => $record) +{ + $count++; + is($record->_key, $id, "Iterator id $id"); +} +is($count, 2, "Iterator with select"); + +$count = 0; +foreach ($record as $dummy_rec) + $count++; +is($count, 2, "Iterator reused"); + +# Test field localization feature + +$dbi->query('create temporary table it_dbi_testlocalized ( + ID int not null auto_increment, + foobar_de varchar(42), + foobar_fr varchar(42), + primary key(ID) +);'); + +$record = new it_dbi($db + array('table' => "it_dbi_testlocalized")); +$record->insert(array('foobar_de' => "deutsch", 'foobar_fr' => "franz")); +$record->insert(array('foobar_de' => "deutsch2", 'foobar_fr' => "franz2")); + +T_set_language('de'); +$record->select(array()); +$record->iterate(); +is( + array($record->_key, $record->foobar), + array(1, "deutsch"), + "localized field foobar_de" +); +$record->iterate(); +is( + array($record->_key, $record->foobar), + array(2, "deutsch2"), + "localized field foobar_de iterate" +); + +T_set_language('fr'); +$record->read(1); +is( + array($record->_key, $record->foobar), + array(1, "franz"), + "localized field foobar_fr" +); + diff --git a/devel-utf8/tests/it_html.t b/devel-utf8/tests/it_html.t new file mode 100755 index 0000000..0def431 --- /dev/null +++ b/devel-utf8/tests/it_html.t @@ -0,0 +1,159 @@ +#!/www/server/bin/php -qC + "html")); + +is( + a(array('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => ""), "bar"), + 'bar', + "tag with attributes" +); + +is( + div(), + "
\n", + "empty div tag" +); + +is( + img(array('src' => "foo.png", 'alt' => "ALT")), + 'ALT', + "img tag with attributes" +); + +is( + tag('link'), + "\n", + "empty link tag" +); + +is( + tag('link', "foo"), + "foo\n", + "link tag with data" +); + +is( + it::replace(array('\n+\s*' => ""), select(array('name' => "gna", 'multiple' => true), '1:foo,2:bar', '1,2')), + '', + "select tag with multiselect" +); + +is( + it::replace(array('\n+\s*' => ""), select(array('name' => "gna"), array("1" => "foo", "2" => 'bar', '1,2' => "qux"), '1,2')), + '', + "select tag without multiselect" +); + +# XML generation +unset($GLOBALS['it_html']); +new it_html(array('htmltype' => "xhtml", 'tags' => "xmltest")); + +is( + xmltest(), + "\n", + "empty xmltest tag" +); + +is( + xmltest("foo"), + "foo\n", + "empty xmltest tag" +); + +is( + xmltest(array('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, '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")), + 'foo', + "it_html inheritance" +); + +is( + it_html::sanitize(" \r \n " . '

swisspics posted < < ä & yesterday a photo tag missmatch:



+ +

Wolken

+'), + ' swisspics posted < < ä & yesterday a photo tag missmatch:

', + 'it_html::sanitize tag soup' +); + +is( + it_html::sanitize('q←x'), + "q←x", + 'it_html::sanitize preserve numeric entities' +); + +it_html::configure(array('charset' => "utf-8")); +is( + it_html::sanitize('qüx'), + "q\xc3\xbcx", + 'it_html::sanitize with utf-8' +); + +it_html::configure(array('charset' => "iso-8859-1")); +is( + it_html::sanitize('qüx'), + "q\xfcx", + 'it_html::sanitize with latin1' +); + +is( + it_html::sanitize('a
b
'), + "a
b
", + 'it_html::sanitize with b and br (tag prefix of other tag bug)' +); + +is( + U("/foo.html", array('bar' => array('gna' => 42, 'qux' => array('quux' => "", 'gnöp' => "fasel")))), + '/foo.html?bar[gna]=42&bar[qux][quux]=%3CZ%FCrich%3E&bar[qux][gn%F6p]=fasel', + 'U() with nested arrays' +); + +is( + U("Jet d'eau"), + 'Jet+d%27eau', + 'U() with single quotes in URL' +); + +is( + U('%% %1%x %1x%x1%xx%11%ff%FF'), + '%25%25+%251%25x+%251x%25x1%25xx%11%ff%FF', + 'U() quoting of % if not followed by 2 hex digits' +); + +is( + U('a\\b'), + 'a/b', + 'U() converting of \ to /' +); + +is(it_html::entity_decode("ä"), "ä"); +is(it_html::entity_decode("’"), "'"); +is(it_html::entity_decode("J"), "J"); +is(it_html::entity_decode("J"), "J"); +is(it_html::entity_decode("࿿"), " "); +is(it_html::entity_decode("A"), "A"); +is(it_html::entity_decode("ϧ"), " "); +?> diff --git a/devel-utf8/tests/it_text.t b/devel-utf8/tests/it_text.t new file mode 100755 index 0000000..bc4d5c0 --- /dev/null +++ b/devel-utf8/tests/it_text.t @@ -0,0 +1,18 @@ +#!/www/server/bin/php +x = "attr"; +$obj->y->z = "attr"; + +is(it_text::transmogrify(""), ""); +is(it_text::transmogrify("foo"), "foo"); +is(it_text::transmogrify("{foo}"), ""); +is(it_text::transmogrify("{foo}", array('foo' => 1)), "1"); +is(it_text::transmogrify("{foo}{foo}", array('foo' => 1)), "11"); +is(it_text::transmogrify("{foo}X", array('foo' => 1)), "1X"); +is(it_text::transmogrify("{foo}X{foo}", array('foo' => 1)), "1X1"); +is(it_text::transmogrify("X{foo}", array('foo' => 1)), "X1"); +is(it_text::transmogrify("X{foo}{bar}", array('foo' => 1, 'bar' => 2)), "X12"); +is(it_text::transmogrify("X{foo}", array('foo' => "&")), "X&"); +is(it_text::transmogrify("X{x}", $obj), "Xattr"); +is(it_text::transmogrify("X{y.z}", $obj), "Xattr"); diff --git a/devel-utf8/tests/it_url.t b/devel-utf8/tests/it_url.t new file mode 100755 index 0000000..e8507aa --- /dev/null +++ b/devel-utf8/tests/it_url.t @@ -0,0 +1,135 @@ +#!/www/server/bin/php -qC +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' +); + +$_SERVER['HTTP_HOST'] = "gna.ch"; +is( + it_url::absolute("/"), + 'http://gna.ch:/', + 'it_url::absolute basic' +); + +$_SERVER['SERVER_PORT'] = 42; +is( + it_url::absolute("/port"), + 'http://gna.ch:42/port', + 'it_url::absolute with non-standard port' +); + +$_SERVER['HTTPS'] = true; +$_SERVER['SERVER_PORT'] = 443; +is( + it_url::absolute("/https"), + 'https://gna.ch/https', + 'it_url::absolute for https' +); + +$url = new it_url('http://www.gna.ch/'); +$page = $url->get(); +is( + it::match('()', $page), + '', + '$url->get with url in constructor' +); + +$url = new it_url('http://bogus.url'); +$page = $url->get('http://www.gna.ch/'); +is( + it::match('()', $page), + '', + '$url->get(url) with url as string arg' +); + +$url = new it_url('http://bogus.url'); +$page = $url->get(array('url' => 'http://www.gna.ch/')); +is( + it::match('()', $page), + '', + '$url->get(\'url\' => url) with url as named arg' +); +is( + $url->result, + 200, + '$url->result = 200' +); +is( + $url->headers['Connection'], + 'close', + '$url->headers correctly set' +); + +unset($url, $page); +$page = it_url::get('http://www.gna.ch/'); +is( + it::match('()', $page), + '', + 'it_url::get() static call' +); + +$pages = it_url::get_multi('urls' => array('a' => 'http://www.gna.ch/', 'b' => 'http://search.ch/')); +ok(it::match('', $pages['a']), 'it_url::get_multi got first url'); +ok(it::match('', $pages['b']), 'it_url::get_multi got second url'); +is(count($pages), 2, 'it_url::get_multi no additional array elements'); + +?> diff --git a/devel-utf8/tests/it_xml.t b/devel-utf8/tests/it_xml.t new file mode 100755 index 0000000..f74c54b --- /dev/null +++ b/devel-utf8/tests/it_xml.t @@ -0,0 +1,120 @@ +#!/www/server/bin/php -qC +$xmldata"; + $xml = new $classname($xmldata, $p); + + is( + preg_replace('/[#\s]+/', " ", print_r($xml->$varname, true)), + $expected, + "$name (string)" + ); + + $tmpfile = tmpfile(); + fwrite($tmpfile, $xmldata); + rewind($tmpfile); + + $xml = new $classname($tmpfile, $p); + fclose($tmpfile); + + is( + preg_replace('/[#\s]+/', " ", print_r($xml->$varname, true)), + $expected, + "$name (file)" + ); + +} + +match( + '', + 'foo Object ( ) ', + 'empty tag' +); + +match( + '', + 'Array ( [0] => foo Object ( ) [1] => foo Object ( ) ) ', + 'multiple empty tags converted to array' +); + +match( + 'Stüssihofstadt', + 'foo Object ( [attr] => Array ( [title] => Zürich ) [val] => Stüssihofstadt ) ', + 'simple tag with latin1 content and attribute' +); + +match( + '', + 'foo Object ( [a_b__c] => a_b__c Object ( [attr] => Array ( [d_e_f] => value ) ) ) ', + 'Tags and attributes with name space and special characters' +); + +match( + 'x & y', + 'foo Object ( [val] => x & y ) ', + 'Character data with entities' +); + +match( + '&amp; <a> &amp; <b> &amp; <c> ü', + 'foo Object ( [val] => & & & ü ) ', + 'Predecode illegal entities while keeping properly encoded ones' +); + +match( + '&amp; <a> &amp; <b> &amp; <c> ü', + utf8_encode('foo Object ( [val] => & & & ü ) '), + 'Predecode illegal entities while keeping properly encoded ones (UTF-8)', + "", + array('encoding' => "UTF-8") +); + + +match( + "a\x05b", + 'foo Object ( [val] => a b ) ', + 'Illegal latin 1 character', + "", + array('encoding' => "ISO-8859-1") +); + +# 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 Object ( [inheritbaseclass] => ) ', + 'Inheritance and constructor (critical for e.g. tel_xmlentry)', + 'my' +); + +$x = new foo("", array('prefix' => "test")); +$x->set(array('gna' => 42, 'bar' => array('baz' => array("qux", "quux")))); +match( + $x->to_xml(), + 'foo Object ( [gna] => gna Object ( [val] => 42 ) [bar] => bar Object ( [baz] => Array ( [0] => baz Object ( [val] => qux ) [1] => baz Object ( [val] => quux ) ) ) ) ', + "Method set()" +); + +?> diff --git a/devel-utf8/tests/itjs.t b/devel-utf8/tests/itjs.t new file mode 100755 index 0000000..f616ced --- /dev/null +++ b/devel-utf8/tests/itjs.t @@ -0,0 +1,50 @@ +#!/www/server/bin/php -qC + "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' +); + +is( + itjs::serialize(array('import' => array('function' => array(true, 42)))), + '{\'import\':{\'function\':[true, 42]}}', + 'keywords' +); + +?> -- cgit v1.2.3