xref: /php-src/ext/intl/tests/bug75317.phpt (revision 74859783)
1--TEST--
2Bug #75317 (UConverter::setDestinationEncoding changes source instead of destinatination)
3--EXTENSIONS--
4intl
5--FILE--
6<?php
7$utf8 = UConverter::getAliases('utf-8')[0];
8$utf16 = UConverter::getAliases('utf-16')[0];
9$utf32 = UConverter::getAliases('utf-32')[0];
10$latin1 = UConverter::getAliases('latin1')[0];
11
12function printResult($actual, $expected) {
13    var_dump($actual === $expected ? true : "expected: $expected, actual: $actual");
14}
15
16// test default values
17$c = new UConverter();
18printResult($c->getDestinationEncoding(), $utf8);
19printResult($c->getSourceEncoding(), $utf8);
20
21// test constructor args
22$c = new UConverter('utf-16', 'latin1');
23printResult($c->getDestinationEncoding(), $utf16);
24printResult($c->getSourceEncoding(), $latin1);
25
26// test setters
27var_dump($c->setDestinationEncoding('utf-8'));
28var_dump($c->setSourceEncoding('utf-32'));
29printResult($c->getDestinationEncoding(), $utf8);
30printResult($c->getSourceEncoding(), $utf32);
31
32// test invalid inputs dont change values
33var_dump($c->setDestinationEncoding('foobar') === false);
34var_dump($c->setSourceEncoding('foobar') === false);
35printResult($c->getDestinationEncoding(), $utf8);
36printResult($c->getSourceEncoding(), $utf32);
37
38?>
39--EXPECT--
40bool(true)
41bool(true)
42bool(true)
43bool(true)
44bool(true)
45bool(true)
46bool(true)
47bool(true)
48bool(true)
49bool(true)
50bool(true)
51bool(true)
52