mediawiki-extensions-AbuseF.../tests/legacyParserTest.php
Daimona Eaytoy f2c1beec44 Replace double-equals with triple-equals
Since double-equals are evil. I left some of them in place where I
wasn't sure, but I may be changed some which were intended to be
doubles. It could be a good idea to delay merging this patch until we'll
have more code coverage.

Change-Id: I1721a3ba532d481e3ecf35f51099c1438b6b73b2
2019-03-22 16:12:13 +01:00

53 lines
1.2 KiB
PHP

<?php
/**
* Runs tests against the PHP parser.
*/
require_once getenv( 'MW_INSTALL_PATH' ) !== false
? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
: __DIR__ . '/../../../maintenance/commandLine.inc';
$tester = new AbuseFilterParser;
$test_path = __DIR__ . "/parserTests";
$tests = glob( $test_path . "/*.t" );
$check = 0;
$pass = 0;
foreach ( $tests as $test ) {
$result = substr( $test, 0, -2 ) . ".r";
$rule = trim( file_get_contents( $test ) );
$output = trim( file_get_contents( $result ) ) === 'MATCH';
$testname = basename( $test );
print "Trying test $testname...\n";
try {
$check++;
$actual = intval( $tester->parse( $rule ) );
if ( $actual === $output ) {
print "-PASSED.\n";
$pass++;
} else {
print "-FAILED - expected output $output, actual output $actual.\n";
print "-Expression: $rule\n";
// export
$vars = var_export( $tester->mTokens, true );
file_put_contents( $test . '.parsed', $vars );
}
} catch ( AFPException $excep ) {
print "-FAILED - exception " . $excep->getMessage() . " with input $rule\n";
// export
$vars = var_export( $tester->mTokens, true );
file_put_contents( $test . '.parsed', $vars );
}
}
print "$pass tests passed out of $check\n";