TPParseTest.php
Go to the documentation of this file.00001 <?php
00014 class TPParseTest extends MediaWikiTestCase {
00015 public function testGetTranslationPageText() {
00016 $title = Title::newFromText( __CLASS__ );
00017 $page = TranslatablePage::newFromText(
00018 $title,
00019 '<translate>Hello <tvar|abc>peter!</></translate>'
00020 );
00021 $prefix = $title->getPrefixedDBKey() . '/';
00022 $parse = $page->getParse();
00023
00024 $collection = array();
00025 $expected = 'Hello peter!';
00026
00027 $actual = $parse->getTranslationPageText( $collection );
00028 $this->assertEquals(
00029 $expected,
00030 $actual,
00031 'Variable declarations are substituted when no translation'
00032 );
00033
00034 foreach ( $parse->sections as $section ) {
00035 $key = $prefix . $section->id;
00036 $message = new FatMessage( $key, $section->getText() );
00037 $message->setTranslation( $section->getText() );
00038 $collection[$key] = $message;
00039 }
00040
00041 $actual = $parse->getTranslationPageText( $collection );
00042 $this->assertEquals(
00043 $expected,
00044 $actual,
00045 'Variable declarations are substituted in source language'
00046 );
00047
00048 foreach ( $parse->sections as $section ) {
00049 $key = $prefix . $section->id;
00050 $message = new FatMessage( $key, $section->getText() );
00051 $message->setTranslation( $section->getTextForTrans() );
00052 $collection[$key] = $message;
00053 }
00054 $actual = $parse->getTranslationPageText( $collection );
00055 $this->assertEquals(
00056 $expected,
00057 $actual,
00058 'Variable declarations are substituted in translation'
00059 );
00060 }
00061 }