From ff18d57c636047c9b56cee26772f7a2f0edd4e21 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 8 Jun 2018 23:07:38 -0700 Subject: [PATCH] Rewrite IEUrlExtensionTest using a data provider Change-Id: I67568f997d682b88ad99676a57b85395b1b20f85 --- .../includes/libs/IEUrlExtensionTest.php | 230 +++--------------- 1 file changed, 33 insertions(+), 197 deletions(-) diff --git a/tests/phpunit/includes/libs/IEUrlExtensionTest.php b/tests/phpunit/includes/libs/IEUrlExtensionTest.php index 03c7b0c05c..9ec660e2c5 100644 --- a/tests/phpunit/includes/libs/IEUrlExtensionTest.php +++ b/tests/phpunit/includes/libs/IEUrlExtensionTest.php @@ -2,208 +2,44 @@ /** * Tests for IEUrlExtension::findIE6Extension - * @todo tests below for findIE6Extension should be split into... - * ...a dataprovider and test method. */ class IEUrlExtensionTest extends PHPUnit\Framework\TestCase { use MediaWikiCoversValidator; - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testSimple() { - $this->assertEquals( - 'y', - IEUrlExtension::findIE6Extension( 'x.y' ), - 'Simple extension' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testSimpleNoExt() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( 'x' ), - 'No extension' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testEmpty() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( '' ), - 'Empty string' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testQuestionMark() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( '?' ), - 'Question mark only' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testExtQuestionMark() { - $this->assertEquals( - 'x', - IEUrlExtension::findIE6Extension( '.x?' ), - 'Extension then question mark' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testQuestionMarkExt() { - $this->assertEquals( - 'x', - IEUrlExtension::findIE6Extension( '?.x' ), - 'Question mark then extension' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testInvalidChar() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( '.x*' ), - 'Extension with invalid character' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testInvalidCharThenExtension() { - $this->assertEquals( - 'x', - IEUrlExtension::findIE6Extension( '*.x' ), - 'Invalid character followed by an extension' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testMultipleQuestionMarks() { - $this->assertEquals( - 'c', - IEUrlExtension::findIE6Extension( 'a?b?.c?.d?e?f' ), - 'Multiple question marks' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testExeException() { - $this->assertEquals( - 'd', - IEUrlExtension::findIE6Extension( 'a?b?.exe?.d?.e' ), - '.exe exception' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testExeException2() { - $this->assertEquals( - 'exe', - IEUrlExtension::findIE6Extension( 'a?b?.exe' ), - '.exe exception 2' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testHash() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( 'a#b.c' ), - 'Hash character preceding extension' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testHash2() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( 'a?#b.c' ), - 'Hash character preceding extension 2' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testDotAtEnd() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( '.' ), - 'Dot at end of string' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testTwoDots() { - $this->assertEquals( - 'z', - IEUrlExtension::findIE6Extension( 'x.y.z' ), - 'Two dots' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testScriptQuery() { - $this->assertEquals( - 'php', - IEUrlExtension::findIE6Extension( 'example.php?foo=a&bar=b' ), - 'Script with query' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testEscapedScriptQuery() { - $this->assertEquals( - '', - IEUrlExtension::findIE6Extension( 'example%2Ephp?foo=a&bar=b' ), - 'Script with urlencoded dot and query' - ); - } - - /** - * @covers IEUrlExtension::findIE6Extension - */ - public function testEscapedScriptQueryDot() { - $this->assertEquals( - 'y', - IEUrlExtension::findIE6Extension( 'example%2Ephp?foo=a.x&bar=b.y' ), - 'Script with urlencoded dot and query with dot' + public function provideFindIE6Extension() { + return [ + // url, expected, message + [ 'x.y', 'y', 'Simple extension' ], + [ 'x', '', 'No extension' ], + [ '', '', 'Empty string' ], + [ '?', '', 'Question mark only' ], + [ '.x?', 'x', 'Extension then question mark' ], + [ '?.x', 'x', 'Question mark then extension' ], + [ '.x*', '', 'Extension with invalid character' ], + [ '*.x', 'x', 'Invalid character followed by an extension' ], + [ 'a?b?.c?.d?e?f', 'c', 'Multiple question marks' ], + [ 'a?b?.exe?.d?.e', 'd', '.exe exception' ], + [ 'a?b?.exe', 'exe', '.exe exception 2' ], + [ 'a#b.c', '', 'Hash character preceding extension' ], + [ 'a?#b.c', '', 'Hash character preceding extension 2' ], + [ '.', '', 'Dot at end of string' ], + [ 'x.y.z', 'z', 'Two dots' ], + [ 'example.php?foo=a&bar=b', 'php', 'Script with query' ], + [ 'example%2Ephp?foo=a&bar=b', '', 'Script with urlencoded dot and query' ], + [ 'example%2Ephp?foo=a.x&bar=b.y', 'y', 'Script with urlencoded dot and query with dot' ], + ]; + } + + /** + * @covers IEUrlExtension::findIE6Extension + * @dataProvider provideFindIE6Extension + */ + public function testFindIE6Extension( $url, $expected, $message ) { + $this->assertEquals( + $expected, + IEUrlExtension::findIE6Extension( $url ), + $message ); } } -- 2.20.1