PageTranslationParserTest.php
Go to the documentation of this file.00001 <?php
00016 class PageTranslationParserTest extends MediaWikiTestCase {
00017 public static function provideTestFiles() {
00018 $dir = __DIR__;
00019 $testFiles = glob( "$dir/pagetranslation/*.ptfile" );
00020 foreach ( $testFiles as $i => $file ) {
00021 $testFiles[$i] = array( $file );
00022 }
00023
00024 return $testFiles;
00025 }
00026
00030 public function testParsing( $file ) {
00031
00032 $filename = basename( $file );
00033 list( $pagename, ) = explode( '.', $filename, 2 );
00034 $title = Title::newFromText( $pagename );
00035 $translatablePage = TranslatablePage::newFromText( $title, file_get_contents( $file ) );
00036
00037 $pattern = $file;
00038
00039 if ( $filename === 'FailNotAtomic.ptfile' ) {
00040 $this->markTestSkipped( 'Extented validation not yet implemented' );
00041 }
00042
00043 $failureExpected = strpos( $pagename, 'Fail' ) === 0;
00044
00045 if ( $failureExpected ) {
00046 $this->setExpectedException( 'TPException' );
00047 }
00048
00049 $parse = $translatablePage->getParse();
00050 $this->assertInstanceOf( 'TPParse', $parse );
00051
00052 if ( file_exists( "$pattern.ptsource" ) ) {
00053 $source = $parse->getSourcePageText();
00054 $this->assertEquals( $source, file_get_contents( "$pattern.ptsource" ) );
00055 }
00056
00057 if ( file_exists( "$pattern.pttarget" ) ) {
00058 $target = $parse->getTranslationPageText( MessageCollection::newEmpty( 'foo' ) );
00059 $this->assertEquals( $target, file_get_contents( "$pattern.pttarget" ) );
00060 }
00061
00062
00063 if ( file_exists( "$pattern.pttest" ) ) {
00064 require "$pattern.pttest";
00065 }
00066 }
00067 }