*/ class AbuseFilterParserTest extends MediaWikiTestCase { /** * @return AbuseFilterParser */ static function getParser() { static $parser = null; if ( !$parser ) { $parser = new AbuseFilterParser(); } return $parser; } /** * @dataProvider readTests */ public function testParser( $testName, $rule, $expected ) { if ( !class_exists( 'AntiSpoof' ) && preg_match( '/(cc)?norm\(/i', $rule ) ) { // The norm and ccnorm parser functions aren't working correctly without AntiSpoof $this->markTestSkipped( 'Parser test ' . $testName . ' requires the AntiSpoof extension' ); } $parser = self::getParser(); $actual = $parser->parse( $rule ); $this->assertEquals( $expected, $actual, 'Running parser test ' . $testName ); } /** * @return array */ public function readTests() { $tests = array(); $testPath = __DIR__ . "/../parserTests"; $testFiles = glob( $testPath . "/*.t" ); foreach ( $testFiles as $testFile ) { $testName = substr( $testFile, 0, -2 ); $resultFile = $testName . '.r'; $rule = trim( file_get_contents( $testFile ) ); $result = trim( file_get_contents( $resultFile ) ) == 'MATCH'; $tests[] = array( basename( $testName ), $rule, $result ); } return $tests; } }