JavaFFSTest.php

Go to the documentation of this file.
00001 <?php
00011 class JavaFFSTest extends MediaWikiTestCase {
00012 
00013     protected $groupConfiguration = array(
00014         'BASIC' => array(
00015             'class' => 'FileBasedMessageGroup',
00016             'id' => 'test-id',
00017             'label' => 'Test Label',
00018             'namespace' => 'NS_MEDIAWIKI',
00019             'description' => 'Test description',
00020         ),
00021         'FILES' => array(
00022             'class' => 'JavaFFS',
00023         ),
00024     );
00025 
00026     public function testParsing() {
00027         $file =
00028             <<<PROPERTIES
00029             # You are reading the ".properties" entry.
00030 ! The exclamation mark can also mark text as comments.
00031 website = <nowiki>http://en.wikipedia.org/</nowiki>
00032 language = English
00033 # The backslash below tells the application to continue reading
00034 # the value onto the next line.
00035 message = Welcome to \
00036           Wikipedia!
00037 # Add spaces to the key
00038 key\ with\ spaces = Value that can be looked up with "key with spaces".
00039 key-with-{curlies} = Value that can be looked up with "key-with-{curlies}".
00040 PROPERTIES;
00041 
00045         $group = MessageGroupBase::factory( $this->groupConfiguration );
00046         $ffs = new JavaFFS( $group );
00047         $parsed = $ffs->readFromVariable( $file );
00048         $expected = array(
00049             'website' => '<nowiki>http://en.wikipedia.org/</nowiki>',
00050             'language' => 'English',
00051             'message' => 'Welcome to Wikipedia!',
00052             'key with spaces' => 'Value that can be looked up with "key with spaces".',
00053             // We expect this one to be mangled for storage
00054             'key-with-=7Bcurlies=7D' => 'Value that can be looked up with "key-with-{curlies}".',
00055         );
00056         $expected = array( 'MESSAGES' => $expected, 'AUTHORS' => array() );
00057         $this->assertEquals( $expected, $parsed );
00058     }
00059 
00063     public function testRowRoundtrip( $key, $sep, $value, $comment ) {
00064         $write = JavaFFS::writeRow( $key, $sep, $value );
00065         // Trim the trailing newline
00066         $write = rtrim( $write );
00067         list( $newkey, $newvalue ) = JavaFFS::readRow( $write, $sep );
00068 
00069         $this->assertSame( $key, $newkey, "Key survives roundtrip in testdata: $comment" );
00070         $this->assertSame( $value, $newvalue, "Value survives roundtrip in testdata: $comment" );
00071     }
00072 
00073     public function rowValuesProvider() {
00074         return array(
00075             array( 'key', '=', 'value', 'simple row' ),
00076             array( 'key', ':', 'value', 'row with different sep' ),
00077             array( 'key', '=', 'val=ue', 'row with sep inside value' ),
00078             array( 'k=ey', '=', 'value', 'row with sep inside key' ),
00079             array( '!key', '=', 'value', 'row with ! at the beginning of key' ),
00080             array( 'k!ey', '=', 'value', 'row with ! inside key' ),
00081             array( '#key', '=', 'value', 'row with # at the beginning of key' ),
00082             array( 'k#ey', '=', 'value', 'row with # inside key' ),
00083             array( 'k{ey}', '=', 'value', 'row with { and } inside key' ),
00084             array( 'k\\tey', '=', 'value\\', 'row with escapes' ),
00085             array( '01234', '=', '13.34', 'row with numbers' ),
00086             array( '\\n\\tкая', '=', 'кая', 'row with annoying characteres' ),
00087             array( '=', '=', '', 'row with empty value' ),
00088             array( '#k   e\\=y#', '=', '=v!\\=alue\\ \\\\', 'complex row' ),
00089         );
00090     }
00091 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3