Merge "Add LinkTarget::hasFragment() helper function"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 21 Apr 2016 08:29:48 +0000 (08:29 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 21 Apr 2016 08:29:48 +0000 (08:29 +0000)
includes/LinkTarget.php
includes/title/TitleValue.php
tests/phpunit/includes/title/TitleValueTest.php

index 175a839..8246f7d 100644 (file)
@@ -21,6 +21,13 @@ interface LinkTarget {
         */
        public function getFragment();
 
+       /**
+        * Whether the link target has a fragment
+        *
+        * @return bool
+        */
+       public function hasFragment();
+
        /**
         * Get the main part with underscores.
         *
index c8ebc2a..18a06ea 100644 (file)
@@ -95,6 +95,14 @@ class TitleValue implements LinkTarget {
                return $this->fragment;
        }
 
+       /**
+        * @since 1.27
+        * @return bool
+        */
+       public function hasFragment() {
+               return $this->fragment !== '';
+       }
+
        /**
         * Returns the title's DB key, as supplied to the constructor,
         * without namespace prefix or fragment.
index af7b758..013bbc1 100644 (file)
  */
 class TitleValueTest extends MediaWikiTestCase {
 
-       public function testConstruction() {
-               $title = new TitleValue( NS_USER, 'TestThis', 'stuff' );
+       public function goodConstructorProvider() {
+               return [
+                       [ NS_USER, 'TestThis', 'stuff', true ],
+                       [ NS_USER, 'TestThis', '', false ],
+               ];
+       }
 
-               $this->assertEquals( NS_USER, $title->getNamespace() );
-               $this->assertEquals( 'TestThis', $title->getText() );
-               $this->assertEquals( 'stuff', $title->getFragment() );
+       /**
+        * @dataProvider goodConstructorProvider
+        */
+       public function testConstruction( $ns, $text, $fragment, $hasFragment ) {
+               $title = new TitleValue( $ns, $text, $fragment );
+
+               $this->assertEquals( $ns, $title->getNamespace() );
+               $this->assertEquals( $text, $title->getText() );
+               $this->assertEquals( $fragment, $title->getFragment() );
+               $this->assertEquals( $hasFragment, $title->hasFragment() );
        }
 
        public function badConstructorProvider() {