00001 <?php 00014 class MediaWikiMessageCheckerTest extends MediaWikiTestCase { 00015 00019 public function testGetPluralFormCount( $expected, $code, $comment ) { 00020 $provided = MediaWikiMessageChecker::GetPluralFormCount( $code ); 00021 $this->assertEquals( $expected, $provided, $comment ); 00022 } 00023 00024 public function getPluralFormCountProvider() { 00025 return array( 00026 array( 2, 'en', 'English has two plural forms' ), 00027 array( 3, 'ro', 'Romanian has three plural forms' ), 00028 array( 5, 'br', 'Breton has five plural forms' ), 00029 ); 00030 } 00031 00035 public function testGetPluralForms( $expected, $string, $comment ) { 00036 $provided = MediaWikiMessageChecker::getPluralForms( $string ); 00037 $this->assertEquals( $expected, $provided, $comment ); 00038 } 00039 00040 public function getPluralFormsProvider() { 00041 return array( 00042 array( 00043 array( array( '1', '2' ) ), 00044 'a{{PLURAL:#|1|2}}b', 00045 'one plural magic word is parsed correctly' 00046 ), 00047 00048 array( 00049 array( array( '1', '2' ), array( '3', '4' ) ), 00050 '{{PLURAL:#|1|2}}{{PLURAL:#|3|4}}', 00051 'two plural magic words are parsed correctly' 00052 ), 00053 00054 array( 00055 array( array( '1', '2{{car}}3' ) ), 00056 'a{{PLURAL:#|1|2{{car}}3}}', 00057 'one plural magic word with curlies inside is parsed correctly' 00058 ), 00059 00060 array( 00061 array( array( '0=0', '1=one', '1', '2' ) ), 00062 'a{{PLURAL:#|0=0|1=one|1|2}}', 00063 'one plural magic word with explicit forms is parsed correctly' 00064 ), 00065 array( 00066 array(), 00067 'a{{PLURAL:#|0=0|1=one|1|2}', 00068 'unclosed plural tag is ignored' 00069 ), 00070 array( 00071 array( array( '1=foo', '{{GENDER:#_he}}' ) ), 00072 'a{{PLURAL:#|1=foo|{{GENDER:#|he}}}}', 00073 'pipes in subtemplates are ignored by replacing them with other char' 00074 ), 00075 ); 00076 } 00077 00081 public function testRemoveExplicitPluralForms( $expected, $forms, $comment ) { 00082 $provided = MediaWikiMessageChecker::removeExplicitPluralForms( $forms ); 00083 $this->assertEquals( $expected, $provided, $comment ); 00084 } 00085 00086 public function removeExplicitPluralFormsProvider() { 00087 return array( 00088 array( 00089 array( '1', '2' ), 00090 array( '1', '2' ), 00091 'default forms are not removed', 00092 ), 00093 00094 array( 00095 array( '1', '2' ), 00096 array( '0=0', '1', '0=0', '2', '1=one' ), 00097 'explicit forms are removed regardless of position', 00098 ), 00099 ); 00100 } 00101 }