Dmaza has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/371204 )
Change subject: Add normalizeString method ...................................................................... Add normalizeString method To make use of AntiSpoof normalization there was not a method that would take a string and return a normalized version of it. Grouping that functionality here will allow for later improvements on making it more strict. Bug: T172766 Change-Id: I731733671b650b6bb2f480c41c4f6f2d2f5c62e8 --- M AntiSpoof_body.php M tests/phpunit/AntiSpoofTest.php 2 files changed, 25 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AntiSpoof refs/changes/04/371204/1 diff --git a/AntiSpoof_body.php b/AntiSpoof_body.php index c5a7a5f..181babb 100644 --- a/AntiSpoof_body.php +++ b/AntiSpoof_body.php @@ -434,4 +434,12 @@ // And return the canonical version of the name return [ "OK", $testName ]; } + + /** + * @param $str + * @return string + */ + public static function normalizeString( $str ) { + return self::listToString( self::equivString( self::stringToList( $str ) ) ); + } } diff --git a/tests/phpunit/AntiSpoofTest.php b/tests/phpunit/AntiSpoofTest.php index 73f2dd7..b1de8ad 100644 --- a/tests/phpunit/AntiSpoofTest.php +++ b/tests/phpunit/AntiSpoofTest.php @@ -3,7 +3,7 @@ public function providePositives() { return [ - /** Format: username -> spoofing attempt */ + /** Format: string -> spoofing attempt */ [ 'Laura Fiorucci', 'Låura Fiorucci' ], [ 'Lucien leGrey', 'Lucien le6rey' ], [ 'Poco a poco', 'Poco a ƿoco' ], @@ -18,13 +18,26 @@ * @covers AntiSpoof::checkUnicodeString * @dataProvider providePositives */ - public function testCheckUnicodeString( $userName, $spooferName ) { - $a = AntiSpoof::checkUnicodeString( $userName ); - $b = AntiSpoof::checkUnicodeString( $spooferName ); + public function testCheckUnicodeString( $strA, $strB ) { + $a = AntiSpoof::checkUnicodeString( $strA ); + $b = AntiSpoof::checkUnicodeString( $strB ); $this->assertEquals( 'OK', $a[0] ); $this->assertEquals( 'OK', $b[0] ); $this->assertEquals( $a[1], $b[1] ); } + + /** + * String normalization check + * + * @covers AntiSpoof:normalizeString: + * @dataProvider providePositives + */ + public function testNormalizeString( $strA, $strB ) { + $a = AntiSpoof::normalizeString( $strA ); + $b = AntiSpoof::normalizeString( $strB ); + + $this->assertEquals( $a, $b ); + } } -- To view, visit https://gerrit.wikimedia.org/r/371204 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I731733671b650b6bb2f480c41c4f6f2d2f5c62e8 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/AntiSpoof Gerrit-Branch: master Gerrit-Owner: Dmaza <dm...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits