Rename AbuseFilterCachingParser -> FilterEvaluator

It's an evaluator, not a parser.

Change-Id: Ib6d33e8423ea72709cf5a33f4397ba33e352ea80
This commit is contained in:
Daimona Eaytoy 2021-09-01 00:26:13 +02:00
parent 79c7f568f5
commit f8e9ac7e2a
21 changed files with 81 additions and 86 deletions

View file

@ -4,8 +4,8 @@ namespace MediaWiki\Extension\AbuseFilter\EditBox;
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
use MediaWiki\Extension\AbuseFilter\KeywordsManager;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterTokenizer;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MessageLocalizer;
use OOUI\ButtonWidget;
use OOUI\HorizontalLayout;
@ -86,7 +86,7 @@ class AceEditBoxBuiler extends EditBoxBuilder {
$deprecatedVars = $this->keywordsManager->getDeprecatedVariables();
$builderVariables = implode( '|', array_keys( $values['vars'] ) );
$builderFunctions = implode( '|', array_keys( AbuseFilterCachingParser::FUNCTIONS ) );
$builderFunctions = implode( '|', array_keys( FilterEvaluator::FUNCTIONS ) );
// AbuseFilterTokenizer::KEYWORDS also includes constants (true, false and null),
// but Ace redefines these constants afterwards so this will not be an issue
$builderKeywords = implode( '|', AbuseFilterTokenizer::KEYWORDS );

View file

@ -11,7 +11,7 @@ use MediaWiki\Extension\AbuseFilter\ChangeTags\ChangeTagger;
use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesExecutorFactory;
use MediaWiki\Extension\AbuseFilter\Filter\ExistingFilter;
use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
// phpcs:ignore MediaWiki.Classes.UnusedUseStatement.UnusedUse
use MediaWiki\Extension\AbuseFilter\Parser\ParserStatus;
@ -70,7 +70,7 @@ class FilterRunner {
private $options;
/**
* @var AbuseFilterCachingParser
* @var FilterEvaluator
* @private Temporarily public for BC
*/
public $parser;

View file

@ -5,7 +5,7 @@ namespace MediaWiki\Extension\AbuseFilter\Parser;
/**
* A class representing a whole AST generated by AFPTreeParser, holding AFPTreeNode's. This wrapper
* could be expanded in the future. For now, it's mostly useful for typehints, and to have an
* evalTree function in the CachingParser.
* evalTree function in the evaluator.
*/
class AFPSyntaxTree {
/**

View file

@ -499,7 +499,7 @@ class AFPTreeParser {
$leftOperand = $this->doLevelUnarys();
$keyword = strtolower( $this->mCur->value );
if ( $this->mCur->type === AFPToken::TKEYWORD &&
isset( AbuseFilterCachingParser::KEYWORDS[$keyword] )
isset( FilterEvaluator::KEYWORDS[$keyword] )
) {
$position = $this->mPos;
$this->move();
@ -738,11 +738,11 @@ class AFPTreeParser {
* @return bool
*/
protected function functionIsVariadic( string $fname ): bool {
if ( !array_key_exists( $fname, AbuseFilterCachingParser::FUNC_ARG_COUNT ) ) {
if ( !array_key_exists( $fname, FilterEvaluator::FUNC_ARG_COUNT ) ) {
// @codeCoverageIgnoreStart
throw new InvalidArgumentException( "Function $fname is not valid" );
// @codeCoverageIgnoreEnd
}
return AbuseFilterCachingParser::FUNC_ARG_COUNT[$fname][1] === INF;
return FilterEvaluator::FUNC_ARG_COUNT[$fname][1] === INF;
}
}

View file

@ -24,16 +24,14 @@ use Wikimedia\Equivset\Equivset;
use Wikimedia\IPUtils;
/**
* AbuseFilterCachingParser is the AbuseFilter parser which parses
* the code into an abstract syntax tree before evaluating it, and caches that
* tree.
* This class evaluates an AST generated by the filter parser.
*
* @todo Override checkSyntax and make it only try to build the AST. That would mean faster results,
* and no need to mess with DUNDEFINED and the like. However, we must first try to reduce the
* amount of runtime-only exceptions, and try to detect them in the AFPTreeParser instead.
* Otherwise, people may be able to save a broken filter without the syntax check reporting that.
*/
class AbuseFilterCachingParser {
class FilterEvaluator {
private const CACHE_VERSION = 1;
public const FUNCTIONS = [
@ -148,11 +146,11 @@ class AbuseFilterCachingParser {
protected $allowMissingVariables = false;
/**
* @var BagOStuff Used to cache the AST (in CachingParser) and the tokens
* @var BagOStuff Used to cache the AST and the tokens
*/
protected $cache;
/**
* @var bool Whether the AST was retrieved from cache (CachingParser only)
* @var bool Whether the AST was retrieved from cache
*/
protected $fromCache = false;
/**
@ -194,7 +192,7 @@ class AbuseFilterCachingParser {
* Create a new instance
*
* @param Language $contLang Content language, used for language-dependent function
* @param BagOStuff $cache Used to cache the AST (in CachingParser) and the tokens
* @param BagOStuff $cache Used to cache the AST and the tokens
* @param LoggerInterface $logger Used for debugging
* @param KeywordsManager $keywordsManager
* @param VariablesManager $varManager

View file

@ -56,10 +56,10 @@ class ParserFactory {
/**
* @param VariableHolder|null $vars
* @return AbuseFilterCachingParser
* @return FilterEvaluator
*/
public function newParser( VariableHolder $vars = null ): AbuseFilterCachingParser {
return new AbuseFilterCachingParser(
public function newParser( VariableHolder $vars = null ): FilterEvaluator {
return new FilterEvaluator(
$this->contLang,
$this->cache,
$this->logger,

View file

@ -447,7 +447,7 @@ class SyntaxChecker {
case AFPTreeNode::FUNCTION_CALL:
$fname = $node->children[0];
$args = array_slice( $node->children, 1 );
if ( !array_key_exists( $fname, AbuseFilterCachingParser::FUNCTIONS ) ) {
if ( !array_key_exists( $fname, FilterEvaluator::FUNCTIONS ) ) {
throw new UserVisibleException(
'unknownfunction',
$node->position,
@ -643,12 +643,12 @@ class SyntaxChecker {
* @throws UserVisibleException
*/
protected function checkArgCount( array $args, string $func, int $position ): void {
if ( !array_key_exists( $func, AbuseFilterCachingParser::FUNC_ARG_COUNT ) ) {
if ( !array_key_exists( $func, FilterEvaluator::FUNC_ARG_COUNT ) ) {
// @codeCoverageIgnoreStart
throw new InvalidArgumentException( "$func is not a valid function." );
// @codeCoverageIgnoreEnd
}
list( $min, $max ) = AbuseFilterCachingParser::FUNC_ARG_COUNT[ $func ];
list( $min, $max ) = FilterEvaluator::FUNC_ARG_COUNT[ $func ];
if ( count( $args ) < $min ) {
throw new UserVisibleException(
$min === 1 ? 'noparams' : 'notenoughargs',
@ -673,7 +673,7 @@ class SyntaxChecker {
*/
protected function isReservedIdentifier( string $name ): bool {
return $this->keywordsManager->varExists( $name ) ||
array_key_exists( $name, AbuseFilterCachingParser::FUNCTIONS ) ||
array_key_exists( $name, FilterEvaluator::FUNCTIONS ) ||
// We need to check for true, false, if/then/else etc. because, even if they have a different
// AFPToken type, they may be used inside set/set_var()
in_array( $name, AbuseFilterTokenizer::KEYWORDS, true );

View file

@ -1,3 +1,3 @@
/* CachingParser's intEval used to return AFPTreeNode for this */
/* intEval used to return a tree node for this */
var := [1];
var[0] := 2;
var[0] := 2;

View file

@ -1,3 +1,3 @@
/* CachingParser's intEval used to return AFPTreeNode for this */
/* intEval used to return a tree node for this */
var := [1];
var[0] := str_replace('a','b','c');
var[0] := str_replace('a','b','c');

View file

@ -1,3 +1,3 @@
/* CachingParser's intEval used to return AFPTreeNode for this - T236870 */
/* intEval used to return a tree node for this - T236870 */
a := [];
a[] := 2;
a[] := 2;

View file

@ -2,7 +2,7 @@
namespace MediaWiki\Extension\AbuseFilter\Tests\Integration\Api;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
/**
@ -11,10 +11,10 @@ use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
trait AbuseFilterApiTestTrait {
/**
* @param AbuseFilterCachingParser|null $parser
* @param FilterEvaluator|null $parser
* @return ParserFactory
*/
protected function getParserFactory( AbuseFilterCachingParser $parser = null ): ParserFactory {
protected function getParserFactory( FilterEvaluator $parser = null ): ParserFactory {
$factory = $this->createMock( ParserFactory::class );
if ( $parser !== null ) {
$factory->expects( $this->atLeastOnce() )

View file

@ -4,7 +4,7 @@ namespace MediaWiki\Extension\AbuseFilter\Tests\Integration\Api;
use ApiTestCase;
use FormatJson;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
use MediaWiki\Extension\AbuseFilter\Parser\ParserStatus;
@ -46,7 +46,7 @@ class CheckMatchTest extends ApiTestCase {
$filter = 'sampleFilter';
$checkStatus = new ParserStatus( true, false, null, [] );
$resultStatus = new ParserStatus( $expected, false, null, [] );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->expects( $this->once() )
->method( 'checkSyntax' )->with( $filter )
->willReturn( $checkStatus );
@ -80,7 +80,7 @@ class CheckMatchTest extends ApiTestCase {
$this->setExpectedApiException( 'apierror-abusefilter-badsyntax', 'badsyntax' );
$filter = 'sampleFilter';
$status = new ParserStatus( false, false, null, [] );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->expects( $this->once() )
->method( 'checkSyntax' )->with( $filter )
->willReturn( $status );

View file

@ -3,9 +3,9 @@
namespace MediaWiki\Extension\AbuseFilter\Tests\Integration\Api;
use ApiTestCase;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleException;
use MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleWarning;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
use MediaWiki\Extension\AbuseFilter\Parser\ParserStatus;
@ -37,7 +37,7 @@ class CheckSyntaxTest extends ApiTestCase {
public function testExecute_Ok() {
$input = 'sampleFilter';
$status = new ParserStatus( true, false, null, [] );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->method( 'checkSyntax' )->with( $input )
->willReturn( $status );
$this->setService( ParserFactory::SERVICE_NAME, $this->getParserFactory( $parser ) );
@ -65,7 +65,7 @@ class CheckSyntaxTest extends ApiTestCase {
new UserVisibleWarning( 'exception-2', 8, [ 'param' ] ),
];
$status = new ParserStatus( true, false, null, $warnings );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->method( 'checkSyntax' )->with( $input )
->willReturn( $status );
$this->setService( ParserFactory::SERVICE_NAME, $this->getParserFactory( $parser ) );
@ -111,7 +111,7 @@ class CheckSyntaxTest extends ApiTestCase {
$input = 'sampleFilter';
$exception = new UserVisibleException( 'error-id', 4, [] );
$status = new ParserStatus( false, false, $exception, [] );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->method( 'checkSyntax' )->with( $input )
->willReturn( $status );
$this->setService( ParserFactory::SERVICE_NAME, $this->getParserFactory( $parser ) );

View file

@ -3,7 +3,7 @@
namespace MediaWiki\Extension\AbuseFilter\Tests\Integration\Api;
use ApiTestCase;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
use MediaWiki\Extension\AbuseFilter\Parser\ParserStatus;
@ -37,7 +37,7 @@ class EvalExpressionTest extends ApiTestCase {
$this->setExpectedApiException( 'abusefilter-tools-syntax-error' );
$expression = 'sampleExpression';
$status = new ParserStatus( false, false, null, [] );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->method( 'checkSyntax' )->with( $expression )
->willReturn( $status );
$this->setService( ParserFactory::SERVICE_NAME, $this->getParserFactory( $parser ) );
@ -55,7 +55,7 @@ class EvalExpressionTest extends ApiTestCase {
public function testExecute_Ok() {
$expression = 'sampleExpression';
$status = new ParserStatus( true, false, null, [] );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->method( 'checkSyntax' )->with( $expression )
->willReturn( $status );
$parser->expects( $this->once() )->method( 'evaluateExpression' )
@ -87,7 +87,7 @@ class EvalExpressionTest extends ApiTestCase {
public function testExecute_OkAndPrettyPrint() {
$expression = 'sampleExpression';
$status = new ParserStatus( true, false, null, [] );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->method( 'checkSyntax' )->with( $expression )
->willReturn( $status );
$parser->expects( $this->once() )->method( 'evaluateExpression' )

View file

@ -26,7 +26,7 @@ use EmptyBagOStuff;
use Generator;
use LanguageEn;
use MediaWiki\Extension\AbuseFilter\AbuseFilterServices;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Tests\Unit\Parser\ParserTest;
use MediaWiki\Extension\AbuseFilter\Variables\LazyVariableComputer;
use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager;
@ -39,7 +39,7 @@ use MediaWikiIntegrationTestCase;
* @group AbuseFilter
* @group AbuseFilterParser
*
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeParser
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeNode
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPSyntaxTree
@ -51,7 +51,7 @@ use MediaWikiIntegrationTestCase;
*/
class ParserEquivsetTest extends MediaWikiIntegrationTestCase {
/**
* @return AbuseFilterCachingParser
* @return FilterEvaluator
*/
protected function getParser() {
// We're not interested in caching or logging; tests should call respectively setCache
@ -66,7 +66,7 @@ class ParserEquivsetTest extends MediaWikiIntegrationTestCase {
$logger
);
$cachingParser = new AbuseFilterCachingParser(
$evaluator = new FilterEvaluator(
$contLang,
$cache,
$logger,
@ -74,8 +74,8 @@ class ParserEquivsetTest extends MediaWikiIntegrationTestCase {
$varManager,
1000
);
$cachingParser->toggleConditionLimit( false );
return $cachingParser;
$evaluator->toggleConditionLimit( false );
return $evaluator;
}
/**

View file

@ -8,10 +8,10 @@ use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager;
use MediaWiki\Extension\AbuseFilter\ChangeTags\ChangeTagValidator;
use MediaWiki\Extension\AbuseFilter\Filter\AbstractFilter;
use MediaWiki\Extension\AbuseFilter\FilterValidator;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\Exception\ExceptionBase;
use MediaWiki\Extension\AbuseFilter\Parser\Exception\InternalException;
use MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleException;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
use MediaWiki\Extension\AbuseFilter\Parser\ParserStatus;
use MediaWikiUnitTestCase;
@ -29,19 +29,19 @@ class FilterValidatorTest extends MediaWikiUnitTestCase {
/**
* @param AbuseFilterPermissionManager|null $permissionManager
* @param AbuseFilterCachingParser|null $parser
* @param FilterEvaluator|null $parser
* @param array $restrictions
* @param array $validFilterGroups
* @return FilterValidator
*/
private function getFilterValidator(
AbuseFilterPermissionManager $permissionManager = null,
AbuseFilterCachingParser $parser = null,
FilterEvaluator $parser = null,
array $restrictions = [],
array $validFilterGroups = [ 'default' ]
): FilterValidator {
if ( !$parser ) {
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$parser->method( 'checkSyntax' )->willReturn(
new ParserStatus( true, true, null, [] )
);
@ -101,7 +101,7 @@ class FilterValidatorTest extends MediaWikiUnitTestCase {
* @dataProvider provideSyntax
*/
public function testCheckValidSyntax( bool $valid, ?ExceptionBase $excep, ?string $expected, ?array $expParams ) {
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$syntaxStatus = new ParserStatus( $valid, true, $excep, [] );
$parser->method( 'checkSyntax' )->willReturn( $syntaxStatus );
$validator = $this->getFilterValidator( null, $parser );
@ -363,7 +363,7 @@ class FilterValidatorTest extends MediaWikiUnitTestCase {
* @param AbstractFilter $newFilter
* @param string|null $expected
* @param AbuseFilterPermissionManager|null $permissionManager
* @param AbuseFilterCachingParser|null $parser
* @param FilterEvaluator|null $parser
* @param array $restrictions
* @covers \MediaWiki\Extension\AbuseFilter\FilterValidator::checkAll
* @dataProvider provideCheckAll
@ -372,7 +372,7 @@ class FilterValidatorTest extends MediaWikiUnitTestCase {
AbstractFilter $newFilter,
?string $expected,
AbuseFilterPermissionManager $permissionManager = null,
AbuseFilterCachingParser $parser = null,
FilterEvaluator $parser = null,
array $restrictions = []
) {
$validator = $this->getFilterValidator( $permissionManager, $parser, $restrictions );
@ -389,7 +389,7 @@ class FilterValidatorTest extends MediaWikiUnitTestCase {
$noopFilter->method( 'getName' )->willReturn( 'Foo' );
$noopFilter->method( 'isEnabled' )->willReturn( true );
$parser = $this->createMock( AbuseFilterCachingParser::class );
$parser = $this->createMock( FilterEvaluator::class );
$syntaxStatus = new ParserStatus( false, true, $this->createMock( UserVisibleException::class ), [] );
$parser->method( 'checkSyntax' )->willReturn( $syntaxStatus );
yield 'invalid syntax' => [ $noopFilter, 'abusefilter-edit-badsyntax', null, $parser ];

View file

@ -36,7 +36,7 @@ class AFPDataTest extends ParserTestCase {
* @param string $expr The expression to test
* @param string $caller The function where the exception is thrown
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPData::mulRel
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeParser
*
* @dataProvider divideByZero

View file

@ -5,7 +5,7 @@ namespace MediaWiki\Extension\AbuseFilter\Tests\Unit\Parser;
use BagOStuff;
use Language;
use MediaWiki\Extension\AbuseFilter\KeywordsManager;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Parser\ParserFactory;
use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager;
use MediaWikiUnitTestCase;
@ -32,6 +32,6 @@ class ParserFactoryTest extends MediaWikiUnitTestCase {
$this->createMock( VariablesManager::class ),
1000
);
$this->assertInstanceOf( AbuseFilterCachingParser::class, $factory->newParser() );
$this->assertInstanceOf( FilterEvaluator::class, $factory->newParser() );
}
}

View file

@ -28,9 +28,9 @@ use Generator;
use IBufferingStatsdDataFactory;
use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
use MediaWiki\Extension\AbuseFilter\KeywordsManager;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterTokenizer;
use MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleException;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager;
use Psr\Log\NullLogger;
@ -42,7 +42,7 @@ use Wikimedia\TestingAccessWrapper;
* @group AbuseFilter
* @group AbuseFilterParser
*
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeParser
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeNode
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPSyntaxTree
@ -779,7 +779,7 @@ class ParserTest extends ParserTestCase {
* @param string $new The new name of the variable
* @dataProvider provideDeprecatedVars
*
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::getVarValue
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::getVarValue
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeParser::checkLogDeprecatedVar
*/
public function testDeprecatedVars( $old, $new ) {
@ -1012,7 +1012,7 @@ class ParserTest extends ParserTestCase {
}
/**
* Test that empty operands raise an exception in the CachingParser
* Test that empty operands raise an exception
*
* @param string $code
* @dataProvider provideEmptyOperands
@ -1144,19 +1144,18 @@ class ParserTest extends ParserTestCase {
}
/**
* Ensure that every function in AbuseFilterCachingParser::FUNCTIONS is also listed in
* AbuseFilterCachingParser::FUNC_ARG_COUNT
* Ensure that every function in FUNCTIONS is also listed in FUNC_ARG_COUNT
*/
public function testAllFunctionsHaveArgCount() {
$funcs = array_keys( AbuseFilterCachingParser::FUNCTIONS );
$funcs = array_keys( FilterEvaluator::FUNCTIONS );
sort( $funcs );
$argsCount = array_keys( AbuseFilterCachingParser::FUNC_ARG_COUNT );
$argsCount = array_keys( FilterEvaluator::FUNC_ARG_COUNT );
sort( $argsCount );
$this->assertSame( $funcs, $argsCount );
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::__construct
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::__construct
*/
public function testConstructorInitsVars() {
$lang = $this->getLanguageMock();
@ -1166,12 +1165,12 @@ class ParserTest extends ParserTestCase {
$varManager = $this->createMock( VariablesManager::class );
$vars = new VariableHolder();
$parser = new AbuseFilterCachingParser( $lang, $cache, $logger, $keywordsManager, $varManager, 1000, $vars );
$parser = new FilterEvaluator( $lang, $cache, $logger, $keywordsManager, $varManager, 1000, $vars );
$this->assertSame( $vars, $parser->mVariables, 'Variables should be initialized' );
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::setFilter
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::setFilter
*/
public function testSetFilter() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );
@ -1182,7 +1181,7 @@ class ParserTest extends ParserTestCase {
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::setCache
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::setCache
*/
public function testSetCache() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );
@ -1192,7 +1191,7 @@ class ParserTest extends ParserTestCase {
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::setLogger
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::setLogger
*/
public function testSetLogger() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );
@ -1202,7 +1201,7 @@ class ParserTest extends ParserTestCase {
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::setStatsd
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::setStatsd
*/
public function testSetStatsd() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );
@ -1212,8 +1211,8 @@ class ParserTest extends ParserTestCase {
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::getCondCount
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::resetCondCount
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::getCondCount
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::resetCondCount
*/
public function testCondCountMethods() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );
@ -1226,7 +1225,7 @@ class ParserTest extends ParserTestCase {
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::toggleConditionLimit
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::toggleConditionLimit
*/
public function testToggleConditionLimit() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );
@ -1239,7 +1238,7 @@ class ParserTest extends ParserTestCase {
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::clearFuncCache
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::clearFuncCache
*/
public function testClearFuncCache() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );
@ -1251,7 +1250,7 @@ class ParserTest extends ParserTestCase {
}
/**
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser::setVariables
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator::setVariables
*/
public function testSetVariables() {
$parser = TestingAccessWrapper::newFromObject( $this->getParser() );

View file

@ -27,8 +27,8 @@ use Language;
use LanguageEn;
use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
use MediaWiki\Extension\AbuseFilter\KeywordsManager;
use MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser;
use MediaWiki\Extension\AbuseFilter\Parser\Exception\UserVisibleException;
use MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator;
use MediaWiki\Extension\AbuseFilter\Variables\LazyVariableComputer;
use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager;
use MediaWikiUnitTestCase;
@ -39,7 +39,7 @@ use PHPUnit\Framework\MockObject\MockObject;
*/
abstract class ParserTestCase extends MediaWikiUnitTestCase {
/**
* @return AbuseFilterCachingParser
* @return FilterEvaluator
*/
protected function getParser() {
// We're not interested in caching or logging; tests should call respectively setCache
@ -54,7 +54,7 @@ abstract class ParserTestCase extends MediaWikiUnitTestCase {
$logger
);
$cachingParser = new AbuseFilterCachingParser(
$evaluator = new FilterEvaluator(
$contLang,
$cache,
$logger,
@ -62,8 +62,8 @@ abstract class ParserTestCase extends MediaWikiUnitTestCase {
$varManager,
1000
);
$cachingParser->toggleConditionLimit( false );
return $cachingParser;
$evaluator->toggleConditionLimit( false );
return $evaluator;
}
/**
@ -101,8 +101,6 @@ abstract class ParserTestCase extends MediaWikiUnitTestCase {
* @param string $excep Identifier of the exception (e.g. 'unexpectedtoken')
* @param string $expr The expression to test
* @param string $caller The function where the exception is thrown, if available
* The method may be different in Parser and CachingParser, but this parameter is
* just used for debugging purposes.
*/
protected function exceptionTest( $excep, $expr, $caller = '' ) {
$this->exceptionTestInternal( $excep, $expr, $caller, false );

View file

@ -37,7 +37,7 @@ use Psr\Log\NullLogger;
* @group AbuseFilterParser
*
* @covers \MediaWiki\Extension\AbuseFilter\Parser\SyntaxChecker
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AbuseFilterCachingParser
* @covers \MediaWiki\Extension\AbuseFilter\Parser\FilterEvaluator
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeParser
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPTreeNode
* @covers \MediaWiki\Extension\AbuseFilter\Parser\AFPSyntaxTree