resourcebundle_individual.phpt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. --TEST--
  2. Test ResourceBundle::get() and length() - existing/missing keys
  3. --EXTENSIONS--
  4. intl
  5. --FILE--
  6. <?php
  7. include "resourcebundle.inc";
  8. function ut_main() {
  9. $str_res = '';
  10. // fall back
  11. $r = ut_resourcebundle_create( 'en_US', BUNDLE );
  12. $str_res .= sprintf( "length: %d\n", ut_resourcebundle_count($r) );
  13. $str_res .= sprintf( "teststring: %s\n", ut_resourcebundle_get($r, 'teststring' ) );
  14. $str_res .= sprintf( "testint: %d\n", ut_resourcebundle_get($r, 'testint' ) );
  15. $str_res .= print_r( ut_resourcebundle_get($r, 'testvector' ), true );
  16. $str_res .= sprintf( "testbin: %s\n", bin2hex(ut_resourcebundle_get( $r,'testbin' )) );
  17. $r2 = ut_resourcebundle_get($r, 'testtable' );
  18. $str_res .= sprintf( "testtable: %d\n", ut_resourcebundle_get($r2, 'major' ) );
  19. $r2 = ut_resourcebundle_get($r,'testarray' );
  20. $str_res .= sprintf( "testarray: %s\n", ut_resourcebundle_get($r2, 2 ) );
  21. $t = ut_resourcebundle_get( $r, 'nonexisting' );
  22. $str_res .= debug( $t );
  23. // Make sure accessing existing after non-existing works.
  24. $t = ut_resourcebundle_get( $r, 'teststring' );
  25. $str_res .= debug( $t );
  26. return $str_res;
  27. }
  28. include_once( 'ut_common.inc' );
  29. ut_run();
  30. ?>
  31. --EXPECT--
  32. length: 6
  33. teststring: Hello World!
  34. testint: 2
  35. Array
  36. (
  37. [0] => 1
  38. [1] => 2
  39. [2] => 3
  40. [3] => 4
  41. [4] => 5
  42. [5] => 6
  43. [6] => 7
  44. [7] => 8
  45. [8] => 9
  46. [9] => 0
  47. )
  48. testbin: a1b2c3d4e5f67890
  49. testtable: 3
  50. testarray: string 3
  51. NULL
  52. 2: Cannot load resource element 'nonexisting': U_MISSING_RESOURCE_ERROR
  53. Hello World!
  54. 0: U_ZERO_ERROR