~ubuntu-branches/ubuntu/trusty/mediawiki/trusty

« back to all changes in this revision

Viewing changes to tests/phpunit/languages/LanguageSrTest.php

  • Committer: Package Import Robot
  • Author(s): Thorsten Glaser
  • Date: 2014-03-28 09:56:29 UTC
  • mfrom: (1.3.14)
  • Revision ID: package-import@ubuntu.com-20140328095629-1526y9tchdd507id
Tags: 1:1.19.14+dfsg-1
* New upstream security fix release (Closes: #742857):
  - (bug 62497) SECURITY: Add CSRF token on Special:ChangePassword
  - (bug 62467) Set a title for the context during import on the cli
* Use upstream-provided signing key bundle

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * PHPUnit tests for the Serbian language.
 
4
 * The language can be represented using two scripts:
 
5
 *  - Latin (SR_el)
 
6
 *  - Cyrillic (SR_ec)
 
7
 * Both representations seems to be bijective, hence MediaWiki can convert
 
8
 * from one script to the other.
 
9
 *
 
10
 * @author Antoine Musso <hashar at free dot fr>
 
11
 * @copyright Copyright © 2011, Antoine Musso <hashar at free dot fr>
 
12
 * @file
 
13
 */
 
14
 
 
15
require_once dirname( dirname( __FILE__ ) ) . '/bootstrap.php';
 
16
 
 
17
/** Tests for MediaWiki languages/LanguageTr.php */
 
18
class LanguageSrTest extends MediaWikiTestCase {
 
19
        /* Language object. Initialized before each test */
 
20
        private $lang;
 
21
 
 
22
        function setUp() {
 
23
                $this->lang = Language::factory( 'sr' );
 
24
        }
 
25
        function tearDown() {
 
26
                unset( $this->lang );
 
27
        }
 
28
 
 
29
        ##### TESTS #######################################################
 
30
 
 
31
        function testEasyConversions( ) {
 
32
                $this->assertCyrillic(
 
33
                        'шђчћжШЂЧЋЖ',
 
34
                        'Cyrillic guessing characters'
 
35
                );
 
36
                $this->assertLatin(
 
37
                        'šđč枊ĐČĆŽ',
 
38
                        'Latin guessing characters'
 
39
                );
 
40
        }
 
41
 
 
42
        function testMixedConversions() {
 
43
                $this->assertCyrillic(
 
44
                        'шђчћжШЂЧЋЖ - šđčćž',
 
45
                        'Mostly cyrillic characters'
 
46
                );
 
47
                $this->assertLatin(
 
48
                        'šđč枊ĐČĆŽ - шђчћж',
 
49
                        'Mostly latin characters'
 
50
                );
 
51
        }
 
52
 
 
53
        function testSameAmountOfLatinAndCyrillicGetConverted() {
 
54
                $this->assertConverted(
 
55
                        '4 latin: šđčć | 4 cyrillic: шђчћ',
 
56
                        'sr-ec'
 
57
                );
 
58
                $this->assertConverted(
 
59
                        '4 latin: šđčć | 4 cyrillic: шђчћ',
 
60
                        'sr-el'
 
61
                );
 
62
        }
 
63
 
 
64
        /**
 
65
         * @author Nikola Smolenski
 
66
         */
 
67
        function testConversionToCyrillic() {
 
68
                $this->assertEquals( 'абвг',
 
69
                        $this->convertToCyrillic( 'abvg' )
 
70
                );
 
71
                $this->assertEquals( 'абвг',
 
72
                        $this->convertToCyrillic( 'абвг' )
 
73
                );
 
74
                $this->assertEquals( 'abvgшђжчћ',
 
75
                        $this->convertToCyrillic( 'abvgшђжчћ' )
 
76
                );
 
77
                $this->assertEquals( 'абвгшђжчћ',
 
78
                        $this->convertToCyrillic( 'абвгšđžčć' )
 
79
                );
 
80
                // Roman numerals are not converted
 
81
                $this->assertEquals( 'а I б II в III г IV шђжчћ',
 
82
                        $this->convertToCyrillic( 'a I b II v III g IV šđžčć' )
 
83
                );
 
84
        }
 
85
 
 
86
        function testConversionToLatin() {
 
87
                $this->assertEquals( 'abcd',
 
88
                        $this->convertToLatin( 'abcd' )
 
89
                );
 
90
                $this->assertEquals( 'abcd',
 
91
                        $this->convertToLatin( 'абцд' )
 
92
                );
 
93
                $this->assertEquals( 'abcdšđžčć',
 
94
                        $this->convertToLatin( 'abcdшђжчћ' )
 
95
                );
 
96
                $this->assertEquals( 'абцдšđžčć',
 
97
                        $this->convertToLatin( 'абцдšđžčć' )
 
98
                );
 
99
        }
 
100
 
 
101
        /** @dataProvider providePluralFourForms */
 
102
        function testPluralFourForms( $result, $value ) {
 
103
                $forms = array( 'one', 'few', 'many', 'other' );
 
104
                $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 
105
        }
 
106
 
 
107
        function providePluralFourForms() {
 
108
                return array (
 
109
                        array( 'one', 1 ),
 
110
                        array( 'many', 11 ),
 
111
                        array( 'one', 91 ),
 
112
                        array( 'one', 121 ),
 
113
                        array( 'few', 2 ),
 
114
                        array( 'few', 3 ),
 
115
                        array( 'few', 4 ),
 
116
                        array( 'few', 334 ),
 
117
                        array( 'many', 5 ),
 
118
                        array( 'many', 15 ),
 
119
                        array( 'many', 120 ),
 
120
                );
 
121
        }
 
122
        /** @dataProvider providePluralTwoForms */
 
123
        function testPluralTwoForms( $result, $value ) {
 
124
                $forms = array( 'one', 'several' );
 
125
                $this->assertEquals( $result, $this->lang->convertPlural( $value, $forms ) );
 
126
        }
 
127
        function providePluralTwoForms() {
 
128
                return array (
 
129
                        array( 'one', 1 ),
 
130
                        array( 'several', 11 ),
 
131
                        array( 'several', 91 ),
 
132
                        array( 'several', 121 ),
 
133
                );
 
134
        }
 
135
 
 
136
        ##### HELPERS #####################################################
 
137
        /**
 
138
         *Wrapper to verify text stay the same after applying conversion
 
139
         * @param $text string Text to convert
 
140
         * @param $variant string Language variant 'sr-ec' or 'sr-el'
 
141
         * @param $msg string Optional message
 
142
         */
 
143
        function assertUnConverted( $text, $variant, $msg = '' ) {
 
144
                $this->assertEquals(
 
145
                        $text,
 
146
                        $this->convertTo( $text, $variant ),
 
147
                        $msg
 
148
                );
 
149
        }
 
150
        /**
 
151
         * Wrapper to verify a text is different once converted to a variant.
 
152
         * @param $text string Text to convert
 
153
         * @param $variant string Language variant 'sr-ec' or 'sr-el'
 
154
         * @param $msg string Optional message
 
155
         */
 
156
        function assertConverted( $text, $variant, $msg = '' ) {
 
157
                $this->assertNotEquals(
 
158
                        $text,
 
159
                        $this->convertTo( $text, $variant ),
 
160
                        $msg
 
161
                );
 
162
        }
 
163
 
 
164
        /**
 
165
         * Verifiy the given Cyrillic text is not converted when using
 
166
         * using the cyrillic variant and converted to Latin when using
 
167
         * the Latin variant.
 
168
         */
 
169
        function assertCyrillic( $text, $msg = '' ) {
 
170
                $this->assertUnConverted( $text, 'sr-ec', $msg );
 
171
                $this->assertConverted( $text, 'sr-el', $msg );
 
172
        }
 
173
        /**
 
174
         * Verifiy the given Latin text is not converted when using
 
175
         * using the Latin variant and converted to Cyrillic when using
 
176
         * the Cyrillic variant.
 
177
         */
 
178
        function assertLatin( $text, $msg = '' ) {
 
179
                $this->assertUnConverted( $text, 'sr-el', $msg );
 
180
                $this->assertConverted( $text, 'sr-ec', $msg );
 
181
        }
 
182
 
 
183
 
 
184
        /** Wrapper for converter::convertTo() method*/
 
185
        function convertTo( $text, $variant ) {
 
186
                return $this
 
187
                        ->lang
 
188
                        ->mConverter
 
189
                        ->convertTo(
 
190
                                $text, $variant
 
191
                        );
 
192
        }
 
193
        function convertToCyrillic( $text ) {
 
194
                return $this->convertTo( $text, 'sr-ec' );
 
195
        }
 
196
        function convertToLatin( $text ) {
 
197
                return $this->convertTo( $text, 'sr-el' );
 
198
        }
 
199
}