mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-12 08:49:28 +00:00
03da29b9da
The abusefilter array test failed because length( ['a', 'b', 'c'] ) returned 12 instead of 6. That was du to it converted the array to a string with new line seperated values first before measuring the string length. Changed that behaviour to act like the php count() function or the python len() function which seems far more useful to me. The old behaviour can be established using length( string( array ) ). Change-Id: I16646891837c9743ca5af2dd328077a7225bb5f1
53 lines
1.2 KiB
PHP
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__ . "/tests";
|
|
$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 = ( $cont = 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";
|