Title: Test the ->equals() method more thoughroughly
authorJames D. Forrester <jforrester@wikimedia.org>
Sat, 16 Mar 2019 19:40:13 +0000 (12:40 -0700)
committerJames D. Forrester <jforrester@wikimedia.org>
Thu, 21 Mar 2019 23:54:58 +0000 (16:54 -0700)
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

tests/phpunit/includes/TitleMethodsTest.php
tests/phpunit/includes/TitleTest.php

index 25dc9b3..abd70b2 100644 (file)
@@ -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 ],
index 4af12a8..35b196a 100644 (file)
@@ -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 )
+               );
+       }
 }