idn_uts46_errors.phpt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --TEST--
  2. IDN UTS #46 API error tests
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded('intl'))
  6. die('skip');
  7. if (!defined('INTL_IDNA_VARIANT_UTS46'))
  8. die('skip no UTS #46 API');
  9. --FILE--
  10. <?php
  11. ini_set("intl.error_level", E_WARNING);
  12. echo "=> PHP level errors", "\n";
  13. echo "bad args:", "\n";
  14. var_dump(idn_to_ascii("", 0, array()));
  15. var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46, $foo, null));
  16. echo "bad variant:", "\n";
  17. var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46 + 10));
  18. echo "empty domain:", "\n";
  19. var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46));
  20. echo "fourth arg for 2003 variant (only notice raised):", "\n";
  21. var_dump(idn_to_ascii("foo.com", 0, INTL_IDNA_VARIANT_2003, $foo));
  22. echo "with error, but no details arg:", "\n";
  23. var_dump(idn_to_ascii("www.fußball.com-", 0, INTL_IDNA_VARIANT_UTS46));
  24. echo "with error, with details arg:", "\n";
  25. var_dump(idn_to_ascii("www.fußball.com-", IDNA_NONTRANSITIONAL_TO_ASCII,
  26. INTL_IDNA_VARIANT_UTS46, $foo));
  27. var_dump($foo);
  28. echo "with error, with details arg, contextj:", "\n";
  29. var_dump(idn_to_ascii(
  30. html_entity_decode("www.a&#x200D;b.com", 0, "UTF-8"),
  31. IDNA_NONTRANSITIONAL_TO_ASCII | IDNA_CHECK_CONTEXTJ,
  32. INTL_IDNA_VARIANT_UTS46, $foo));
  33. var_dump($foo);
  34. var_dump($foo["errors"]==IDNA_ERROR_CONTEXTJ);
  35. --EXPECTF--
  36. => PHP level errors
  37. bad args:
  38. Warning: idn_to_ascii() expects parameter 3 to be int, array given in %s on line %d
  39. Warning: idn_to_ascii(): idn_to_ascii: bad arguments in %s on line %d
  40. NULL
  41. Warning: idn_to_ascii() expects at most 4 parameters, 5 given in %s on line %d
  42. Warning: idn_to_ascii(): idn_to_ascii: bad arguments in %s on line %d
  43. NULL
  44. bad variant:
  45. Warning: idn_to_ascii(): idn_to_ascii: invalid variant, must be one of {INTL_IDNA_VARIANT_2003, INTL_IDNA_VARIANT_UTS46} in %s on line %d
  46. bool(false)
  47. empty domain:
  48. Warning: idn_to_ascii(): idn_to_ascii: empty domain name in %s on line %d
  49. bool(false)
  50. fourth arg for 2003 variant (only notice raised):
  51. Deprecated: idn_to_ascii(): INTL_IDNA_VARIANT_2003 is deprecated in %s on line %d
  52. Notice: idn_to_ascii(): 4 arguments were provided, but INTL_IDNA_VARIANT_2003 only takes 3 - extra argument ignored in %s on line %d
  53. string(7) "foo.com"
  54. with error, but no details arg:
  55. bool(false)
  56. with error, with details arg:
  57. bool(false)
  58. array(3) {
  59. ["result"]=>
  60. string(23) "www.xn--fuball-cta.com-"
  61. ["isTransitionalDifferent"]=>
  62. bool(true)
  63. ["errors"]=>
  64. int(16)
  65. }
  66. with error, with details arg, contextj:
  67. bool(false)
  68. array(3) {
  69. ["result"]=>
  70. string(18) "www.xn--ab-m1t.com"
  71. ["isTransitionalDifferent"]=>
  72. bool(true)
  73. ["errors"]=>
  74. int(4096)
  75. }
  76. bool(true)