OSDN Git Service

- release branch for 2.5.0 preview3. this will be merged to trunk after releasing...
[ethna/ethna.git] / test / Plugin / Smarty / Ethna_SmartyPlugin_modifier_wordwrap_i18n_Test.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_SmartyPlugin_modifier_wordwrap_i18n_Test.php
5  *
6  *  @author     Yoshinari Takaoka <takaoka@beatcraft.com>
7  *  @version    $Id$
8  */
9
10 require_once ETHNA_BASE . '/class/Plugin/Smarty/modifier.wordwrap_i18n.php';
11
12 //{{{    Ethna_SmartyPlugin_modifier_wordwrap_i18n_Test
13 /**
14  *  Test Case For modifier_wordwrap_i18n.php
15  *
16  *  @access public
17  */
18 class Ethna_SmartyPlugin_modifier_wordwrap_i18n_Test extends Ethna_UnitTestBase
19 {
20     function tearDown()
21     {
22         $ctl =& new Ethna_Controller();
23         $ctl->setClientEncoding('UTF-8');
24     }
25
26     // {{{  test_smarty_modifier_wordwrap_i18n
27     function test_smarty_modifier_wordwrap_i18n()
28     {
29         unset($GLOBALS['_Ethna_controller']);
30
31         //    UTF-8
32         $input_str = 'あいうaえaおaかきaaaくけこ';
33         $expected = "あいうa\n"
34                   . "えaおaか\n"
35                   . "きaaaく\n"
36                   . 'けこ';
37
38         $ctl =& new Ethna_Controller();
39         $actual = smarty_modifier_wordwrap_i18n($input_str, 8);
40         $this->assertEqual($expected, $actual);
41         unset($GLOBALS['_Ethna_controller']);
42
43         //     SJIS
44         $ctl =& new Ethna_Controller();
45         $ctl->setClientEncoding('SJIS');
46
47         $sjis_input = mb_convert_encoding($input_str, 'SJIS', 'UTF-8');
48         $sjis_expected = mb_convert_encoding($expected, 'SJIS', 'UTF-8');
49         $sjis_actual = smarty_modifier_wordwrap_i18n($sjis_input, 8);
50         $this->assertEqual($sjis_expected, $sjis_actual);
51         unset($GLOBALS['_Ethna_controller']);
52
53         //     EUC-JP
54         $ctl =& new Ethna_Controller();
55         $ctl->setClientEncoding('EUC-JP');
56
57         $eucjp_input = mb_convert_encoding($input_str, 'EUC-JP', 'UTF-8');
58         $eucjp_expected = mb_convert_encoding($expected, 'EUC-JP', 'UTF-8');
59         $eucjp_actual = smarty_modifier_wordwrap_i18n($eucjp_input, 8);
60         $this->assertEqual($eucjp_expected, $eucjp_actual);
61     }
62
63     function test_smarty_modifier_wordwrap_i18n_indent()
64     {
65         //
66         //    indent を指定した場合、はじめの行は
67         //    インデントされないので注意
68         //
69
70         unset($GLOBALS['_Ethna_controller']);
71
72         //    UTF-8
73         $input_str = 'あいうaえaおaかきaaaくけこ';
74         $expected = "あいうa\n"
75                   . "    えaおaか\n"
76                   . "    きaaaく\n"
77                   . '    けこ';
78
79         $ctl =& new Ethna_Controller();
80         $actual = smarty_modifier_wordwrap_i18n($input_str, 8, "\n", 4);
81         $this->assertEqual($expected, $actual);
82         unset($GLOBALS['_Ethna_controller']);
83
84         //     SJIS
85         $ctl =& new Ethna_Controller();
86         $ctl->setClientEncoding('SJIS');
87
88         $sjis_input = mb_convert_encoding($input_str, 'SJIS', 'UTF-8');
89         $sjis_expected = mb_convert_encoding($expected, 'SJIS', 'UTF-8');
90         $sjis_actual = smarty_modifier_wordwrap_i18n($sjis_input, 8, "\n", 4);
91         $this->assertEqual($sjis_expected, $sjis_actual);
92         unset($GLOBALS['_Ethna_controller']);
93
94         //     EUC-JP
95         $ctl =& new Ethna_Controller();
96         $ctl->setClientEncoding('EUC-JP');
97
98         $eucjp_input = mb_convert_encoding($input_str, 'EUC-JP', 'UTF-8');
99         $eucjp_expected = mb_convert_encoding($expected, 'EUC-JP', 'UTF-8');
100         $eucjp_actual = smarty_modifier_wordwrap_i18n($eucjp_input, 8, "\n", 4);
101         $this->assertEqual($eucjp_expected, $eucjp_actual);
102     }
103
104     function test_smarty_modifier_wordwrap_i18n_break()
105     {
106         unset($GLOBALS['_Ethna_controller']);
107
108         //    UTF-8
109         $input_str = 'あいうaえaおaかきaaaくけこ';
110         $expected = "あいうa\r\n"
111                   . "    えaおaか\r\n"
112                   . "    きaaaく\r\n"
113                   . '    けこ';
114
115         $ctl =& new Ethna_Controller();
116         $actual = smarty_modifier_wordwrap_i18n($input_str, 8, "\r\n", 4);
117         $this->assertEqual($expected, $actual);
118         unset($GLOBALS['_Ethna_controller']);
119
120         //     SJIS
121         $ctl =& new Ethna_Controller();
122         $ctl->setClientEncoding('SJIS');
123
124         $sjis_input = mb_convert_encoding($input_str, 'SJIS', 'UTF-8');
125         $sjis_expected = mb_convert_encoding($expected, 'SJIS', 'UTF-8');
126         $sjis_actual = smarty_modifier_wordwrap_i18n($sjis_input, 8, "\r\n", 4);
127         $this->assertEqual($sjis_expected, $sjis_actual);
128         unset($GLOBALS['_Ethna_controller']);
129
130         //     EUC-JP
131         $ctl =& new Ethna_Controller();
132         $ctl->setClientEncoding('EUC-JP');
133
134         $eucjp_input = mb_convert_encoding($input_str, 'EUC-JP', 'UTF-8');
135         $eucjp_expected = mb_convert_encoding($expected, 'EUC-JP', 'UTF-8');
136         $eucjp_actual = smarty_modifier_wordwrap_i18n($eucjp_input, 8, "\r\n", 4);
137         $this->assertEqual($eucjp_expected, $eucjp_actual);
138     }
139     // }}}
140 }
141 // }}}
142
143 ?>