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 variant:", "\n";
15var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46 + 10));
16
17echo "empty domain:", "\n";
18var_dump(idn_to_ascii("", 0, INTL_IDNA_VARIANT_UTS46));
19
20echo "with error, but no details arg:", "\n";
21var_dump(idn_to_ascii("www.fußball.com-", 0, INTL_IDNA_VARIANT_UTS46));
22
23echo "with error, with details arg:", "\n";
24var_dump(idn_to_ascii("www.fußball.com-", IDNA_NONTRANSITIONAL_TO_ASCII,
25    INTL_IDNA_VARIANT_UTS46, $foo));
26var_dump($foo);
27
28echo "with error, with details arg, contextj:", "\n";
29var_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));
33var_dump($foo);
34var_dump($foo["errors"]==IDNA_ERROR_CONTEXTJ);
35
36?>
37--EXPECTF--
38=> PHP level errors
39bad variant:
40
41Warning: idn_to_ascii(): idn_to_ascii: invalid variant, must be INTL_IDNA_VARIANT_UTS46 in %s on line %d
42bool(false)
43empty domain:
44
45Warning: idn_to_ascii(): idn_to_ascii: empty domain name in %s on line %d
46bool(false)
47with error, but no details arg:
48bool(false)
49with error, with details arg:
50bool(false)
51array(3) {
52  ["result"]=>
53  string(23) "www.xn--fuball-cta.com-"
54  ["isTransitionalDifferent"]=>
55  bool(true)
56  ["errors"]=>
57  int(16)
58}
59with error, with details arg, contextj:
60bool(false)
61array(3) {
62  ["result"]=>
63  string(18) "www.xn--ab-m1t.com"
64  ["isTransitionalDifferent"]=>
65  bool(true)
66  ["errors"]=>
67  int(4096)
68}
69bool(true)
70