Hoo man has uploaded a new change for review. https://gerrit.wikimedia.org/r/71571
Change subject: Allow running the AbuseFilter parser tests via phpunit ...................................................................... Allow running the AbuseFilter parser tests via phpunit I've also added myself to the credits file as I'm the only maintainer of this extension for a while now. Change-Id: Id998172ea2abd70b8243de9db1a96cc2cfa47a64 --- M AbuseFilter.hooks.php M AbuseFilter.php R tests/legacyParserTest.php R tests/parserTests/arith.r R tests/parserTests/arith.t R tests/parserTests/arrays.r R tests/parserTests/arrays.t R tests/parserTests/bug25373.r R tests/parserTests/bug25373.t R tests/parserTests/cast.r R tests/parserTests/cast.t R tests/parserTests/ccnorm.r R tests/parserTests/ccnorm.t R tests/parserTests/comment.r R tests/parserTests/comment.t R tests/parserTests/count.r R tests/parserTests/count.t R tests/parserTests/eq.r R tests/parserTests/eq.t R tests/parserTests/float.r R tests/parserTests/float.t R tests/parserTests/ifthen.r R tests/parserTests/ifthen.t R tests/parserTests/in.r R tests/parserTests/in.t R tests/parserTests/lcase.r R tests/parserTests/lcase.t R tests/parserTests/length.r R tests/parserTests/length.t R tests/parserTests/like.r R tests/parserTests/like.t R tests/parserTests/norm.r R tests/parserTests/norm.t R tests/parserTests/numbers.r R tests/parserTests/numbers.t R tests/parserTests/ord.r R tests/parserTests/ord.t R tests/parserTests/prec.r R tests/parserTests/prec.t R tests/parserTests/regex.r R tests/parserTests/regex.t R tests/parserTests/rmdoubles.r R tests/parserTests/rmdoubles.t R tests/parserTests/rmspecials.r R tests/parserTests/rmspecials.t R tests/parserTests/specialratio.r R tests/parserTests/specialratio.t R tests/parserTests/string.r R tests/parserTests/string.t R tests/parserTests/tern.r R tests/parserTests/tern.t R tests/parserTests/ucase.r R tests/parserTests/ucase.t R tests/parserTests/utf8.r R tests/parserTests/utf8.t R tests/parserTests/vars.r R tests/parserTests/vars.t R tests/parserTests/whitespace.r R tests/parserTests/whitespace1.r R tests/parserTests/whitespace1.t R tests/parserTests/wptest1.r R tests/parserTests/wptest1.t R tests/parserTests/wptest2.r R tests/parserTests/wptest2.t R tests/parserTests/wptest3.r R tests/parserTests/wptest3.t A tests/phpunit/parserTest.php 67 files changed, 97 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AbuseFilter refs/changes/71/71571/1 diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php index 96b421c..31e7871 100644 --- a/AbuseFilter.hooks.php +++ b/AbuseFilter.hooks.php @@ -560,4 +560,23 @@ } return true; } + + /** + * Hook to add PHPUnit test cases. + * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList + * + * @param array $files + * + * @return bool + */ + public static function onUnitTestsList( array &$files ) { + $testDir = __DIR__ . '/tests/phpunit'; + + $files = array_merge( + $files, + glob( $testDir . '/*Test.php' ) + ); + + return true; + } } diff --git a/AbuseFilter.php b/AbuseFilter.php index 67ceddc..aa79051 100644 --- a/AbuseFilter.php +++ b/AbuseFilter.php @@ -18,7 +18,7 @@ $wgExtensionCredits['antispam'][] = array( 'path' => __FILE__, 'name' => 'Abuse Filter', - 'author' => array( 'Andrew Garrett', 'River Tarnell', 'Victor Vasiliev' ), + 'author' => array( 'Andrew Garrett', 'River Tarnell', 'Victor Vasiliev', 'Marius Hoch' ), 'descriptionmsg' => 'abusefilter-desc', 'url' => 'https://www.mediawiki.org/wiki/Extension:AbuseFilter', ); @@ -87,6 +87,7 @@ $wgHooks['UploadVerifyFile'][] = 'AbuseFilterHooks::onUploadVerifyFile'; $wgHooks['MakeGlobalVariablesScript'][] = 'AbuseFilterHooks::onMakeGlobalVariablesScript'; $wgHooks['ArticleSaveComplete'][] = 'AbuseFilterHooks::onArticleSaveComplete'; +$wgHooks['UnitTestsList'][] = 'AbuseFilterHooks::onUnitTestsList'; $wgAvailableRights[] = 'abusefilter-modify'; $wgAvailableRights[] = 'abusefilter-log-detail'; diff --git a/phpTest.php b/tests/legacyParserTest.php similarity index 86% rename from phpTest.php rename to tests/legacyParserTest.php index 97ae897..36efd08 100644 --- a/phpTest.php +++ b/tests/legacyParserTest.php @@ -5,11 +5,11 @@ require_once ( getenv( 'MW_INSTALL_PATH' ) !== false ? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc" - : __DIR__ . '/../../maintenance/commandLine.inc' ); + : __DIR__ . '/../../../maintenance/commandLine.inc' ); $tester = new AbuseFilterParser; -$test_path = __DIR__ . "/tests"; +$test_path = __DIR__ . "/parserTests"; $tests = glob( $test_path . "/*.t" ); $check = 0; @@ -19,7 +19,7 @@ $result = substr( $test, 0, - 2 ) . ".r"; $rule = trim( file_get_contents( $test ) ); - $output = ( $cont = trim( file_get_contents( $result ) ) ) == 'MATCH'; + $output = trim( file_get_contents( $result ) ) == 'MATCH'; $testname = basename( $test ); diff --git a/tests/arith.r b/tests/parserTests/arith.r similarity index 100% rename from tests/arith.r rename to tests/parserTests/arith.r diff --git a/tests/arith.t b/tests/parserTests/arith.t similarity index 100% rename from tests/arith.t rename to tests/parserTests/arith.t diff --git a/tests/arrays.r b/tests/parserTests/arrays.r similarity index 100% rename from tests/arrays.r rename to tests/parserTests/arrays.r diff --git a/tests/arrays.t b/tests/parserTests/arrays.t similarity index 100% rename from tests/arrays.t rename to tests/parserTests/arrays.t diff --git a/tests/bug25373.r b/tests/parserTests/bug25373.r similarity index 100% rename from tests/bug25373.r rename to tests/parserTests/bug25373.r diff --git a/tests/bug25373.t b/tests/parserTests/bug25373.t similarity index 100% rename from tests/bug25373.t rename to tests/parserTests/bug25373.t diff --git a/tests/cast.r b/tests/parserTests/cast.r similarity index 100% rename from tests/cast.r rename to tests/parserTests/cast.r diff --git a/tests/cast.t b/tests/parserTests/cast.t similarity index 100% rename from tests/cast.t rename to tests/parserTests/cast.t diff --git a/tests/ccnorm.r b/tests/parserTests/ccnorm.r similarity index 100% rename from tests/ccnorm.r rename to tests/parserTests/ccnorm.r diff --git a/tests/ccnorm.t b/tests/parserTests/ccnorm.t similarity index 100% rename from tests/ccnorm.t rename to tests/parserTests/ccnorm.t diff --git a/tests/comment.r b/tests/parserTests/comment.r similarity index 100% rename from tests/comment.r rename to tests/parserTests/comment.r diff --git a/tests/comment.t b/tests/parserTests/comment.t similarity index 100% rename from tests/comment.t rename to tests/parserTests/comment.t diff --git a/tests/count.r b/tests/parserTests/count.r similarity index 100% rename from tests/count.r rename to tests/parserTests/count.r diff --git a/tests/count.t b/tests/parserTests/count.t similarity index 100% rename from tests/count.t rename to tests/parserTests/count.t diff --git a/tests/eq.r b/tests/parserTests/eq.r similarity index 100% rename from tests/eq.r rename to tests/parserTests/eq.r diff --git a/tests/eq.t b/tests/parserTests/eq.t similarity index 100% rename from tests/eq.t rename to tests/parserTests/eq.t diff --git a/tests/float.r b/tests/parserTests/float.r similarity index 100% rename from tests/float.r rename to tests/parserTests/float.r diff --git a/tests/float.t b/tests/parserTests/float.t similarity index 100% rename from tests/float.t rename to tests/parserTests/float.t diff --git a/tests/ifthen.r b/tests/parserTests/ifthen.r similarity index 100% rename from tests/ifthen.r rename to tests/parserTests/ifthen.r diff --git a/tests/ifthen.t b/tests/parserTests/ifthen.t similarity index 100% rename from tests/ifthen.t rename to tests/parserTests/ifthen.t diff --git a/tests/in.r b/tests/parserTests/in.r similarity index 100% rename from tests/in.r rename to tests/parserTests/in.r diff --git a/tests/in.t b/tests/parserTests/in.t similarity index 100% rename from tests/in.t rename to tests/parserTests/in.t diff --git a/tests/lcase.r b/tests/parserTests/lcase.r similarity index 100% rename from tests/lcase.r rename to tests/parserTests/lcase.r diff --git a/tests/lcase.t b/tests/parserTests/lcase.t similarity index 100% rename from tests/lcase.t rename to tests/parserTests/lcase.t diff --git a/tests/length.r b/tests/parserTests/length.r similarity index 100% rename from tests/length.r rename to tests/parserTests/length.r diff --git a/tests/length.t b/tests/parserTests/length.t similarity index 100% rename from tests/length.t rename to tests/parserTests/length.t diff --git a/tests/like.r b/tests/parserTests/like.r similarity index 100% rename from tests/like.r rename to tests/parserTests/like.r diff --git a/tests/like.t b/tests/parserTests/like.t similarity index 100% rename from tests/like.t rename to tests/parserTests/like.t diff --git a/tests/norm.r b/tests/parserTests/norm.r similarity index 100% rename from tests/norm.r rename to tests/parserTests/norm.r diff --git a/tests/norm.t b/tests/parserTests/norm.t similarity index 100% rename from tests/norm.t rename to tests/parserTests/norm.t diff --git a/tests/numbers.r b/tests/parserTests/numbers.r similarity index 100% rename from tests/numbers.r rename to tests/parserTests/numbers.r diff --git a/tests/numbers.t b/tests/parserTests/numbers.t similarity index 100% rename from tests/numbers.t rename to tests/parserTests/numbers.t diff --git a/tests/ord.r b/tests/parserTests/ord.r similarity index 100% rename from tests/ord.r rename to tests/parserTests/ord.r diff --git a/tests/ord.t b/tests/parserTests/ord.t similarity index 100% rename from tests/ord.t rename to tests/parserTests/ord.t diff --git a/tests/prec.r b/tests/parserTests/prec.r similarity index 100% rename from tests/prec.r rename to tests/parserTests/prec.r diff --git a/tests/prec.t b/tests/parserTests/prec.t similarity index 100% rename from tests/prec.t rename to tests/parserTests/prec.t diff --git a/tests/regex.r b/tests/parserTests/regex.r similarity index 100% rename from tests/regex.r rename to tests/parserTests/regex.r diff --git a/tests/regex.t b/tests/parserTests/regex.t similarity index 100% rename from tests/regex.t rename to tests/parserTests/regex.t diff --git a/tests/rmdoubles.r b/tests/parserTests/rmdoubles.r similarity index 100% rename from tests/rmdoubles.r rename to tests/parserTests/rmdoubles.r diff --git a/tests/rmdoubles.t b/tests/parserTests/rmdoubles.t similarity index 100% rename from tests/rmdoubles.t rename to tests/parserTests/rmdoubles.t diff --git a/tests/rmspecials.r b/tests/parserTests/rmspecials.r similarity index 100% rename from tests/rmspecials.r rename to tests/parserTests/rmspecials.r diff --git a/tests/rmspecials.t b/tests/parserTests/rmspecials.t similarity index 100% rename from tests/rmspecials.t rename to tests/parserTests/rmspecials.t diff --git a/tests/specialratio.r b/tests/parserTests/specialratio.r similarity index 100% rename from tests/specialratio.r rename to tests/parserTests/specialratio.r diff --git a/tests/specialratio.t b/tests/parserTests/specialratio.t similarity index 100% rename from tests/specialratio.t rename to tests/parserTests/specialratio.t diff --git a/tests/string.r b/tests/parserTests/string.r similarity index 100% rename from tests/string.r rename to tests/parserTests/string.r diff --git a/tests/string.t b/tests/parserTests/string.t similarity index 100% rename from tests/string.t rename to tests/parserTests/string.t diff --git a/tests/tern.r b/tests/parserTests/tern.r similarity index 100% rename from tests/tern.r rename to tests/parserTests/tern.r diff --git a/tests/tern.t b/tests/parserTests/tern.t similarity index 100% rename from tests/tern.t rename to tests/parserTests/tern.t diff --git a/tests/ucase.r b/tests/parserTests/ucase.r similarity index 100% rename from tests/ucase.r rename to tests/parserTests/ucase.r diff --git a/tests/ucase.t b/tests/parserTests/ucase.t similarity index 100% rename from tests/ucase.t rename to tests/parserTests/ucase.t diff --git a/tests/utf8.r b/tests/parserTests/utf8.r similarity index 100% rename from tests/utf8.r rename to tests/parserTests/utf8.r diff --git a/tests/utf8.t b/tests/parserTests/utf8.t similarity index 100% rename from tests/utf8.t rename to tests/parserTests/utf8.t diff --git a/tests/vars.r b/tests/parserTests/vars.r similarity index 100% rename from tests/vars.r rename to tests/parserTests/vars.r diff --git a/tests/vars.t b/tests/parserTests/vars.t similarity index 100% rename from tests/vars.t rename to tests/parserTests/vars.t diff --git a/tests/whitespace.r b/tests/parserTests/whitespace.r similarity index 100% rename from tests/whitespace.r rename to tests/parserTests/whitespace.r diff --git a/tests/whitespace1.r b/tests/parserTests/whitespace1.r similarity index 100% rename from tests/whitespace1.r rename to tests/parserTests/whitespace1.r diff --git a/tests/whitespace1.t b/tests/parserTests/whitespace1.t similarity index 100% rename from tests/whitespace1.t rename to tests/parserTests/whitespace1.t diff --git a/tests/wptest1.r b/tests/parserTests/wptest1.r similarity index 100% rename from tests/wptest1.r rename to tests/parserTests/wptest1.r diff --git a/tests/wptest1.t b/tests/parserTests/wptest1.t similarity index 100% rename from tests/wptest1.t rename to tests/parserTests/wptest1.t diff --git a/tests/wptest2.r b/tests/parserTests/wptest2.r similarity index 100% rename from tests/wptest2.r rename to tests/parserTests/wptest2.r diff --git a/tests/wptest2.t b/tests/parserTests/wptest2.t similarity index 100% rename from tests/wptest2.t rename to tests/parserTests/wptest2.t diff --git a/tests/wptest3.r b/tests/parserTests/wptest3.r similarity index 100% rename from tests/wptest3.r rename to tests/parserTests/wptest3.r diff --git a/tests/wptest3.t b/tests/parserTests/wptest3.t similarity index 100% rename from tests/wptest3.t rename to tests/parserTests/wptest3.t diff --git a/tests/phpunit/parserTest.php b/tests/phpunit/parserTest.php new file mode 100644 index 0000000..8d1f6a2 --- /dev/null +++ b/tests/phpunit/parserTest.php @@ -0,0 +1,73 @@ +<?php +/** + * Tests for the AbuseFilter parser + * + * 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 + * + * @group Test + * @group AbuseFilter + * + * @licence GNU GPL v2+ + * @author Marius Hoch < h...@online.de > + */ +class AbuseFilterParserTest extends \MediaWikiTestCase { + /** + * @return AbuseFilterParser + */ + static function getParser() { + static $parser = null; + if ( !$parser ) { + $parser = new AbuseFilterParser(); + } + return $parser; + } + + /** + * @dataProvider readTests + */ + public function testParser( $testName, $rule, $expected ) { + $parser = self::getParser(); + $actual = $parser->parse( $rule ); + $this->assertEquals( $expected, $actual, 'Running parser test ' . $testName ); + } + + /** + * @return array + */ + public function readTests() { + $tests = array(); + $testPath = __DIR__ . "/../parserTests"; + $testFiles = glob( $testPath . "/*.t" ); + + foreach ( $testFiles as $testFile ) { + $testName = substr( $testFile, 0, - 2 ); + + $resultFile = $testName . '.r'; + $rule = trim( file_get_contents( $testFile ) ); + $result = trim( file_get_contents( $resultFile ) ) == 'MATCH'; + + $tests[] = array( + basename( $testName ), + $rule, + $result + ); + } + + return $tests; + } +} -- To view, visit https://gerrit.wikimedia.org/r/71571 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id998172ea2abd70b8243de9db1a96cc2cfa47a64 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/AbuseFilter Gerrit-Branch: master Gerrit-Owner: Hoo man <h...@online.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits