Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PMA_kanji-encoding_test.php « libraries « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6d6518cee24749cd2857eecc35e9969c5a4307f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Tests for Kanji Encoding Library
 *
 * @package PhpMyAdmin-test
 */

/*
 * Include to test.
 */
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/kanji-encoding.lib.php';

/**
 * Tests for Kanji Encoding Library
 *
 * @package PhpMyAdmin-test
 */
class PMA_Kanji_Encoding_Test extends PHPUnit_Framework_TestCase
{
    /**
     * Test for PMA_Kanji_checkEncoding
     *
     * @param string $encoding Encoding to set
     * @param string $expected Expected encoding list
     *
     * @return void
     * @test
     * @dataProvider checkEncodingData
     */
    public function testCheckEncoding($encoding, $expected)
    {
        mb_internal_encoding($encoding);
        $this->assertTrue(PMA_Kanji_checkEncoding());
        $this->assertEquals($expected, $GLOBALS['kanji_encoding_list']);
    }

    /**
     * Data provider for testPMA_Kanji_checkEncoding
     *
     * @return array Test data
     */
    public function checkEncodingData()
    {
        return array(
            array('UTF-8', 'ASCII,SJIS,EUC-JP,JIS'),
            array('EUC-JP', 'ASCII,EUC-JP,SJIS,JIS')
        );
    }

    /**
     * Test for PMA_Kanji_changeOrder
     *
     * @param string $kanji_test_list current list
     * @param string $expected        expected list
     *
     * @return void
     * @test
     * @dataProvider changeOrderData
     */
    public function testChangeOrder($kanji_test_list, $expected)
    {
        $GLOBALS['kanji_encoding_list'] = $kanji_test_list;
        $this->assertTrue(PMA_Kanji_changeOrder());
        $this->assertEquals($expected, $GLOBALS['kanji_encoding_list']);
    }

    /**
     * Data Provider for testPMA_Kanji_changeOrder
     *
     * @return array Test data
     */
    public function changeOrderData()
    {
        return array(
            array('ASCII,SJIS,EUC-JP,JIS', 'ASCII,EUC-JP,SJIS,JIS'),
            array('ASCII,EUC-JP,SJIS,JIS', 'ASCII,SJIS,EUC-JP,JIS')
        );
    }

    /**
     * Test for PMA_Kanji_strConv
     *
     * @return void
     * @test
     */
    public function testStrConv()
    {
        $this->assertEquals(
            'test',
            PMA_Kanji_strConv('test', '', '')
        );

        $GLOBALS['kanji_encoding_list'] = 'ASCII,SJIS,EUC-JP,JIS';

        $this->assertEquals(
            'test è',
            PMA_Kanji_strConv('test è', '', '')
        );

        $this->assertEquals(
            mb_convert_encoding('test è', 'ASCII', 'SJIS'),
            PMA_Kanji_strConv('test è', 'ASCII', '')
        );

        $this->assertEquals(
            mb_convert_kana('全角', 'KV', 'SJIS'),
            PMA_Kanji_strConv('全角', '', 'kana')
        );
    }


    /**
     * Test for PMA_Kanji_fileConv
     *
     * @return void
     * @test
     */
    public function testFileConv()
    {
        $file_str = "教育漢字常用漢字";
        $filename = 'test.kanji';
        $file = fopen($filename, 'w');
        fputs($file, $file_str);
        fclose($file);
        $GLOBALS['kanji_encoding_list'] = 'ASCII,EUC-JP,SJIS,JIS';

        $result = PMA_Kanji_fileConv($filename, 'JIS', 'kana');

        $string = file_get_contents($result);
        PMA_Kanji_changeOrder();
        $expected = PMA_Kanji_strConv($file_str, 'JIS', 'kana');
        PMA_Kanji_changeOrder();
        $this->assertEquals($string, $expected);
        unlink($result);
    }


    /**
     * Test for PMA_Kanji_encodingForm
     *
     * @return void
     * @test
     */
    public function testEncodingForm()
    {
        $actual = PMA_Kanji_encodingForm();
        $this->assertContains(
            '<input type="radio" name="knjenc"',
            $actual
        );
        $this->assertContains(
            'type="radio" name="knjenc"',
            $actual
        );
        $this->assertContains(
            '<input type="radio" name="knjenc" value="EUC-JP" id="kj-euc" />',
            $actual
        );
        $this->assertContains(
            '<input type="radio" name="knjenc" value="SJIS" id="kj-sjis" />',
            $actual
        );
        $this->assertContains(
            '<input type="checkbox" name="xkana" value="kana" id="kj-kana" />',
            $actual
        );
    }
}