mediawiki-extensions-AbuseF.../tests/phpunit/AbuseFilterParserTestCase.php
Daimona Eaytoy 430ba818d0 Add test for multiple conditions inside conditionals
The regression itself was fixed in
I980aec3481a52ecc35f1811a366014a5581a7cdb, so this patch only adds a
test for it.
Also remove a comment about CachingParser failures: we don't want to
encourage people to remove it from tests anymore.

Bug: T152281
Change-Id: I3ad49050ea49bf45d3226878e091da3c8dbefdb1
2019-08-12 18:18:05 +02:00

74 lines
2.2 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*
* @license GPL-2.0-or-later
*/
/**
* Helper for parser-related tests
*/
abstract class AbuseFilterParserTestCase extends MediaWikiTestCase {
/**
* @return AbuseFilterParser[]
*/
public static function getParsers() {
static $parsers = null;
if ( !$parsers ) {
$parsers = [
new AbuseFilterParser(),
new AbuseFilterCachingParser()
];
} 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;
}
/**
* Base method for testing exceptions
*
* @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 ) {
foreach ( self::getParsers() as $parser ) {
$pname = get_class( $parser );
try {
$parser->parse( $expr );
} catch ( AFPUserVisibleException $e ) {
$this->assertEquals(
$excep,
$e->mExceptionID,
"Exception $excep not thrown in $caller. Parser: $pname."
);
continue;
}
$this->fail( "Exception $excep not thrown in $caller. Parser: $pname." );
}
}
}