MediaWikiExtensionFFSTest.php

Go to the documentation of this file.
00001 <?php
00013 class MediaWikiExtensionFFSTest extends MediaWikiTestCase {
00014     protected $conf = array(
00015         'BASIC' => array(
00016             'class' => 'MediaWikiExtensionMessageGroup',
00017             'id' => 'test-id',
00018             'label' => 'Test Label',
00019             'namespace' => 'NS_MEDIAWIKI',
00020             'description' => 'Test description',
00021         ),
00022         'FILES' => array(
00023             'class' => 'MediaWikiExtensionFFS',
00024         ),
00025     );
00026 
00027     protected function setUp() {
00028         parent::setUp();
00029         $this->setMwGlobals( array(
00030             'wgTranslateDocumentationLanguageCode' => 'qqq',
00031         ) );
00032     }
00033 
00034     public function testWriteReal() {
00035         if ( !method_exists( 'LanguageNames', 'getNames' ) ) {
00036             $this->markTestSkipped( 'Cldr extension is not installed' );
00037         }
00038 
00039         $this->conf['FILES']['sourcePattern'] = __DIR__ . '/../data/Example.i18n.php';
00040         $ffs = MessageGroupBase::factory( $this->conf )->getFFS();
00041         $obj = new ReflectionObject( $ffs );
00042         $method = $obj->getMethod( 'writeReal' );
00043         $method->setAccessible( true );
00044         $collection = new MockMessageCollectionForExport();
00045         $result = $method->invoke( $ffs, $collection );
00046 
00047         $expected = file_get_contents( __DIR__ . '/../data/Example-result.i18n.php' );
00048         $this->assertEquals( $expected, $result );
00049     }
00050 
00051     public function testGenerateMessageBlock() {
00052         $ffs = MessageGroupBase::factory( $this->conf )->getFFS();
00053         $obj = new ReflectionObject( $ffs );
00054         $method = $obj->getMethod( 'generateMessageBlock' );
00055         $method->setAccessible( true );
00056         $collection = new MockMessageCollectionForExport();
00057         $mangler = StringMatcher::emptyMatcher();
00058 
00059         $result = $method->invoke( $ffs, $collection, $mangler );
00060 
00061         $expected = "\n\t'translatedmsg' => 'translation',\n\t'fuzzymsg' => 'translation', # Fuzzy\n";
00062         $this->assertEquals( $expected, $result );
00063     }
00064 
00068     public function testQuote( $source, $expected ) {
00069         $class = new ReflectionClass( 'MediaWikiExtensionFFS' );
00070         $method = $class->getMethod( 'quote' );
00071         $method->setAccessible( true );
00072         $result = $method->invoke( null, $source );
00073         $this->assertEquals( $expected, $result );
00074     }
00075 
00076     public static function provideQuotableStrings() {
00077         return array(
00078             array( 'key', "'key'" ),
00079             array( 'normal $1 variable', "'normal $1 variable'" ),
00080             array( 'abnormal $foo variable', "'abnormal \$foo variable'" ),
00081             array( 'quote " and quote \'', "'quote \" and quote \\''" ),
00082             array( 'quote " and quote \' twice \'', "\"quote \\\" and quote ' twice '\"" ),
00083         );
00084     }
00085 
00089     public function testParseAuthorsFromString( $source, $expected ) {
00090         $class = new ReflectionClass( 'MediaWikiExtensionFFS' );
00091         $method = $class->getMethod( 'parseAuthorsFromString' );
00092         $method->setAccessible( true );
00093         $result = $method->invoke( null, $source );
00094         $this->assertEquals( $expected, $result );
00095     }
00096 
00097     public static function provideComments() {
00098         $comment =
00099             <<<PHP
00104 PHP;
00105 
00106         return array(
00107             array( $comment, array( 'Purodha', 'The Evil IP address' ) ),
00108         );
00109     }
00110 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3