/**
  * @dataProvider provideTestFiles
  */
 public function testParsing($file)
 {
     $filename = basename($file);
     list($pagename, ) = explode('.', $filename, 2);
     $title = Title::newFromText($pagename);
     $translatablePage = TranslatablePage::newFromText($title, file_get_contents($file));
     $pattern = $file;
     if ($filename === 'FailNotAtomic.ptfile') {
         $this->markTestSkipped('Extended validation not yet implemented');
     }
     $failureExpected = strpos($pagename, 'Fail') === 0;
     if ($failureExpected) {
         $this->setExpectedException('TPException');
     }
     $parse = $translatablePage->getParse();
     $this->assertInstanceOf('TPParse', $parse);
     if (file_exists("{$pattern}.ptsource")) {
         $source = $parse->getSourcePageText();
         $this->assertEquals($source, file_get_contents("{$pattern}.ptsource"));
     }
     if (file_exists("{$pattern}.pttarget")) {
         $target = $parse->getTranslationPageText(MessageCollection::newEmpty('foo'));
         $this->assertEquals($target, file_get_contents("{$pattern}.pttarget"));
     }
     // Custom tests written in php
     if (file_exists("{$pattern}.pttest")) {
         require "{$pattern}.pttest";
     }
 }
コード例 #2
0
	public function execute() {
		$dir = dirname( __FILE__ );
		$testDirectory = "$dir/../tests/pagetranslation";
		$testFiles = glob( "$testDirectory/*.ptfile" );

		foreach ( $testFiles as $file ) {
			$filename = basename( $file );
			list( $pagename, ) = explode( '.', $filename, 2 );
			$title = Title::newFromText( $pagename );
			$translatablePage = TranslatablePage::newFromText( $title, file_get_contents( $file ) );

			$pattern = realpath( "$testDirectory" ) . "/$pagename";

			$failureExpected = strpos( $pagename, 'Fail' ) === 0;

			try {
				$parse = $translatablePage->getParse();
				if ( $failureExpected ) {
					$target = $parse->getTranslationPageText( MessageCollection::newEmpty( "foo" ) );
					$this->output( "Testfile $filename should have failed... see $pattern.pttarget.fail\n" );
					file_put_contents( "$pattern.pttarget.fail", $target );
				}
			} catch ( TPException $e ) {
				if ( !$failureExpected ) {
					$this->output( "Testfile $filename failed to parse... see $pattern.ptfile.fail\n" );
					file_put_contents( "$pattern.ptfile.fail", $e->getMessage() );
				}
				continue;
			}

			if ( file_exists( "$pattern.ptsource" ) ) {
				$source = $parse->getSourcePageText();
				if ( $source !== file_get_contents( "$pattern.ptsource" ) ) {
					$this->output( "Testfile $filename failed with source page output... writing $pattern.ptsource.fail\n" );
					file_put_contents( "$pattern.ptsource.fail", $source );
				}
			}

			if ( file_exists( "$pattern.pttarget" ) ) {
				$target = $parse->getTranslationPageText( MessageCollection::newEmpty( "foo" ) );
				if ( $target !== file_get_contents( "$pattern.pttarget" ) ) {
					$this->output( "Testfile $filename failed with target page output... writing $pattern.pttarget.fail\n" );
					file_put_contents( "$pattern.pttarget.fail", $target );
				}
			}

			// Custom tests written in php
			if ( file_exists( "$pattern.pttest" ) ) {
				require( "$pattern.pttest" );
			}
		}
	}