<?php
-class StringUtilsTest extends PHPUnit_Framework_TestCase {
+class StringUtilsTest extends PHPUnit\Framework\TestCase {
- /**
- * This tests StringUtils::isUtf8 whenever we have the mbstring extension
- * loaded.
- *
- * @covers StringUtils::isUtf8
- * @dataProvider provideStringsForIsUtf8Check
- */
- public function testIsUtf8WithMbstring( $expected, $string ) {
- if ( !function_exists( 'mb_check_encoding' ) ) {
- $this->markTestSkipped( 'Test requires the mbstring PHP extension' );
- }
- $this->assertEquals( $expected,
- StringUtils::isUtf8( $string ),
- 'Testing string "' . $this->escaped( $string ) . '" with mb_check_encoding'
- );
- }
+ use MediaWikiCoversValidator;
/**
- * This tests StringUtils::isUtf8 making sure we use the pure PHP
- * implementation used as a fallback when mb_check_encoding() is
- * not available.
- *
* @covers StringUtils::isUtf8
* @dataProvider provideStringsForIsUtf8Check
*/
- public function testIsUtf8WithPhpFallbackImplementation( $expected, $string ) {
- $this->assertEquals( $expected,
- StringUtils::isUtf8( $string, /** disable mbstring: */true ),
- 'Testing string "' . $this->escaped( $string ) . '" with pure PHP implementation'
- );
+ public function testIsUtf8( $expected, $string ) {
+ $this->assertEquals( $expected, StringUtils::isUtf8( $string ),
+ 'Testing string "' . $this->escaped( $string ) . '"' );
}
/**
'noncharacters 2' => [ $PASS, "\xef\xbf\xbf" ],
];
}
+
+ /**
+ * @param strin $input
+ * @param bool $expected
+ * @dataProvider provideRegexps
+ * @covers StringUtils::isValidRegex
+ */
+ public function testIsValidRegex( $input, $expected ) {
+ $this->assertSame( $expected, StringUtils::isValidRegex( $input ) );
+ }
+
+ /**
+ * Data provider for testValidRegex
+ */
+ public static function provideRegexps() {
+ return [
+ [ 'foo', false ],
+ [ '/foo/', true ],
+ [ '//', true ],
+ [ '/(foo/', false ],
+ [ '!(f[o]{2})!', true ],
+ [ '/foo\/', false ]
+ ];
+ }
}