toggleConditionLimit( false ); $cachingParser = new AbuseFilterCachingParser( $contLang, $cache, $logger, $keywordsManager ); $cachingParser->toggleConditionLimit( false ); $parsers = [ $parser, $cachingParser ]; } else { // Reset so that already executed tests don't influence new ones $parsers[0]->resetState(); $parsers[0]->clearFuncCache(); $parsers[1]->resetState(); $parsers[1]->clearFuncCache(); } return $parsers; } /** * @param string $rule The rule to parse * @dataProvider provideGenericTests */ public function testGeneric( $rule ) { if ( !class_exists( 'Wikimedia\Equivset\Equivset' ) ) { $this->markTestSkipped( 'Equivset is not installed' ); } foreach ( $this->getParsers() as $parser ) { $this->assertTrue( $parser->parse( $rule ), 'Parser used: ' . get_class( $parser ) ); } } /** * @return Generator|array */ public function provideGenericTests() { $testPath = __DIR__ . "/../parserTestsEquivset"; $testFiles = glob( $testPath . "/*.t" ); foreach ( $testFiles as $testFile ) { $testName = basename( substr( $testFile, 0, -2 ) ); $rule = trim( file_get_contents( $testFile ) ); yield $testName => [ $rule ]; } } /** * @param string $func * @see AbuseFilterParserTest::testVariadicFuncsArbitraryArgsAllowed() * @dataProvider variadicFuncs */ public function testVariadicFuncsArbitraryArgsAllowed( $func ) { $argsList = str_repeat( ', "arg"', 50 ); $code = "$func( 'arg' $argsList )"; foreach ( $this->getParsers() as $parser ) { $pname = get_class( $parser ); try { $parser->parse( $code ); $this->assertTrue( true ); } catch ( AFPException $e ) { $this->fail( "Got exception with parser $pname.\n$e" ); } } } /** * @return array */ public function variadicFuncs() { return [ [ 'ccnorm_contains_any' ], [ 'ccnorm_contains_all' ], ]; } }