| 1 | # test suite for MT::I18N modules |
|---|
| 2 | |
|---|
| 3 | # english / utf-8 |
|---|
| 4 | # english / latin-1 |
|---|
| 5 | # french / utf-8 |
|---|
| 6 | # french / latin-1 |
|---|
| 7 | # japanese / utf-8 |
|---|
| 8 | # japanese / shift_jis |
|---|
| 9 | # japanese / euc |
|---|
| 10 | |
|---|
| 11 | # routines to test |
|---|
| 12 | # substr_text |
|---|
| 13 | # length_text |
|---|
| 14 | # wrap_text |
|---|
| 15 | # break_up_text |
|---|
| 16 | # first_n_text |
|---|
| 17 | # convert_high_ascii |
|---|
| 18 | # const |
|---|
| 19 | |
|---|
| 20 | use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib'; |
|---|
| 21 | use Test::More tests => 16; |
|---|
| 22 | |
|---|
| 23 | use Encode; |
|---|
| 24 | use MT; |
|---|
| 25 | use MT::Util; |
|---|
| 26 | my $mt = new MT; |
|---|
| 27 | |
|---|
| 28 | MT->set_language('en_US'); |
|---|
| 29 | require MT::I18N; |
|---|
| 30 | |
|---|
| 31 | is(MT::I18N::const('LENGTH_ENTRY_TITLE_FROM_TEXT'), 5); |
|---|
| 32 | |
|---|
| 33 | MT->config('PublishCharset', 'utf-8'); |
|---|
| 34 | my $utf8_str = 'IñtërnâtiÎnà lizÊtiÞn'; |
|---|
| 35 | is(length($utf8_str), 27); # make sure this is in bytes |
|---|
| 36 | is(MT::I18N::substr_text('this is a test', 0, 4), 'this'); |
|---|
| 37 | is(MT::I18N::substr_text($utf8_str, 0, 4), 'Iñtë'); |
|---|
| 38 | is(MT::I18N::length_text($utf8_str), 20); |
|---|
| 39 | is(MT::I18N::encode_text($utf8_str, undef, 'utf-8'), $utf8_str); |
|---|
| 40 | is(MT::Util::dirify($utf8_str), "internationalizaetion"); |
|---|
| 41 | |
|---|
| 42 | MT->config('PublishCharset', 'iso-8859-1'); |
|---|
| 43 | my $latin1_str = $utf8_str; |
|---|
| 44 | Encode::from_to($latin1_str, 'utf-8', 'iso-8859-1'); |
|---|
| 45 | is(length($latin1_str), 20); |
|---|
| 46 | is(MT::I18N::substr_text($latin1_str, 0, 4), substr($latin1_str, 0, 4)); |
|---|
| 47 | is(MT::I18N::length_text($latin1_str), 20); |
|---|
| 48 | is(MT::I18N::encode_text($latin1_str, undef, 'utf-8'), $utf8_str); |
|---|
| 49 | is(MT::I18N::convert_high_ascii($latin1_str), 'Internationalizaetion'); |
|---|
| 50 | |
|---|
| 51 | MT->set_language('ja'); |
|---|
| 52 | MT->config('UseJcodeModule', 0); |
|---|
| 53 | MT->config('PublishCharset', 'utf-8'); |
|---|
| 54 | |
|---|
| 55 | $utf8_str = 'ãµã€ããŒã·ã§ãããããããŠã©ãŒã¯ãã³ãåœãã'; |
|---|
| 56 | is(length($utf8_str), 66); |
|---|
| 57 | is(MT::I18N::substr_text($utf8_str, 0, 4), 'ãµã€ããŒ'); |
|---|
| 58 | is(MT::I18N::length_text($utf8_str), 22); |
|---|
| 59 | is(MT::I18N::encode_text($utf8_str, undef, 'utf-8'), $utf8_str); |
|---|