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 long, 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
65Notice: idn_to_ascii(): 4 arguments were provided, but INTL_IDNA_VARIANT_2003 only takes 3 - extra argument ignored in %s on line %d
66string(7) "foo.com"
67with error, but no details arg:
68bool(false)
69with error, with details arg:
70bool(false)
71array(3) {
72  ["result"]=>
73  string(23) "www.xn--fuball-cta.com-"
74  ["isTransitionalDifferent"]=>
75  bool(true)
76  ["errors"]=>
77  int(16)
78}
79with error, with details arg, contextj:
80bool(false)
81array(3) {
82  ["result"]=>
83  string(18) "www.xn--ab-m1t.com"
84  ["isTransitionalDifferent"]=>
85  bool(true)
86  ["errors"]=>
87  int(4096)
88}
89bool(true)
90