r101369 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101368‎ | r101369 | r101370 >
Date:17:30, 31 October 2011
Author:hashar
Status:deferred (Comments)
Tags:
Comment:
(bug 28643) tests for Serbian script conversions

Input by Nikola Smolenski.
Modified paths:
  • /branches/nikola/phase3/tests/phpunit/languages/LanguageSrTest.php (added) (history)

Diff [purge]

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

Sign-offs

UserFlagDate
Nikola Smolenskitested15:05, 16 November 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r103131Adding test for roman numeralsnikola06:18, 15 November 2011
r103327bug 28643 improvement to serbian variants conversion...hashar15:12, 16 November 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86623(bug 28643) Merge Serbian language variant conversion improvements to trunk (...demon14:02, 21 April 2011

Comments

#Comment by Hashar (talk | contribs)   14:31, 16 November 2011

reviewed by nikola by email

Status & tagging log