bug 28040 Turkish: properly handle dotted and dotless i
authorAntoine Musso <hashar@users.mediawiki.org>
Tue, 15 Mar 2011 21:56:54 +0000 (21:56 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Tue, 15 Mar 2011 21:56:54 +0000 (21:56 +0000)
As mentioned by Bawolff on code review, r83970 only handled case change
of the first character lacking full strings support.

This patch override the uc and lc methods for the Turkish language (tr)
using preg_replace() which know about unicode. Other possible choices
would have been:
 - strtr() =>  outputs garbage
 - mbstring => can not know we handle turkish and transform i to I!

I have amended the RELEASE-NOTES to reflect this patch.

Some new tests are added as well to cover the regular functions as
well as the specific Turkish overriding. Result in testdox:

LanguageTr
[x] Change case of first char being dotted and dotless i
[x] Language tr lower casing override
[x] Language tr upper casing override
[x] Upper casing of a string with dotted and dot less i
[x] Lower casing of a string with dotted and dot less i

RELEASE-NOTES
languages/classes/LanguageTr.php
tests/phpunit/languages/LanguageTrTest.php

index 3f8bba0..576edb0 100644 (file)
@@ -277,7 +277,8 @@ changes to languages because of Bugzilla reports.
 * (bug 27681) Set $namespaceGenderAliases for Portuguese (pt and pt-br)
 * (bug 27785) Fallback language for Kabardian (kbd) is English now.
 * (bug 27825) Raw watchlist edit message now uses formatted numbers.
-* (bug 28040) Turkish: properly lower case 'I' to 'ı' (dotless i)
+* (bug 28040) Turkish: properly lower case 'I' to 'ı' (dotless i) and
+  uppercase 'i' to 'İ' (dotted i)
 
 == Compatibility ==
 
index dec5045..297f6b4 100644 (file)
@@ -28,4 +28,16 @@ class LanguageTr extends Language {
                }
        }
 
+       /** @see bug 28040 */
+       function uc( $string ) {
+               $string = preg_replace( '/i/', 'İ', $string );
+               return parent::uc( $string );
+       }
+
+       /** @see bug 28040 */
+       function lc( $string ) {
+               $string = preg_replace( '/I/', 'ı', $string );
+               return parent::lc( $string );
+       }
+
 }
index ddc8ea6..eb3601d 100644 (file)
@@ -24,7 +24,7 @@ class LanguageTrTest extends MediaWikiTestCase {
         * @see http://en.wikipedia.org/wiki/Dotted_and_dotless_I
         * @dataProvider provideDottedAndDotlessI
         */
-       function testDottedAndDotlessI( $func, $input, $inputCase, $expected ) {
+       function testChangeCaseOfFirstCharBeingDottedAndDotlessI( $func, $input, $inputCase, $expected ) {
                if( $func == 'ucfirst' ) {
                        $res = $this->lang->ucfirst( $input );
                } elseif( $func == 'lcfirst' ) {
@@ -62,6 +62,60 @@ class LanguageTrTest extends MediaWikiTestCase {
                        array( 'lcfirst', 'IPhone', 'upper', 'ıPhone' ),
 
                );
+       } 
+
+##### LanguageTr specificities  #############################################
+       /**
+        * @cover LanguageTr:lc
+        * See @bug 28040
+        */
+       function testLanguageTrLowerCasingOverride() {
+               $this->assertEquals( 'ııııı', $this->lang->lc( 'IIIII') );
+       }
+       /**
+        * @cover LanguageTr:uc
+        * See @bug 28040
+        */
+       function testLanguageTrUpperCasingOverride() {
+               $this->assertEquals( 'İİİİİ', $this->lang->uc( 'iiiii') );
+       }
+
+##### Upper casing a string #################################################
+       /**
+        * Generic test for the Turkish dotted and dotless I strings
+        * See @bug 28040
+        * @dataProvider provideUppercaseStringsWithDottedAndDotlessI
+        */
+       function testUpperCasingOfAStringWithDottedAndDotLessI( $expected, $input ) {
+               $this->assertEquals( $expected, $this->lang->uc( $input ) );
+       }
+       function provideUppercaseStringsWithDottedAndDotlessI() {
+               return array(
+                       # expected, input string to uc()
+                       array( 'IIIII', 'ııııı' ),
+                       array( 'IIIII', 'IIIII' ), #identity
+                       array( 'İİİİİ', 'iiiii' ), # Specifically handled by LanguageTr:uc
+                       array( 'İİİİİ', 'İİİİİ' ), #identity
+               );
+       }
+
+##### Lower casing a string #################################################
+       /**
+        * Generic test for the Turkish dotted and dotless I strings
+        * See @bug 28040
+        * @dataProvider provideLowercaseStringsWithDottedAndDotlessI
+        */
+       function testLowerCasingOfAStringWithDottedAndDotLessI( $expected, $input ) {
+               $this->assertEquals( $expected, $this->lang->lc( $input ) );
+       }
+       function provideLowercaseStringsWithDottedAndDotlessI() {
+               return array(
+                       # expected, input string to lc()
+                       array( 'ııııı', 'IIIII' ), # Specifically handled by LanguageTr:lc
+                       array( 'ııııı', 'ııııı' ), #identity
+                       array( 'iiiii', 'İİİİİ' ),
+                       array( 'iiiii', 'iiiii' ), #identity
+               );
        }
 
 }