OSDN Git Service

d4d7b9836c012c6d46cdde25f667a5a945ca0758
[ethna/ethna.git] / test / Plugin / Smarty / Ethna_Plugin_Smarty_modifier_wordwrap_i18n_Test.php
1 <?php
2 // vim: foldmethod=marker
3 /**
4  *  Ethna_Plugin_Smarty_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_Plugin_Smarty_modifier_wordwrap_i18n_Test
13 /**
14  *  Test Case For modifier.wordwrap_i18n.php
15  *
16  *  @access public
17  */
18 class Ethna_Plugin_Smarty_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         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8);
38
39         //    UTF-8
40         $input_str = 'あいうaえaおaかきaaaく';
41         $expected = "あいうa\n"
42                   . "えaおaか\n"
43                   . "きaaaく";
44         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8);
45
46         //    UTF-8
47         $input_str = 'あいうaえaaaaaaaaaaaaaaaaaaaおかahaかきaaaく';
48         $expected = "あいうa\n"
49                   . "えaaaaaa\n"
50                   . "aaaaaaaa\n"
51                   . "aaaaaお\n"
52                   . "かahaか\n"
53                   . "きaaaく";
54         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8);
55     }
56
57     function test_smarty_modifier_wordwrap_i18n_indent()
58     {
59         //
60         //    indent を指定した場合、はじめの行は
61         //    インデントされないので注意
62         //
63
64         //    UTF-8
65         $input_str = 'あいうaえaおaかきaaaくけこ';
66         $expected = "あいうa\n"
67                   . "    えaおaか\n"
68                   . "    きaaaく\n"
69                   . '    けこ';
70         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8, "\n", 4);
71     }
72
73     function test_smarty_modifier_wordwrap_i18n_break()
74     {
75         //    UTF-8
76         $input_str = 'あいうaえaおaかきaaaくけこ';
77         $expected = "あいうa\r\n"
78                   . "    えaおaか\r\n"
79                   . "    きaaaく\r\n"
80                   . '    けこ';
81         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8, "\r\n", 4);
82     }
83
84     function test_smarty_modifier_wordwrap_i18n_space()
85     {
86         //    UTF-8
87         $input_str = 'あいうaえaおaかきaaaくけこ     ';
88         $expected = "あいうa\r\n"
89                   . "    えaおaか\r\n"
90                   . "    きaaaく\r\n"
91                   . "    けこ    \r\n"
92                   . '     ';
93         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8, "\r\n", 4);
94     }
95
96     function test_smarty_modifier_wordwrap_i18n_kana()
97     {
98         //    UTF-8
99         $input_str = 'あいうイエオaえaおaかきaaaくけこ';
100         $expected = "あいうイエ\r\n"
101                   . "    オaえaおa\r\n"
102                   . "    かきaaa\r\n"
103                   . '    くけこ';
104         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8, "\r\n", 4);
105     }
106
107     function test_smarty_modifier_wordwrap_i18n_alphabet()
108     {
109         $input_str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz';
110         $expected = 'abcdefgh<br />'
111                   . 'ijklmnop<br />'
112                   . 'qrstuvwx<br />'
113                   . 'yzabcdef<br />'
114                   . 'ghijklmn<br />'
115                   . 'opqrstuv<br />'
116                   . 'wxyz';
117         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8, '<br />');
118
119         $input_str = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv';
120         $expected = 'abcdefgh<br />'
121                   . 'ijklmnop<br />'
122                   . 'qrstuvwx<br />'
123                   . 'yzabcdef<br />'
124                   . 'ghijklmn<br />'
125                   . 'opqrstuv';
126         $this->_test_smarty_modifier_wordwrap_i18n($expected, $input_str, 8, '<br />');
127     }
128
129     function _test_smarty_modifier_wordwrap_i18n($expected, $input_str, $width, $break = "\n", $indent = 0)
130     {
131         unset($GLOBALS['_Ethna_controller']);
132
133         $ctl =& new Ethna_Controller();
134         $actual = smarty_modifier_wordwrap_i18n($input_str, $width, $break, $indent);
135         $this->assertEqual($expected, $actual);
136         unset($GLOBALS['_Ethna_controller']);
137
138         //     SJIS
139         $ctl =& new Ethna_Controller();
140         $ctl->setClientEncoding('SJIS');
141
142         $sjis_input = mb_convert_encoding($input_str, 'SJIS', 'UTF-8');
143         $sjis_expected = mb_convert_encoding($expected, 'SJIS', 'UTF-8');
144         $sjis_actual = smarty_modifier_wordwrap_i18n($sjis_input, $width, $break, $indent);
145         $this->assertEqual($sjis_expected, $sjis_actual);
146         unset($GLOBALS['_Ethna_controller']);
147
148         //     EUC-JP
149         $ctl =& new Ethna_Controller();
150         $ctl->setClientEncoding('EUC-JP');
151
152         $eucjp_input = mb_convert_encoding($input_str, 'EUC-JP', 'UTF-8');
153         $eucjp_expected = mb_convert_encoding($expected, 'EUC-JP', 'UTF-8');
154         $eucjp_actual = smarty_modifier_wordwrap_i18n($eucjp_input, $width, $break, $indent);
155         $this->assertEqual($eucjp_expected, $eucjp_actual);
156     }
157     // }}}
158 }
159 // }}}
160
161 ?>