From: James D. Forrester Date: Sat, 16 Mar 2019 19:40:13 +0000 (-0700) Subject: Title: Test the ->equals() method more thoughroughly X-Git-Tag: 1.34.0-rc.0~2418^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=76617a777176ac1109791929c90bc054c69bcfd1;p=lhc%2Fweb%2Fwiklou.git Title: Test the ->equals() method more thoughroughly Move from TitleMethodTest to TitleTest for simplicity with duplicating into TitleValueTest. We're not using the language- and namespace-specific test setup with these tests anyway. Change-Id: Ieec78c35f04faea5e01da8d39ed88f7c4876ac84 --- diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index 25dc9b3e30..abd70b2524 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -31,30 +31,6 @@ class TitleMethodsTest extends MediaWikiLangTestCase { ); } - public static function provideEquals() { - return [ - [ 'Main Page', 'Main Page', true ], - [ 'Main Page', 'Not The Main Page', false ], - [ 'Main Page', 'Project:Main Page', false ], - [ 'File:Example.png', 'Image:Example.png', true ], - [ 'Special:Version', 'Special:Version', true ], - [ 'Special:Version', 'Special:Recentchanges', false ], - [ 'Special:Version', 'Main Page', false ], - ]; - } - - /** - * @dataProvider provideEquals - * @covers Title::equals - */ - public function testEquals( $titleA, $titleB, $expectedBool ) { - $titleA = Title::newFromText( $titleA ); - $titleB = Title::newFromText( $titleB ); - - $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) ); - $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) ); - } - public static function provideInNamespace() { return [ [ 'Main Page', NS_MAIN, true ], diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 4af12a808c..35b196a9ba 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -981,4 +981,93 @@ class TitleTest extends MediaWikiTestCase { [ 'Main Page', false ], ]; } + + public function provideEquals() { + yield [ + Title::newFromText( 'Main Page' ), + Title::newFromText( 'Main Page' ), + true + ]; + yield [ + Title::newFromText( 'Main Page' ), + Title::newFromText( 'Not The Main Page' ), + false + ]; + yield [ + Title::newFromText( 'Main Page' ), + Title::newFromText( 'Project:Main Page' ), + false + ]; + yield [ + Title::newFromText( 'File:Example.png' ), + Title::newFromText( 'Image:Example.png' ), + true + ]; + yield [ + Title::newFromText( 'Special:Version' ), + Title::newFromText( 'Special:Version' ), + true + ]; + yield [ + Title::newFromText( 'Special:Version' ), + Title::newFromText( 'Special:Recentchanges' ), + false + ]; + yield [ + Title::newFromText( 'Special:Version' ), + Title::newFromText( 'Main Page' ), + false + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', '', '' ), + Title::makeTitle( NS_MAIN, 'Foo', '', '' ), + true + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', '', '' ), + Title::makeTitle( NS_MAIN, 'Bar', '', '' ), + false + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', '', '' ), + Title::makeTitle( NS_TALK, 'Foo', '', '' ), + false + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ), + Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ), + true + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ), + Title::makeTitle( NS_MAIN, 'Foo', 'Baz', '' ), + true + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', 'Bar', '' ), + Title::makeTitle( NS_MAIN, 'Foo', '', '' ), + true + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', '', 'baz' ), + Title::makeTitle( NS_MAIN, 'Foo', '', 'baz' ), + true + ]; + yield [ + Title::makeTitle( NS_MAIN, 'Foo', '', '' ), + Title::makeTitle( NS_MAIN, 'Foo', '', 'baz' ), + false + ]; + } + + /** + * @covers Title::equals + * @dataProvider provideEquals + */ + public function testEquals( Title $firstValue, /* LinkTarget */ $secondValue, $expectedSame ) { + $this->assertSame( + $expectedSame, + $firstValue->equals( $secondValue ) + ); + } }