summaryrefslogtreecommitdiff
path: root/ext/intl/tests
diff options
context:
space:
mode:
Diffstat (limited to 'ext/intl/tests')
-rwxr-xr-xext/intl/tests/_files/es-bundle.txt21
-rwxr-xr-xext/intl/tests/_files/res_index.txt6
-rwxr-xr-xext/intl/tests/_files/resourcebundle.txt21
-rwxr-xr-xext/intl/tests/_files/resourcebundle/es.resbin0 -> 384 bytes
-rwxr-xr-xext/intl/tests/_files/resourcebundle/res_index.resbin0 -> 128 bytes
-rwxr-xr-xext/intl/tests/_files/resourcebundle/root.resbin0 -> 388 bytes
-rwxr-xr-xext/intl/tests/badargs.phpt25
-rwxr-xr-xext/intl/tests/collator_get_sort_key.phpt97
-rwxr-xr-xext/intl/tests/resourcebundle.build33
-rw-r--r--ext/intl/tests/resourcebundle.inc13
-rw-r--r--ext/intl/tests/resourcebundle_arrayaccess.phpt48
-rw-r--r--ext/intl/tests/resourcebundle_create.phpt62
-rw-r--r--ext/intl/tests/resourcebundle_individual.phpt55
-rw-r--r--ext/intl/tests/resourcebundle_iterator.phpt71
-rwxr-xr-xext/intl/tests/resourcebundle_locales.phpt23
-rwxr-xr-xext/intl/tests/ut_common.inc30
16 files changed, 504 insertions, 1 deletions
diff --git a/ext/intl/tests/_files/es-bundle.txt b/ext/intl/tests/_files/es-bundle.txt
new file mode 100755
index 000000000..46399a771
--- /dev/null
+++ b/ext/intl/tests/_files/es-bundle.txt
@@ -0,0 +1,21 @@
+es {
+ teststring:string { "Hola Mundo!" }
+
+ testint:int { 2 }
+
+ testvector:intvector { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }
+
+ testbin:bin { a1b2c3d4e5f67890 }
+
+ testtable:table {
+ major:int { 3 }
+ minor:int { 4 }
+ patch:int { 7 }
+ }
+
+ testarray:array {
+ "cadena 1",
+ "cadena 2",
+ "cadena 3"
+ }
+}
diff --git a/ext/intl/tests/_files/res_index.txt b/ext/intl/tests/_files/res_index.txt
new file mode 100755
index 000000000..a39bea58e
--- /dev/null
+++ b/ext/intl/tests/_files/res_index.txt
@@ -0,0 +1,6 @@
+res_index:table(nofallback) {
+ InstalledLocales {
+es {""}
+root {""}
+ }
+} \ No newline at end of file
diff --git a/ext/intl/tests/_files/resourcebundle.txt b/ext/intl/tests/_files/resourcebundle.txt
new file mode 100755
index 000000000..5b081da6c
--- /dev/null
+++ b/ext/intl/tests/_files/resourcebundle.txt
@@ -0,0 +1,21 @@
+root {
+ teststring:string { "Hello World!" }
+
+ testint:int { 2 }
+
+ testvector:intvector { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }
+
+ testbin:bin { a1b2c3d4e5f67890 }
+
+ testtable:table {
+ major:int { 3 }
+ minor:int { 4 }
+ patch:int { 7 }
+ }
+
+ testarray:array {
+ "string 1",
+ "string 2",
+ "string 3"
+ }
+}
diff --git a/ext/intl/tests/_files/resourcebundle/es.res b/ext/intl/tests/_files/resourcebundle/es.res
new file mode 100755
index 000000000..f9d891d6b
--- /dev/null
+++ b/ext/intl/tests/_files/resourcebundle/es.res
Binary files differ
diff --git a/ext/intl/tests/_files/resourcebundle/res_index.res b/ext/intl/tests/_files/resourcebundle/res_index.res
new file mode 100755
index 000000000..9dd3df2de
--- /dev/null
+++ b/ext/intl/tests/_files/resourcebundle/res_index.res
Binary files differ
diff --git a/ext/intl/tests/_files/resourcebundle/root.res b/ext/intl/tests/_files/resourcebundle/root.res
new file mode 100755
index 000000000..62cb48c45
--- /dev/null
+++ b/ext/intl/tests/_files/resourcebundle/root.res
Binary files differ
diff --git a/ext/intl/tests/badargs.phpt b/ext/intl/tests/badargs.phpt
new file mode 100755
index 000000000..9232bbf0c
--- /dev/null
+++ b/ext/intl/tests/badargs.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Check that bad argumens return the same
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+$funcs = get_extension_funcs("intl");
+function ignore_err() {}
+set_error_handler("ignore_err");
+$arg = new stdClass();
+foreach($funcs as $func) {
+ $rfunc = new ReflectionFunction($func);
+ if($rfunc->getNumberOfRequiredParameters() == 0) {
+ continue;
+ }
+ $res = $func($arg);
+ if($res != false) {
+ echo "$func: ";
+ var_dump($res);
+ }
+}
+echo "OK!\n";
+?>
+--EXPECT--
+OK!
diff --git a/ext/intl/tests/collator_get_sort_key.phpt b/ext/intl/tests/collator_get_sort_key.phpt
new file mode 100755
index 000000000..0186c26f6
--- /dev/null
+++ b/ext/intl/tests/collator_get_sort_key.phpt
@@ -0,0 +1,97 @@
+--TEST--
+collator_get_sort_key()
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+/*
+ * Get sort keys using various locales
+ */
+function sort_arrays( $locale, $data )
+{
+ $res_str = '';
+
+ $coll = ut_coll_create( $locale );
+
+ foreach($data as $value) {
+ $res_val = ut_coll_get_sort_key( $coll, $value );
+ $res_str .= "source: ".urlencode($value)."\n".
+ "key: ".urlencode($res_val)."\n";
+ }
+
+ return $res_str;
+}
+
+
+function ut_main()
+{
+ $res_str = '';
+
+ // Regular strings keys
+ $test_params = array(
+ 'abc', 'abd', 'aaa',
+ 'аа', 'а', 'z',
+ '', null , '3',
+ 'y' , 'i' , 'k'
+ );
+
+ $res_str .= sort_arrays( 'en_US', $test_params );
+
+ // Sort a non-ASCII array using ru_RU locale.
+ $test_params = array(
+ 'абг', 'абв', 'жжж', 'эюя'
+ );
+
+ $res_str .= sort_arrays( 'ru_RU', $test_params );
+
+ // Sort an array using Lithuanian locale.
+ $res_str .= sort_arrays( 'lt_LT', $test_params );
+
+ return $res_str . "\n";
+}
+
+include_once( 'ut_common.inc' );
+ut_run();
+?>
+--EXPECT--
+source: abc
+key: %29%2B-%01%07%01%07%00
+source: abd
+key: %29%2B%2F%01%07%01%07%00
+source: aaa
+key: %29%29%29%01%07%01%07%00
+source: %D0%B0%D0%B0
+key: _++%01%06%01%06%00
+source: %D0%B0
+key: _+%01%05%01%05%00
+source: z
+key: %5B%01%05%01%05%00
+source:
+key: %01%01%00
+source:
+key: %01%01%00
+source: 3
+key: %26%80%01%05%01%05%00
+source: y
+key: Y%01%05%01%05%00
+source: i
+key: 9%01%05%01%05%00
+source: k
+key: %3D%01%05%01%05%00
+source: %D0%B0%D0%B1%D0%B3
+key: _+%2C0%01%07%01%07%00
+source: %D0%B0%D0%B1%D0%B2
+key: _+%2C.%01%07%01%07%00
+source: %D0%B6%D0%B6%D0%B6
+key: _LLL%01%07%01%07%00
+source: %D1%8D%D1%8E%D1%8F
+key: %60%05%09%0B%01%07%01%07%00
+source: %D0%B0%D0%B1%D0%B3
+key: _+%2C0%01%07%01%07%00
+source: %D0%B0%D0%B1%D0%B2
+key: _+%2C.%01%07%01%07%00
+source: %D0%B6%D0%B6%D0%B6
+key: _LLL%01%07%01%07%00
+source: %D1%8D%D1%8E%D1%8F
+key: %60%05%09%0B%01%07%01%07%00 \ No newline at end of file
diff --git a/ext/intl/tests/resourcebundle.build b/ext/intl/tests/resourcebundle.build
new file mode 100755
index 000000000..6a7eeae5e
--- /dev/null
+++ b/ext/intl/tests/resourcebundle.build
@@ -0,0 +1,33 @@
+<?php
+// THIS SCRIPT WILL REBUILD ResourceBundle bundles from source files
+
+// DEFINE YOUR ICU TOOLS PATH HERE
+define("ICU_DIR", "C:/PROJECTS/ICU40/BIN/");
+
+$here = dirname(__FILE__);
+
+$dir = new GlobIterator("$here/_files/*.txt", FilesystemIterator::KEY_AS_FILENAME);
+
+foreach($dir as $file) {
+ passthru( ICU_DIR."genrb -s $here/_files/ -d $here/_files/resourcebundle ".$file->getFileName());
+}
+
+$dir = new GlobIterator("$here/_files/resourcebundle/*.res", FilesystemIterator::KEY_AS_FILENAME);
+foreach($dir as $file) {
+ if($file->getFileName() == "res_index.res") continue;
+ $list[] = str_replace(".res", "", $file->getFileName());
+}
+
+$filelist = join(" {\"\"}\n", $list);
+$res_index = <<<END
+res_index:table(nofallback) {
+ InstalledLocales {
+$filelist {""}
+ }
+}
+END;
+file_put_contents("$here/_files/res_index.txt", $res_index);
+
+passthru( ICU_DIR."genrb -s $here/_files/ -d $here/_files/resourcebundle res_index.txt");
+
+// passthru(ICU_DIR."icupkg -tl -a $here/rb.txt -s $here/_files -d $here/_files new $here/_files/resourcebundle.dat"); \ No newline at end of file
diff --git a/ext/intl/tests/resourcebundle.inc b/ext/intl/tests/resourcebundle.inc
new file mode 100644
index 000000000..2ec138bb7
--- /dev/null
+++ b/ext/intl/tests/resourcebundle.inc
@@ -0,0 +1,13 @@
+<?php
+define('BUNDLE', dirname(__FILE__)."/_files/resourcebundle");
+
+function debug( $res ) {
+ if (is_null( $res )) {
+ $ret = "NULL\n";
+ }
+ else {
+ $ret = print_r( $res, true ). "\n";
+ }
+ return $ret . sprintf( "%5d: %s\n", intl_get_error_code(), intl_get_error_message() );
+}
+
diff --git a/ext/intl/tests/resourcebundle_arrayaccess.phpt b/ext/intl/tests/resourcebundle_arrayaccess.phpt
new file mode 100644
index 000000000..ef2c0a8b9
--- /dev/null
+++ b/ext/intl/tests/resourcebundle_arrayaccess.phpt
@@ -0,0 +1,48 @@
+--TEST--
+Test ResourceBundle array access and count - existing/missing keys
+--FILE--
+<?php
+ include "resourcebundle.inc";
+
+ // fall back
+ $r = new ResourceBundle( 'en_US', BUNDLE );
+
+ printf( "length: %d\n", count($r) );
+ printf( "teststring: %s\n", $r['teststring'] );
+ printf( "testint: %d\n", $r['testint'] );
+
+ print_r( $r['testvector'] );
+
+ printf( "testbin: %s\n", bin2hex($r['testbin']) );
+
+ $r2 = $r['testtable'];
+ printf( "testtable: %d\n", $r2['major'] );
+
+ $r2 = $r['testarray'];
+ printf( "testarray: %s\n", $r2[2] );
+
+ $t = $r['nonexisting'];
+ echo debug( $t );
+?>
+--EXPECT--
+length: 6
+teststring: Hello World!
+testint: 2
+Array
+(
+ [0] => 1
+ [1] => 2
+ [2] => 3
+ [3] => 4
+ [4] => 5
+ [5] => 6
+ [6] => 7
+ [7] => 8
+ [8] => 9
+ [9] => 0
+)
+testbin: a1b2c3d4e5f67890
+testtable: 3
+testarray: string 3
+NULL
+ 2: Cannot load resource element 'nonexisting': U_MISSING_RESOURCE_ERROR
diff --git a/ext/intl/tests/resourcebundle_create.phpt b/ext/intl/tests/resourcebundle_create.phpt
new file mode 100644
index 000000000..4d96d3eff
--- /dev/null
+++ b/ext/intl/tests/resourcebundle_create.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Test ResourceBundle::__construct() - existing/missing bundles/locales
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+include "resourcebundle.inc";
+
+function ut_main() {
+ $str_res = '';
+ // all fine
+ $r1 = ut_resourcebundle_create( 'root', BUNDLE );
+ $str_res .= debug( $r1 );
+ $str_res .= print_r( $r1['teststring'], true)."\n";
+
+ // non-root one
+ $r1 = ut_resourcebundle_create( 'es', BUNDLE );
+ $str_res .= debug( $r1 );
+ $str_res .= print_r( $r1['teststring'], true)."\n";
+
+ // fall back
+ $r1 = ut_resourcebundle_create( 'en_US', BUNDLE );
+ $str_res .= debug( $r1 );
+ $str_res .= print_r( $r1['testsring'], true);
+
+ // fall out
+ $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false );
+ $str_res .= debug( $r2 );
+
+ // missing
+ $r3 = ut_resourcebundle_create( 'en_US', 'nonexisting' );
+ $str_res .= debug( $r3 );
+
+ return $str_res;
+}
+
+ include_once( 'ut_common.inc' );
+ ut_run();
+?>
+--EXPECTF--
+ResourceBundle Object
+(
+)
+
+ 0: U_ZERO_ERROR
+Hello World!
+ResourceBundle Object
+(
+)
+
+ 0: U_ZERO_ERROR
+Hola Mundo!
+ResourceBundle Object
+(
+)
+
+ -127: U_USING_DEFAULT_WARNING
+NULL
+ -127: resourcebundle_ctor: Cannot load libICU resource '%s/resourcebundle' without fallback from en_US to root: U_USING_DEFAULT_WARNING
+NULL
+ 2: resourcebundle_ctor: Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR
diff --git a/ext/intl/tests/resourcebundle_individual.phpt b/ext/intl/tests/resourcebundle_individual.phpt
new file mode 100644
index 000000000..182cbf325
--- /dev/null
+++ b/ext/intl/tests/resourcebundle_individual.phpt
@@ -0,0 +1,55 @@
+--TEST--
+Test ResourceBundle::get() and length() - existing/missing keys
+--FILE--
+<?php
+ include "resourcebundle.inc";
+
+function ut_main() {
+ $str_res = '';
+ // fall back
+ $r = ut_resourcebundle_create( 'en_US', BUNDLE );
+
+ $str_res .= sprintf( "length: %d\n", ut_resourcebundle_count($r) );
+ $str_res .= sprintf( "teststring: %s\n", ut_resourcebundle_get($r, 'teststring' ) );
+ $str_res .= sprintf( "testint: %d\n", ut_resourcebundle_get($r, 'testint' ) );
+
+ $str_res .= print_r( ut_resourcebundle_get($r, 'testvector' ), true );
+
+ $str_res .= sprintf( "testbin: %s\n", bin2hex(ut_resourcebundle_get( $r,'testbin' )) );
+
+ $r2 = ut_resourcebundle_get($r, 'testtable' );
+ $str_res .= sprintf( "testtable: %d\n", ut_resourcebundle_get($r2, 'major' ) );
+
+ $r2 = ut_resourcebundle_get($r,'testarray' );
+ $str_res .= sprintf( "testarray: %s\n", ut_resourcebundle_get($r2, 2 ) );
+
+ $t = ut_resourcebundle_get( $r, 'nonexisting' );
+ $str_res .= debug( $t );
+
+ return $str_res;
+}
+ include_once( 'ut_common.inc' );
+ ut_run();
+?>
+--EXPECT--
+length: 6
+teststring: Hello World!
+testint: 2
+Array
+(
+ [0] => 1
+ [1] => 2
+ [2] => 3
+ [3] => 4
+ [4] => 5
+ [5] => 6
+ [6] => 7
+ [7] => 8
+ [8] => 9
+ [9] => 0
+)
+testbin: a1b2c3d4e5f67890
+testtable: 3
+testarray: string 3
+NULL
+ 2: Cannot load resource element 'nonexisting': U_MISSING_RESOURCE_ERROR
diff --git a/ext/intl/tests/resourcebundle_iterator.phpt b/ext/intl/tests/resourcebundle_iterator.phpt
new file mode 100644
index 000000000..31b0768bf
--- /dev/null
+++ b/ext/intl/tests/resourcebundle_iterator.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Test ResourceBundle iterator
+--FILE--
+<?php
+ include "resourcebundle.inc";
+
+ // fall back
+ $r = new ResourceBundle( 'en_US', BUNDLE );
+
+ foreach ($r as $onekey => $oneval) {
+ echo "Here comes $onekey:\n";
+ switch (gettype($oneval)) {
+ case 'string':
+ echo bin2hex( $oneval ) . "\n";
+ break;
+
+ case 'integer':
+ echo "$oneval\n";
+ break;
+
+ default:
+ print_r( $oneval );
+ }
+ echo "\n";
+ }
+
+ echo "Testarray Contents:\n";
+ $r = $r->get( 'testarray' );
+ foreach ($r as $onekey => $oneval) {
+ echo "$onekey => $oneval\n";
+ }
+?>
+--EXPECTF--
+Here comes testarray:
+ResourceBundle Object
+(
+)
+
+Here comes testbin:
+a1b2c3d4e5f67890
+
+Here comes testint:
+2
+
+Here comes teststring:
+48656c6c6f20576f726c6421
+
+Here comes testtable:
+ResourceBundle Object
+(
+)
+
+Here comes testvector:
+Array
+(
+ [0] => 1
+ [1] => 2
+ [2] => 3
+ [3] => 4
+ [4] => 5
+ [5] => 6
+ [6] => 7
+ [7] => 8
+ [8] => 9
+ [9] => 0
+)
+
+Testarray Contents:
+0 => string 1
+1 => string 2
+2 => string 3
diff --git a/ext/intl/tests/resourcebundle_locales.phpt b/ext/intl/tests/resourcebundle_locales.phpt
new file mode 100755
index 000000000..e14a7e5aa
--- /dev/null
+++ b/ext/intl/tests/resourcebundle_locales.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Test ResourceBundle::getLocales
+--SKIPIF--
+<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
+--FILE--
+<?php
+
+include "resourcebundle.inc";
+
+function ut_main() {
+ $str_res = '';
+
+ $str_res .= join("\n", ut_resourcebundle_locales(BUNDLE));
+
+ return $str_res;
+}
+
+ include_once( 'ut_common.inc' );
+ ut_run();
+?>
+--EXPECT--
+es
+root
diff --git a/ext/intl/tests/ut_common.inc b/ext/intl/tests/ut_common.inc
index 4f2036123..09be22bf5 100755
--- a/ext/intl/tests/ut_common.inc
+++ b/ext/intl/tests/ut_common.inc
@@ -59,6 +59,10 @@ function ut_coll_sort_with_sort_keys( $coll, &$arr )
{
return $GLOBALS['oo-mode'] ? $coll->sortWithSortKeys( $arr ) : collator_sort_with_sort_keys( $coll, $arr );
}
+function ut_coll_get_sort_key( $coll, $str )
+{
+ return $GLOBALS['oo-mode'] ? $coll->getSortKey( $str ) : collator_get_sort_key( $coll, $str );
+}
function ut_coll_asort( $coll, &$arr, $sort_flag = Collator::SORT_REGULAR )
{
return $GLOBALS['oo-mode'] ? $coll->asort( $arr, $sort_flag ) : collator_asort( $coll, $arr, $sort_flag );
@@ -385,4 +389,28 @@ function ut_datefmt_localtime( $fmt , $value , &$parse_pos=0 )
{
return $GLOBALS['oo-mode'] ? $fmt->localtime( $value , $parse_pos ) : datefmt_localtime( $fmt , $value , $parse_pos );
}
-?>
+
+function ut_resourcebundle_create( $locale, $bundle, $fallback=true )
+{
+ return $GLOBALS['oo-mode'] ? new ResourceBundle($locale, $bundle, $fallback): resourcebundle_create($locale, $bundle, $fallback);
+}
+function ut_resourcebundle_count($bundle )
+{
+ return $GLOBALS['oo-mode'] ? $bundle->count():resourcebundle_count($bundle);
+}
+function ut_resourcebundle_locales($bundle )
+{
+ return $GLOBALS['oo-mode'] ? ResourceBundle::getLocales($bundle):resourcebundle_locales($bundle);
+}
+function ut_resourcebundle_get($bundle, $idx )
+{
+ return $GLOBALS['oo-mode'] ? $bundle->get($idx):resourcebundle_get($bundle, $idx);
+}
+function ut_resourcebundle_get_error_code($bundle )
+{
+ return $GLOBALS['oo-mode'] ? $bundle->getErrorCode():resourcebundle_get_error_code($bundle);
+}
+function ut_resourcebundle_get_error_message($bundle )
+{
+ return $GLOBALS['oo-mode'] ? $bundle->getErrorMessage():resourcebundle_get_error_message($bundle);
+}