AndroidXmlFFSTest.php
Go to the documentation of this file.00001 <?php
00010 class AndroidXmlFFSTest extends MediaWikiTestCase {
00011
00012 protected $groupConfiguration = array(
00013 'BASIC' => array(
00014 'class' => 'FileBasedMessageGroup',
00015 'id' => 'test-id',
00016 'label' => 'Test Label',
00017 'namespace' => 'NS_MEDIAWIKI',
00018 'description' => 'Test description',
00019 ),
00020 'FILES' => array(
00021 'class' => 'AndroidXmlFFS',
00022 'sourcePattern' => '',
00023 ),
00024 );
00025
00026 public function testParsing() {
00027 $file =
00028 <<<XML
00029 <?xml version="1.0" encoding="utf-8"?>
00030 <resources>
00031 <string name="wpt_voicerec">Voice recording</string>
00032 <string name="wpt_stillimage" fuzzy="true">Picture</string>
00033 </resources>
00034 XML;
00035
00039 $group = MessageGroupBase::factory( $this->groupConfiguration );
00040 $ffs = new AndroidXmlFFS( $group );
00041 $parsed = $ffs->readFromVariable( $file );
00042 $expected = array(
00043 'wpt_voicerec' => 'Voice recording',
00044 'wpt_stillimage' => '!!FUZZY!!Picture',
00045 );
00046 $expected = array( 'MESSAGES' => $expected, 'AUTHORS' => array() );
00047 $this->assertEquals( $expected, $parsed );
00048 }
00049
00050 public function testWrite() {
00054 $group = MessageGroupBase::factory( $this->groupConfiguration );
00055 $ffs = new AndroidXmlFFS( $group );
00056
00057 $messages = array(
00058 'ko=26ra' => 'wawe',
00059 'foobar' => '!!FUZZY!!Kissa kala <koira> "a\'b',
00060 );
00061 $collection = new MockMessageCollection( $messages );
00062
00063 $xml = $ffs->writeIntoVariable( $collection );
00064 $parsed = $ffs->readFromVariable( $xml );
00065 $expected = array( 'MESSAGES' => $messages, 'AUTHORS' => array() );
00066 $this->assertEquals( $expected, $parsed );
00067 }
00068 }
00069
00070 class MockMessageCollection extends MessageCollection {
00071 public function __construct( $messages ) {
00072 $keys = array_keys( $messages );
00073 $this->keys = array_combine( $keys, $keys );
00074 foreach ( $messages as $key => $value ) {
00075 $m = new FatMessage( $key, $value );
00076 $m->setTranslation( $value );
00077 $this->messages[$key] = $m;
00078 }
00079
00080 $this->messages['foobar']->addTag( 'fuzzy' );
00081 }
00082
00083 public function filter( $type, $condition = true, $value = null ) {
00084 }
00085 }