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