1--TEST--
2Temporary test of mbstring's Base64 'encoding'
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7
8/* Using mbstring to convert strings to and from Base64 has already been deprecated
9 * So this test should be removed when the Base64 'encoding' is */
10
11function testConversion($raw, $base64) {
12  $converted = mb_convert_encoding($raw, 'Base64', '8bit');
13  if ($converted !== $base64)
14    die('Expected ' . bin2hex($raw) . ' to convert to "' . $base64 . '"; actually got "' . $converted . '"');
15  $converted = mb_convert_encoding($base64, '8bit', 'Base64');
16  if ($converted !== $raw)
17    die('Expected "' . $base64 . '" to convert to ' . bin2hex($raw) . '; actually got ' . bin2hex($converted));
18}
19
20testConversion('', '');
21testConversion('a', 'YQ==');
22testConversion('ab', 'YWI=');
23testConversion("\x01\x02\x03", 'AQID');
24testConversion("\xFF\xFE\x11\x22", '//4RIg==');
25testConversion("\x00", 'AA==');
26testConversion("\x00\x00", 'AAA=');
27testConversion("\x00\x00\x00", 'AAAA');
28
29testConversion(str_repeat("ABCDEFGHIJ", 20), "QUJDREVGR0hJSkFCQ0RFRkdISUpBQkNERUZHSElKQUJDREVGR0hJSkFCQ0RFRkdISUpBQkNERUZH\r\nSElKQUJDREVGR0hJSkFCQ0RFRkdISUpBQkNERUZHSElKQUJDREVGR0hJSkFCQ0RFRkdISUpBQkNE\r\nRUZHSElKQUJDREVGR0hJSkFCQ0RFRkdISUpBQkNERUZHSElKQUJDREVGR0hJSkFCQ0RFRkdISUpB\r\nQkNERUZHSElKQUJDREVGR0hJSkFCQ0RFRkdISUo=");
30
31echo "Done!\n";
32?>
33--EXPECTF--
34Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
35
36Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
37
38Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
39
40Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
41
42Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
43
44Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
45
46Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
47
48Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
49
50Deprecated: mb_convert_encoding(): Handling Base64 via mbstring is deprecated; use base64_encode/base64_decode instead in %s
51Done!
52