1--TEST--
2Temporary test of mbstring's HTML-ENTITIES 'encoding'
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7
8/* Using mbstring to convert strings to and from HTML entities has already been deprecated
9 * So this test should be removed when the HTML-ENTITIES 'encoding' is */
10
11function convertToEntities($raw, $htmlent) {
12  $converted = mb_convert_encoding($raw, 'HTML-ENTITIES', 'UTF-8');
13  if ($converted !== $htmlent)
14    die('Expected ' . bin2hex($raw) . ' to convert to "' . $htmlent . '"; actually got "' . $converted . '"');
15}
16
17function convertFromEntities($raw, $htmlent) {
18  $converted = mb_convert_encoding($htmlent, 'UTF-8', 'HTML-ENTITIES');
19  if ($converted !== $raw)
20    die('Expected "' . $htmlent . '" to convert to ' . bin2hex($raw) . '; actually got ' . bin2hex($converted));
21}
22
23function testConversion($raw, $htmlent) {
24  convertToEntities($raw, $htmlent);
25  convertFromEntities($raw, $htmlent);
26}
27
28testConversion('', '');
29testConversion('abc', 'abc');
30testConversion('&<>', '&<>');
31
32convertFromEntities('"', '&quot;');
33convertFromEntities("\xC3\xAC", '&igrave;');
34
35convertFromEntities('あ', '&#x3042;');
36testConversion('あ', '&#12354;');
37testConversion('abcあxyz', 'abc&#12354;xyz');
38
39convertFromEntities('&#x;', '&#x;');
40convertFromEntities('&#;', '&#;');
41convertFromEntities('&#', '&#');
42convertFromEntities('&', '&');
43
44convertFromEntities("\x00", '&#00000;');
45
46testConversion(str_repeat('あ', 100), str_repeat('&#12354;', 100));
47
48convertFromEntities("&;", "&;");
49convertFromEntities("&f;", "&f;");
50
51convertFromEntities("&A", "&&#65;");
52convertFromEntities("&A", "&&#x41;");
53
54echo "Done!\n";
55?>
56--EXPECTF--
57Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in %s
58
59Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in %s
60
61Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in %s
62
63Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in %s
64
65Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in %s
66
67Deprecated: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in %s
68Done!
69