mb_http_output.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. mb_http_output()
  3. --EXTENSIONS--
  4. mbstring
  5. --FILE--
  6. <?php
  7. //TODO: Add more encoding. Wrong parameter type test.
  8. ini_set('include_path', __DIR__);
  9. include_once('common.inc');
  10. // Set HTTP output encoding to ASCII
  11. $r = mb_http_output('ASCII');
  12. ($r === TRUE) ? print "OK_ASCII_SET\n" : print "NG_ASCII_SET\n";
  13. $enc = mb_http_output();
  14. print "$enc\n";
  15. // Set HTTP output encoding to SJIS
  16. $r = mb_http_output('SJIS');
  17. ($r === TRUE) ? print "OK_SJIS_SET\n" : print "NG_SJIS_SET\n";
  18. $enc = mb_http_output();
  19. print "$enc\n";
  20. // Set HTTP output encoding to JIS
  21. $r = mb_http_output('JIS');
  22. ($r === TRUE) ? print "OK_JIS_SET\n" : print "NG_JIS_SET\n";
  23. $enc = mb_http_output();
  24. print "$enc\n";
  25. // Set HTTP output encoding to UTF8
  26. $r = mb_http_output('UTF-8');
  27. ($r === TRUE) ? print "OK_UTF-8_SET\n" : print "NG_UTF-8_SET\n";
  28. $enc = mb_http_output();
  29. print "$enc\n";
  30. // Set HTTP output encoding to EUC-JP
  31. $r = mb_http_output('EUC-JP');
  32. ($r === TRUE) ? print "OK_EUC-JP_SET\n" : print "NG_EUC-JP_SET\n";
  33. $enc = mb_http_output();
  34. print "$enc\n";
  35. // Invalid parameters
  36. print "== INVALID PARAMETER ==\n";
  37. // Note: Bad string raise ValueError. Bad Type raise Notice (Type Conversion) and ValueError
  38. try {
  39. $r = mb_http_output('BAD_NAME');
  40. print 'NG_BAD_SET' . \PHP_EOL;
  41. } catch (\ValueError $e) {
  42. echo $e->getMessage() . \PHP_EOL;
  43. }
  44. $enc = mb_http_output();
  45. print "$enc\n";
  46. ?>
  47. --EXPECT--
  48. OK_ASCII_SET
  49. ASCII
  50. OK_SJIS_SET
  51. SJIS
  52. OK_JIS_SET
  53. JIS
  54. OK_UTF-8_SET
  55. UTF-8
  56. OK_EUC-JP_SET
  57. EUC-JP
  58. == INVALID PARAMETER ==
  59. mb_http_output(): Argument #1 ($encoding) must be a valid encoding, "BAD_NAME" given
  60. EUC-JP