Also provide assertNotTag in MediaWikiTestCase
authorMarius Hoch <hoo@online.de>
Fri, 17 Oct 2014 18:14:35 +0000 (20:14 +0200)
committerMarius Hoch <hoo@online.de>
Fri, 17 Oct 2014 18:14:35 +0000 (20:14 +0200)
And mark that and assertTag as deprecated to avoid
new usages.

Bug: 69505
Change-Id: Ibfe78fd1914adfb08b29f61c59c43899bd8840d2

tests/phpunit/MediaWikiTestCase.php

index 4abb4e5..e12d6ab 100644 (file)
@@ -1148,10 +1148,24 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
                $this->assertEmpty( $errors, implode( "\n", $errors ) );
        }
 
+       /**
+        * @param array $matcher
+        * @param string $actual
+        * @param bool $isHtml
+        *
+        * @return bool
+        */
+       private static function tagMatch( $matcher, $actual, $isHtml = true ) {
+               $dom = PHPUnit_Util_XML::load( $actual, $isHtml );
+               $tags = PHPUnit_Util_XML::findNodes( $dom, $matcher, $isHtml );
+               return count( $tags ) > 0 && $tags[0] instanceof DOMNode;
+       }
+
        /**
         * Note: we are overriding this method to remove the deprecated error
         * @see https://bugzilla.wikimedia.org/show_bug.cgi?id=69505
         * @see https://github.com/sebastianbergmann/phpunit/issues/1292
+        * @deprecated
         *
         * @param array $matcher
         * @param string $actual
@@ -1161,10 +1175,21 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
        public static function assertTag( $matcher, $actual, $message = '', $isHtml = true ) {
                //trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
 
-               $dom = PHPUnit_Util_XML::load( $actual, $isHtml );
-               $tags = PHPUnit_Util_XML::findNodes( $dom, $matcher, $isHtml );
-               $matched = count( $tags ) > 0 && $tags[0] instanceof DOMNode;
+               self::assertTrue( self::tagMatch( $matcher, $actual, $isHtml ), $message );
+       }
+
+       /**
+        * @see MediaWikiTestCase::assertTag
+        * @deprecated
+        *
+        * @param array $matcher
+        * @param string $actual
+        * @param string $message
+        * @param bool $isHtml
+        */
+       public static function assertNotTag( $matcher, $actual, $message = '', $isHtml = true ) {
+               //trigger_error(__METHOD__ . ' is deprecated', E_USER_DEPRECATED);
 
-               self::assertTrue( $matched, $message );
+               self::assertFalse( self::tagMatch( $matcher, $actual, $isHtml ), $message );
        }
 }