diff options
author | Urban Müller | 2020-04-21 01:03:53 +0200 |
---|---|---|
committer | Urban Müller | 2020-04-21 01:03:53 +0200 |
commit | d987adefc85095f057c3d6d3eb2fa4c0d487d32b (patch) | |
tree | 4a6f7be8e35ff0c412666c41a46f22383d8ed5c2 | |
parent | 1bd13e02d21ba01f38cd6df04de84b25a75a5264 (diff) | |
download | itools-d987adefc85095f057c3d6d3eb2fa4c0d487d32b.tar.gz itools-d987adefc85095f057c3d6d3eb2fa4c0d487d32b.tar.bz2 itools-d987adefc85095f057c3d6d3eb2fa4c0d487d32b.zip |
use new array syntax
-rwxr-xr-x | test/autoprepend.t | 14 | ||||
-rwxr-xr-x | test/exec.t | 34 | ||||
-rwxr-xr-x | test/getopt.t | 12 | ||||
-rwxr-xr-x | test/it.t | 112 | ||||
-rwxr-xr-x | test/it_cache.t | 22 | ||||
-rwxr-xr-x | test/it_dbi.t | 128 | ||||
-rwxr-xr-x | test/it_html.t | 46 | ||||
-rwxr-xr-x | test/it_mail.t | 4 | ||||
-rwxr-xr-x | test/it_url.t | 26 | ||||
-rwxr-xr-x | test/it_url_slow.t | 8 | ||||
-rwxr-xr-x | test/it_xml.t | 12 | ||||
-rwxr-xr-x | test/itjs.t | 14 |
12 files changed, 216 insertions, 216 deletions
diff --git a/test/autoprepend.t b/test/autoprepend.t index bf40605..7cb33e5 100755 --- a/test/autoprepend.t +++ b/test/autoprepend.t @@ -2,10 +2,10 @@ <?php it_text::init(); -$GLOBALS['it_text']->statictext = array( - '_' => array("de" => "Deutsch", "en" => "English"), - 'foo' => array("de" => "bar {v1}", "en" => "qux {v1}"), -); +$GLOBALS['it_text']->statictext = [ + '_' => ["de" => "Deutsch", "en" => "English"], + 'foo' => ["de" => "bar {v1}", "en" => "qux {v1}"], +]; is( T('foo'), @@ -20,19 +20,19 @@ is( ); is( - T('foo', array('v1' => "gna<bber")), + T('foo', ['v1' => "gna<bber"]), "bar gna<bber", "T() with quoted values" ); is( - T('foo', array('v1' => "gna<bber"), 'en'), + T('foo', ['v1' => "gna<bber"], 'en'), "qux gna<bber", "T() with with quoted values and language" ); is( - T('foo', 'en', array('v1' => "gna<bber")), + T('foo', 'en', ['v1' => "gna<bber"]), "qux gna<bber", "T() with with language and quoted values" ); diff --git a/test/exec.t b/test/exec.t index c155c88..293ad61 100755 --- a/test/exec.t +++ b/test/exec.t @@ -4,71 +4,71 @@ # Tests for getopt in it.class is(it::exec("echo gna"), "gna\n", "basic exec"); -is(it::exec("echo {arg}", array('arg' => 'gna')), "gna\n", "exec with argument"); +is(it::exec("echo {arg}", ['arg' => 'gna']), "gna\n", "exec with argument"); is(it::exec("echo {0}", 'gna'), "gna\n", "exec with positional 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"); +is(it::shell_command("echo {arg}", ['arg' => 'gna07,-:blah']), "echo gna07,-:blah", "don't quote arguments with only whitelistes characters"); +is(it::shell_command("echo {arg}", ['arg' => '2>&1']), "echo '2>&1'", "quote arguments with dangerous characters"); +is(it::shell_command("echo {arg}", ['arg' => '']), "echo ''", "quote empty arguments"); is( - it::shell_command("echo {-opts}", array('-opts' => array('--longopt' => true))), + it::shell_command("echo {-opts}", ['-opts' => ['--longopt' => true]]), "echo --longopt", "options argument with long option" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('-onedash' => true))), + it::shell_command("echo {-opts}", ['-opts' => ['-onedash' => true]]), "echo -onedash", "... with long option but only one dash" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('-s' => true))), + it::shell_command("echo {-opts}", ['-opts' => ['-s' => true]]), "echo -s", "... with short option" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('--longopt' => 'val'))), + it::shell_command("echo {-opts}", ['-opts' => ['--longopt' => 'val']]), "echo --longopt val", "... with long option with value" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('-onedash' => 'val'))), + it::shell_command("echo {-opts}", ['-opts' => ['-onedash' => 'val']]), "echo -onedash val", "... with long option but only one dash and with value" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('-s' => 'val'))), + it::shell_command("echo {-opts}", ['-opts' => ['-s' => 'val']]), "echo -s val", "... with short option with value" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('--longopt' => false))), + it::shell_command("echo {-opts}", ['-opts' => ['--longopt' => false]]), "echo ", "... with disabled long option" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('-s' => false))), + it::shell_command("echo {-opts}", ['-opts' => ['-s' => false]]), "echo ", "... with disabled short option" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('longopt' => true))), + it::shell_command("echo {-opts}", ['-opts' => ['longopt' => true]]), "echo --longopt", "... long option without dashes" ); is( - it::shell_command("echo {-opts}", array('-opts' => array('s' => true))), + it::shell_command("echo {-opts}", ['-opts' => ['s' => true]]), "echo -s", "... short option without dashes" ); -foreach (array("", "C", "de_CH", "de_CH.utf8") as $locale) { +foreach (["", "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("echo {arg}", ['arg' => $arg]), $arg . "\n", "exec with argument and umlaut (locale '$locale')"); } is(it::_exec_quotevalue(""), "''", "empty arg needs quotes"); @@ -84,7 +84,7 @@ it::system('touch /tmp/it_system_test'); ok(file_exists('/tmp/it_system_test'), 'shell command gets executed'); @unlink('/tmp/it_system_test'); -it::system('touch {path}', array('path' => '/tmp/it_system_test')); +it::system('touch {path}', ['path' => '/tmp/it_system_test']); ok(file_exists('/tmp/it_system_test'), 'shell command with argument'); @unlink('/tmp/it_system_test'); diff --git a/test/getopt.t b/test/getopt.t index 8b0ff70..cf3d9e8 100755 --- a/test/getopt.t +++ b/test/getopt.t @@ -12,17 +12,17 @@ $GLOBALS['usage'] = "Usage: doesnotexist.php [OPTIONS] function getopt_ok($argv, $exp, $name) { - $_SERVER['argv'] = array_merge(array('doesnotexist.php'), $argv); + $_SERVER['argv'] = array_merge(['doesnotexist.php'], $argv); $got = it::getopt($GLOBALS['usage']); return is($got['argument'], $exp, $name); } -foreach (array("" => "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); +foreach (["" => "blah gnaber", " (umlaute)" => "pre üäpost"] as $variant => $testarg) { + getopt_ok(['-a', $testarg], $testarg, "Short version" . $variant); + getopt_ok(['--argument', $testarg], $testarg, "Long version with space" . $variant); + getopt_ok(["--argument=$testarg"], $testarg, "Long version with equal" . $variant); } -$_SERVER['argv'] = array('doesnotexist.php', '-0'); +$_SERVER['argv'] = ['doesnotexist.php', '-0']; $zero_opts = it::getopt($GLOBALS['usage']); ok($zero_opts['zero'], '-0'); @@ -12,7 +12,7 @@ $oldlocale = setlocale(LC_CTYPE, 0); ini_set('default_charset', 'utf-8'); setlocale(LC_CTYPE, 'de_CH'); # required becuase we're checking German umlauts in latin1 mode -function match($regex, $string, $expect, $name, $p = array()) +function match($regex, $string, $expect, $name, $p = []) { $GLOBALS['TEST_MORE_LEVEL'] = 1; $pass = is (it::match($regex, $string, $p), $expect, $name); @@ -38,7 +38,7 @@ match( match( 'aa(bb)aa(cc)aa(dd)qq', 'aabbaaccaaddqq', - array('bb', 'cc', 'dd'), + ['bb', 'cc', 'dd'], 'return array of captures' ); @@ -197,9 +197,9 @@ match( match( '\w+', 'word1 wörd2 word_3', - array('word1', 'wörd2', 'word_3'), + ['word1', 'wörd2', 'word_3'], "test match_all function", - array('all' => true) + ['all' => true] ); match( @@ -224,14 +224,14 @@ match( utf8_decode('ö'), utf8_decode('Ö'), utf8_decode('Ö'), 'match umlaute in de_CH.latin1 case insensitive', - array('utf8' => false) + ['utf8' => false] ); match( utf8_decode('aöBÜ'), utf8_decode('AÖbü'), utf8_decode('AÖbü'), "match umlaute with non-utf-8 override in p", - array('utf8' => false) + ['utf8' => false] ); @@ -239,35 +239,35 @@ match( 'abc', "aBc", null, "set case sensitivity by parameter", - array('casesensitive' => 1) + ['casesensitive' => 1] ); match( '\w+', 'word1 wörd2 word_3', - array('word1', 'wörd2', 'word_3'), + ['word1', 'wörd2', 'word_3'], "test all => 1 without captures", - array('all' => 1) + ['all' => 1] ); match( '\w+\s+(\d+)', 'word1 12 wörd2 3 word_3 4', - array('12', '3', '4'), + ['12', '3', '4'], "test all => 1 with one capture", - array('all' => 1) + ['all' => 1] ); match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', - array(array('word1', '12'), array('wörd2', '3'), array('word_3', '4')), + [['word1', '12'], ['wörd2', '3'], ['word_3', '4']], "test all => 1 with captures", - array('all' => 1) + ['all' => 1] ); match( '(\w+)\s+(\d+)', 'word1 12 wörd2 3 word_3 4', - array(array('word1', 'wörd2', 'word_3'), array('12', '3', '4')), + [['word1', 'wörd2', 'word_3'], ['12', '3', '4']], "test all => 1,pattern_order => 1", - array('all' => 1, 'pattern_order' => 1) + ['all' => 1, 'pattern_order' => 1] ); ini_set('default_charset', 'iso-8859-1'); @@ -275,7 +275,7 @@ match( 'aöBÜ', "AÖbü", 'AÖbü', "match utf-8 umlaute in case insensitive mode with utf8 override", - array('utf8' => true) + ['utf8' => true] ); ini_set('default_charset', 'utf-8'); @@ -285,30 +285,30 @@ ini_set('default_charset', 'utf-8'); # is( it::replace( - array( + [ 'regex1' => 'repl1', 'regex2' => 'repl2', - 'regex3' => 'repl3'), + 'regex3' => 'repl3'], 'regex2 regex1 regex3'), 'repl2 repl1 repl3', 'test tr regex function' ); -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"); -is(it::replace(array('\s' => "x"), it_html::entity_decode(" ")), "x", "match non-breaking space as white-space character"); -is(it::replace(array('a' => "b", 'b' => "c"), "a"), "c"); - -is(it::grep('ismatch', array('ismatch', 'isnomatch')), array('ismatch'), 'grep with simple regex'); -is(it::grep('!', array('ismatch!', 'isnomatch')), array('ismatch!'), '! in regex'); -is(it::grep('lower|UPPER', array('lower', 'LOWER', 'upper', 'UPPER'), array('casesensitive' => 1)), array(0 => 'lower', 3 => 'UPPER'), 'set casesensitive'); -is(it::grep('match', array('foo' => 'match', 'bar' => 'gna')), array('foo' => 'match'), 'with keys'); +is(it::replace(['a' => "1", 'b' => "2"], "ab"), "12"); +is(it::replace(['!' => "x"], "!"), "x"); +is(it::replace(['\w' => "x"], "oö"), "xx"); +is(it::replace(['[[:alpha:]]' => "x"], "ö"), "x"); +is(it::replace(['\w' => "x", '#' => "!"], "#ö"), "!x"); +is(it::replace(['#' => "!", '\w' => "x"], "#ö"), "!x"); +is(it::replace(['ö' => "x"], "Ö"), "x"); +is(it::replace(['a' => "1"], "aaa", ['limit' => 1]), "1aa"); +is(it::replace(['\s' => "x"], it_html::entity_decode(" ")), "x", "match non-breaking space as white-space character"); +is(it::replace(['a' => "b", 'b' => "c"], "a"), "c"); + +is(it::grep('ismatch', ['ismatch', 'isnomatch']), ['ismatch'], 'grep with simple regex'); +is(it::grep('!', ['ismatch!', 'isnomatch']), ['ismatch!'], '! in regex'); +is(it::grep('lower|UPPER', ['lower', 'LOWER', 'upper', 'UPPER'], ['casesensitive' => 1]), [0 => 'lower', 3 => 'UPPER'], 'set casesensitive'); +is(it::grep('match', ['foo' => 'match', 'bar' => 'gna']), ['foo' => 'match'], 'with keys'); is(it::grep('2', [0 => 1, 1 => 2, 2 => 3], ['invert' => true]), [0 => 1, 2 => 3]); setlocale(LC_CTYPE, $oldlocale); @@ -326,21 +326,21 @@ is(it::cidr_match('192.168.42.42', '192.168.42.64/26'), false, "cidr_match o is(it::cidr_match('192.168.42.42', '192.168.42.32/27'), true, "cidr_match offset"); is(it::cidr_match('2001:918:ff83:101:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), true, "cidr_match ipv6"); is(it::cidr_match('2001:918:ff83:102:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), false, "cidr_match ipv6 no match" ); -is(it::cidr_match('10.11.12.13', array('10.0.0.0/8', '192.168.0.0./16')), true, "cidr_match array"); +is(it::cidr_match('10.11.12.13', ['10.0.0.0/8', '192.168.0.0./16']), true, "cidr_match array"); # 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"); +$data = ['a' => 1, 'b' => 2, 'c' => 3]; +is(it::filter_keys($data, 'a'), ['a' => 1], "select one key"); +is(it::filter_keys($data, ['a', 'b']), ['a' => 1, 'b' => 2], "select two keys with array"); +is(it::filter_keys($data, 'a,b'), ['a' => 1, 'b' => 2], "select two keys with string"); is( array_keys(it::filter_keys($data, 'b,a')), - array('a', 'b'), + ['a', 'b'], "keep order of data array per default"); is( - array_keys(it::filter_keys($data, 'b,a', array('reorder' => true))), - array('b', 'a'), + array_keys(it::filter_keys($data, 'b,a', ['reorder' => true])), + ['b', 'a'], "reorder with given key order"); # it::date tests @@ -409,10 +409,10 @@ is(it::any2utf8(utf8_encode(utf8_encode("Müller"))), "Müller", "it::any2utf8 t is(it::any2utf8(utf8_decode("Müller")), "Müller", "it::any2utf8 incorrectly encoded latin1"); is(it::any2utf8("a💚b"), "a💚b", "it::any2utf8 correctly handles 4-byte utf-8 character GREEN HEART"); -is(it::any2utf8(array("foo", utf8_decode("bär"))), array("foo", "bär"), "any2utf8 on arrays"); -is(it::any2utf8(array("foo", array(utf8_decode("bär")))), array("foo", array("bär")), "any2utf8 on recursive arrays"); -is(it::any2utf8(array(1, true, false, null)), array(1, true, false, null), "any2utf8 should leave types alone"); -is(it::any2utf8(array(utf8_decode('Müller') => utf8_decode('Müller'))), array('Müller' => 'Müller'), "it::any2utf8 latin1 keys"); +is(it::any2utf8(["foo", utf8_decode("bär")]), ["foo", "bär"], "any2utf8 on arrays"); +is(it::any2utf8(["foo", [utf8_decode("bär")]]), ["foo", ["bär"]], "any2utf8 on recursive arrays"); +is(it::any2utf8([1, true, false, null]), [1, true, false, null], "any2utf8 should leave types alone"); +is(it::any2utf8([utf8_decode('Müller') => utf8_decode('Müller')]), ['Müller' => 'Müller'], "it::any2utf8 latin1 keys"); is(it::any2utf8("\xc2\xad"), "", "it::any2utf8 remove soft hyphens"); @@ -426,32 +426,32 @@ foreach ([ 'a' => 'ä', 'e' => 'ë', 'i' => 'ï', 'o' => 'ö', 'u' => 'ü' ] as is(it::any2utf8("\x65\xcc\x81"), "é", "it::any2utf8 convert to normal form C"); -foreach (array($dummy, false, true, null, 1, "a", "Ä", "/", array()) as $var) +foreach ([$dummy, false, true, null, 1, "a", "Ä", "/", []] as $var) is(it::json_decode(it::json_encode($var)), $var); is(it::json_decode('{"foo":"bar"}')->foo, "bar"); is(it::json_decode('{"foo":"bar"}', ['assoc' => true])['foo'], "bar"); -is(it::sort(array("2!","19!","1!")), array("1!", "19!", "2!")); -is(it::sort(array("2!","19!","1!"), "r"), array("2!", "19!", "1!")); -is(it::sort(array("2!","19!","1!"), "rn"), array("19!", "2!", "1!")); +is(it::sort(["2!","19!","1!"]), ["1!", "19!", "2!"]); +is(it::sort(["2!","19!","1!"], "r"), ["2!", "19!", "1!"]); +is(it::sort(["2!","19!","1!"], "rn"), ["19!", "2!", "1!"]); is(it::mod(-9, 4), 3); is(it::mod(-8, 4), 0); is(it::mod(0, 4), 0); is(it::mod(7, 4), 3); -is(it::map('5*$k+$v', array(0 => 1, 1 => 2)), array(1, 7)); -is(it::map(function($k, $v) {return 5*$k+$v;}, array(0 => 1, 1 => 2)), array(1, 7)); -is(it::map('strlen', array("aaa", "aa")), array(3, 2)); -is(it::map('it::ucfirst', array("aaa")), array("Aaa")); +is(it::map('5*$k+$v', [0 => 1, 1 => 2]), [1, 7]); +is(it::map(function($k, $v) {return 5*$k+$v;}, [0 => 1, 1 => 2]), [1, 7]); +is(it::map('strlen', ["aaa", "aa"]), [3, 2]); +is(it::map('it::ucfirst', ["aaa"]), ["Aaa"]); $dom = new DOMDocument; $dom->loadXML('<foo>42</foo>'); is(it::map('$v->C14N()', $dom->childNodes), [ '<foo>42</foo>' ], "Traversable: Needs copy, not modifiable in-place"); # Special values which are not callable -is(it::map('null', array("aaa", "aa")), array(null, null)); -is(it::map('1', array("aaa", "aa")), array(1, 1)); -is(it::map(42, array("aaa", "aa")), array(42, 42)); +is(it::map('null', ["aaa", "aa"]), [null, null]); +is(it::map('1', ["aaa", "aa"]), [1, 1]); +is(it::map(42, ["aaa", "aa"]), [42, 42]); # Only map selected keys is(it::map('2*$v', [3, 4, 5], ['keys' => '0,1']), [6, 8, 5]); is(it::map('2*$v', [3, 4, 5], ['keys' => [0,1]]), [6, 8, 5]); diff --git a/test/it_cache.t b/test/it_cache.t index 8f804d4..e2e94bf 100755 --- a/test/it_cache.t +++ b/test/it_cache.t @@ -8,8 +8,8 @@ is(it_cache::get('it_cache_t'), 42, "cache put number"); it_cache::put('it_cache_t', false); is(it_cache::get('it_cache_t'), false, "cache get number"); -it_cache::put('it_cache_t', array(2)); -is(it_cache::get('it_cache_t'), array(2), "cache put/get array"); +it_cache::put('it_cache_t', [2]); +is(it_cache::get('it_cache_t'), [2], "cache put/get array"); # test non-distributed apc cache @@ -21,9 +21,9 @@ it_cache::put('it_cache_t', false); unset($GLOBALS['it_cache_local']); is(it_cache::get('it_cache_t'), false, "local put/get false"); -it_cache::put('it_cache_t', array(2)); +it_cache::put('it_cache_t', [2]); unset($GLOBALS['it_cache_local']); -is(it_cache::get('it_cache_t'), array(2), "local put/get array"); +is(it_cache::get('it_cache_t'), [2], "local put/get array"); is(it_cache::get('it_cache_t'.rand(1, 1000)), null, "local get unknown key"); @@ -31,19 +31,19 @@ is(it_cache::get('it_cache_t'.rand(1, 1000)), null, "local get unknown key"); # test distributed memcache $GLOBALS['debug_aslive'] = 1; -it_cache::put('it_cache_d', 42, array('distributed' => 1)); +it_cache::put('it_cache_d', 42, ['distributed' => 1]); it_cache::put('it_cache_d', 0); unset($GLOBALS['it_cache_local']); -is(intval(it_cache::get('it_cache_d', array('distributed' => 1))), 42, "distributed put/get number"); +is(intval(it_cache::get('it_cache_d', ['distributed' => 1])), 42, "distributed put/get number"); -it_cache::put('it_cache_d', false, array('distributed' => 1)); +it_cache::put('it_cache_d', false, ['distributed' => 1]); it_cache::put('it_cache_d', 1); unset($GLOBALS['it_cache_local']); -is(boolval(it_cache::get('it_cache_d', array('distributed' => 1))), false, "distributed put/get false"); +is(boolval(it_cache::get('it_cache_d', ['distributed' => 1])), false, "distributed put/get false"); -it_cache::put('it_cache_d', array(2), array('distributed' => 1)); +it_cache::put('it_cache_d', [2], ['distributed' => 1]); it_cache::put('it_cache_d', 0); unset($GLOBALS['it_cache_local']); -is(it_cache::get('it_cache_d', array('distributed' => 1)), array(2), "distributed put/get array"); +is(it_cache::get('it_cache_d', ['distributed' => 1]), [2], "distributed put/get array"); -is(it_cache::get('it_cache_d'.rand(1, 1000), array('distributed' => 1)), null, "distributed get unknown key"); +is(it_cache::get('it_cache_d'.rand(1, 1000), ['distributed' => 1]), null, "distributed get unknown key"); diff --git a/test/it_dbi.t b/test/it_dbi.t index 705e814..9f43f6e 100755 --- a/test/it_dbi.t +++ b/test/it_dbi.t @@ -4,7 +4,7 @@ # Tests for it_dbi.class # Initialize DB -$db = array('db' => "lib_search_ch", 'safety' => 0); +$db = ['db' => "lib_search_ch", 'safety' => 0]; $dbi = new it_dbi($db); $dbi->query('create temporary table it_dbi_test ( ID int not null auto_increment, @@ -13,13 +13,13 @@ $dbi->query('create temporary table it_dbi_test ( dyncols JSON, primary key(ID) );'); -it_dbi::createclass(array('table' => "it_dbi_test", 'forcecreate' => true)); +it_dbi::createclass(['table' => "it_dbi_test", 'forcecreate' => true]); $record = new it_dbi_test; -$record->insert(array('x' => 42, 'foo' => null)); -$record->insert(array('foo' => "bar")); -$record->insert(array('x' => 64738, 'foo' => "q'uux")); +$record->insert(['x' => 42, 'foo' => null]); +$record->insert(['foo' => "bar"]); +$record->insert(['x' => 64738, 'foo' => "q'uux"]); is( $record->ID, @@ -29,8 +29,8 @@ is( $record->read(1); is( - array($record->_key, $record->x, $record->foo), - array(1, 42, null), + [$record->_key, $record->x, $record->foo], + [1, 42, null], "read" ); @@ -41,7 +41,7 @@ is( ); is( - $record->select(array('foo <>' => ""), "LIMIT 1"), + $record->select(['foo <>' => ""], "LIMIT 1"), 1, "select with multiple parameters (LIMIT part)" ); @@ -51,32 +51,32 @@ is( "select with multiple parameters (foo part)" ); is( - $record->select(array('ID IN' => array(2,3))), + $record->select(['ID IN' => [2,3]]), 2, "select with IN" ); is( - $record->select(array('ID NI' => array(2,3))), + $record->select(['ID NI' => [2,3]]), 2, "select with NI" ); is( - $record->select(array('ID NOT IN' => array(2,3))), + $record->select(['ID NOT IN' => [2,3]]), 1, "select with NOT IN" ); is( - $record->select(array('ID IN' => array())), + $record->select(['ID IN' => []]), 0, "select with empty IN" ); is( - $record->select(array('ID NOT IN' => array())), + $record->select(['ID NOT IN' => []]), 3, "select with empty NOT IN" ); is( - $record->select(array('ID' => array(2,3))), + $record->select(['ID' => [2,3]]), 2, "select with implicit IN" ); @@ -95,14 +95,14 @@ is( "constructor of created class with id parameter" ); -$record = new it_dbi_test(array('x >' => 0), "ORDER BY x DESC"); +$record = new it_dbi_test(['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')); +$record = new it_dbi_test(['foo' => 'bar']); is( $record->ID, 2, @@ -116,96 +116,96 @@ is( "constructor without parameters" ); -$record = new it_dbi_test(array('x >' => 0), "ORDER BY x DESC"); +$record = new it_dbi_test(['x >' => 0], "ORDER BY x DESC"); is( $record->x, 64738, "constructor with multiple select parameters" ); -$record->select(array('x' => 64738)); +$record->select(['x' => 64738]); is( - array($record->_key, $record->x, $record->foo), - array(3, 64738, "q'uux"), + [$record->_key, $record->x, $record->foo], + [3, 64738, "q'uux"], "select" ); -$record->update(array('x' => 17)); +$record->update(['x' => 17]); is( - array($record->_key, $record->x, $record->foo), - array(3, 17, "q'uux"), + [$record->_key, $record->x, $record->foo], + [3, 17, "q'uux"], "update" ); is( - $record->update(array('x' => 18), array('x' => 17)), + $record->update(['x' => 18], ['x' => 17]), 1, "return affected rows" ); is( - $record->update(array('x' => 18), array('x' => 17)), + $record->update(['x' => 18], ['x' => 17]), 0, "return zero affected rows" ); -$record->update(array('-x' => 'POW(2,2) * 10')); +$record->update(['-x' => 'POW(2,2) * 10']); is( - array($record->_key, $record->x, $record->foo), - array(3, 40, "q'uux"), + [$record->_key, $record->x, $record->foo], + [3, 40, "q'uux"], "update with function" ); -$record->update(array('foo' => "00")); +$record->update(['foo' => "00"]); $rand = $record->x; is ( - $record->_set(array('x' => $rand, 'foo' => "0")), + $record->_set(['x' => $rand, 'foo' => "0"]), "SET `foo`='0'", 'update: _set optimization' ); -$record->update(array('foo' => NULL)); +$record->update(['foo' => NULL]); is ( - $record->_set(array('foo' => "")), + $record->_set(['foo' => ""]), "SET `foo`=''", 'update: _set optimization with NULL => ""' ); -$record->update(array('foo' => "bar")); -$record->update(array('foo' => "")); +$record->update(['foo' => "bar"]); +$record->update(['foo' => ""]); is ( - $record->_set(array('foo' => NULL)), + $record->_set(['foo' => NULL]), "SET `foo`=NULL", 'update: _set optimization with "" => NULL' ); -$record->update(array('foo' => "bar")); -$record->select(array('foo' => "bar")); +$record->update(['foo' => "bar"]); +$record->select(['foo' => "bar"]); $record->iterate(); is( - array($record->_key, $record->x, $record->foo), - array(2, null, "bar"), + [$record->_key, $record->x, $record->foo], + [2, null, "bar"], "iterate record 2" ); -$record->update(array('foo' => "qux")); +$record->update(['foo' => "qux"]); $record->iterate(); is( - array($record->_key, $record->x, $record->foo), - array(3, $rand, "bar"), + [$record->_key, $record->x, $record->foo], + [3, $rand, "bar"], "iterate record 3" ); -$record->update(array('foo' => "quux")); +$record->update(['foo' => "quux"]); $record->read(2); is( - array($record->_key, isset($record->x), $record->foo), - array(2, false, "qux"), + [$record->_key, isset($record->x), $record->foo], + [2, false, "qux"], "iterate update record 2" ); $record->read(3); is( - array($record->_key, $record->x, $record->foo), - array(3, $rand, "quux"), + [$record->_key, $record->x, $record->foo], + [3, $rand, "quux"], "iterate update record 3" ); @@ -224,7 +224,7 @@ foreach (new it_dbi_test as $id => $record) is($count, 3, "Iterator without select"); $count = 0; -foreach (new it_dbi_test(array('foo <>' => "")) as $id => $record) +foreach (new it_dbi_test(['foo <>' => ""]) as $id => $record) { $count++; is($record->_key, $id, "Iterator id $id"); @@ -237,7 +237,7 @@ foreach ($record as $dummy_rec) is($count, 2, "Iterator reused"); $GLOBALS['debug_sqllog'] = true; -@$record->store(array('ID' => 5, 'x' => 6)); +@$record->store(['ID' => 5, 'x' => 6]); like( $record->_sqllog[1]['query'], "REPLACE", @@ -251,8 +251,8 @@ is( "saving with store" ); -$record->_sqllog = array(); -@$record->store(array('ID' => 5, 'x' => 7)); +$record->_sqllog = []; +@$record->store(['ID' => 5, 'x' => 7]); like( $record->_sqllog[1]['query'], "UPDATE", @@ -266,8 +266,8 @@ is( "updating with store" ); -$record->_sqllog = array(); -@$record->store(array('ID' => 5, 'x' => 7)); +$record->_sqllog = []; +@$record->store(['ID' => 5, 'x' => 7]); is( $record->_sqllog[1]['query'], null, # Only SELECT, no UPDATE @@ -278,7 +278,7 @@ $GLOBALS['debug_sqllog'] = false; # test latin1 (produces warnings on stderr for failing) $record = new it_dbi_test(['charset' => 'latin1']); -$record->select(array('foo' => "\xc3\x28")); +$record->select(['foo' => "\xc3\x28"]); # Test field localization feature @@ -289,30 +289,30 @@ $dbi->query('create temporary table it_dbi_testlocalized ( 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")); +$record = new it_dbi($db + ['table' => "it_dbi_testlocalized"]); +$record->insert(['foobar_de' => "deutsch", 'foobar_fr' => "franz"]); +$record->insert(['foobar_de' => "deutsch2", 'foobar_fr' => "franz2"]); T_set_language('de'); -$record->select(array()); +$record->select([]); $record->iterate(); is( - array($record->_key, $record->foobar), - array(1, "deutsch"), + [$record->_key, $record->foobar], + [1, "deutsch"], "localized field foobar_de" ); $record->iterate(); is( - array($record->_key, $record->foobar), - array(2, "deutsch2"), + [$record->_key, $record->foobar], + [2, "deutsch2"], "localized field foobar_de iterate" ); T_set_language('fr'); $record->read(1); is( - array($record->_key, $record->foobar), - array(1, "franz"), + [$record->_key, $record->foobar], + [1, "franz"], "localized field foobar_fr" ); diff --git a/test/it_html.t b/test/it_html.t index f5daebd..a43f674 100755 --- a/test/it_html.t +++ b/test/it_html.t @@ -7,10 +7,10 @@ it::getopt(""); #handle possible --debug parameter # Traditional html5 generation ini_set('default_charset', "utf-8"); -new it_html(array('htmltype' => "html5", 'prettyprint' => false, 'error_on_redefine' => false)); +new it_html(['htmltype' => "html5", 'prettyprint' => false, 'error_on_redefine' => false]); is( - a(array('href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => ""), "bar"), + a(['href' => "&foo", 'true' => true, 'false' => false, 'null' => null, 'empty' => ""], "bar"), '<a href="&foo" true empty="">bar</a>', "tag with attributes" ); @@ -34,7 +34,7 @@ is( ); is( - img(array('src' => "foo.png", 'alt' => "ALT")), + img(['src' => "foo.png", 'alt' => "ALT"]), '<img src="foo.png" alt="ALT">', "img tag with attributes" ); @@ -52,50 +52,50 @@ is( ); is( - it::replace(array('\n+\s*' => ""), select(array('name' => "gna", 'multiple' => true), '1:foo,2:bar', '1,2')), + it::replace(['\n+\s*' => ""], select(['name' => "gna", 'multiple' => true], '1:foo,2:bar', '1,2')), '<select name="gna" multiple><option value="1" selected>foo</option><option value="2" selected>bar</option></select>', "select tag with multiselect" ); is( - it::replace(array('\n+\s*' => ""), select(array('name' => "gna"), array("1" => "foo", "2" => 'bar', '1,2' => "qux"), '1,2')), + it::replace(['\n+\s*' => ""], select(['name' => "gna"], ["1" => "foo", "2" => 'bar', '1,2' => "qux"], '1,2')), '<select name="gna"><option value="1">foo</option><option value="2">bar</option><option value="1,2" selected>qux</option></select>', "select tag without multiselect" ); is( - div(array('arg' => "val: \x03, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \t, \n, \r", "\x02, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \t, \n, \r")), + div(['arg' => "val: \x03, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \t, \n, \r", "\x02, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \t, \n, \r"]), "<div arg=\"val: , , , , , , 	, , \">\x02, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \t, \n, \r</div>\n", "blank unprintable characters and illegal utf8 in attributes but not in normal text" ); is( - div(array("arg\x03\x0e\x0f\xc2\x80\xc2\x9fendarg" => "value", "content")), + div(["arg\x03\x0e\x0f\xc2\x80\xc2\x9fendarg" => "value", "content"]), "<div arg\x03\x0e\x0f\xc2\x80\xc2\x9fendarg=\"value\">content</div>\n", "don't blank unprintable characters and illegal utf8 in attribute names" ); is( - div(array('arg' => "abc äüö éá© œàè îôÇ xyz", "abc äüö éá© œàè îôÇ xyz")), + div(['arg' => "abc äüö éá© œàè îôÇ xyz", "abc äüö éá© œàè îôÇ xyz"]), "<div arg=\"abc äüö éá© œàè îôÇ xyz\">abc äüö éá© œàè îôÇ xyz</div>\n", "leave legal utf8 intact" ); unset($GLOBALS['debug_utf8check']); is( - div(array('arg' => "value \xc2", "content")), + div(['arg' => "value \xc2", "content"]), "<div arg=\"value \xc2\">content</div>\n", "handle single \\xc2 at end of attribute value" ); is( - div(array("arg\x00end" => "value \x00 end", "content \x00 content end")), + div(["arg\x00end" => "value \x00 end", "content \x00 content end"]), "<div arg\x00end=\"value end\">content \x00 content end</div>\n", "handle 0-bytes" ); is( - div(array('arg' => "& \" < > \n '", "& \" < > \n '")), + div(['arg' => "& \" < > \n '", "& \" < > \n '"]), "<div arg=\"& " < > '\">& \" < > \n '</div>\n", "use html entities in attributes but not in normal text" ); @@ -107,16 +107,16 @@ is( ); # Test different html types -foreach (array('html5' => "<br flag>", 'html' => "<br flag>", 'xhtml' => "<br flag=\"flag\" />", 'xhtml-mobile' => "<br flag=\"flag\" />") as $type => $value) +foreach (['html5' => "<br flag>", 'html' => "<br flag>", 'xhtml' => "<br flag=\"flag\" />", 'xhtml-mobile' => "<br flag=\"flag\" />"] as $type => $value) { unset($GLOBALS['it_html']); - new it_html(array('htmltype' => $type, 'error_on_redefine' => false)); - is (trim(br(array('flag' => true))), $value, "Check empty tag and attribute for $type"); + new it_html(['htmltype' => $type, 'error_on_redefine' => false]); + is (trim(br(['flag' => true])), $value, "Check empty tag and attribute for $type"); } # XHTML generation unset($GLOBALS['it_html']); -new it_html(array('htmltype' => "xhtml", 'tags' => "script", 'error_on_redefine' => false)); +new it_html(['htmltype' => "xhtml", 'tags' => "script", 'error_on_redefine' => false]); is( script(), @@ -139,7 +139,7 @@ is( # XML generation unset($GLOBALS['it_html']); -new it_html(array('htmltype' => "xml", 'name' => 'it_html', 'tags' => "xmltest", 'error_on_redefine' => false)); +new it_html(['htmltype' => "xml", 'name' => 'it_html', 'tags' => "xmltest", 'error_on_redefine' => false]); is( xmltest(), @@ -154,7 +154,7 @@ is( ); |