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