Merge "Remove useless StatusTest::testCanConstruct()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 28 Dec 2017 10:42:14 +0000 (10:42 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 28 Dec 2017 10:42:14 +0000 (10:42 +0000)
12 files changed:
includes/Linker.php
includes/parser/Parser.php
includes/parser/Preprocessor_DOM.php
includes/parser/Preprocessor_Hash.php
includes/parser/Sanitizer.php
maintenance/benchmarks/Benchmarker.php
maintenance/dumpTextPass.php
tests/parser/parserTests.txt
tests/phpunit/includes/MWNamespaceTest.php
tests/phpunit/includes/TemplateParserTest.php
tests/phpunit/maintenance/BenchmarkerTest.php [new file with mode: 0644]
tests/qunit/suites/resources/mediawiki/mediawiki.toc.test.js

index 48be3bf..84e3103 100644 (file)
@@ -1595,7 +1595,12 @@ class Linker {
                $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
 
                return '<div id="toc" class="toc">'
-                       . '<div class="toctitle"><h2>' . $title . "</h2></div>\n"
+                       . Html::openElement( 'div', [
+                               'class' => 'toctitle',
+                               'lang' => $lang->getHtmlCode(),
+                               'dir' => $lang->getDir(),
+                       ] )
+                       . '<h2>' . $title . "</h2></div>\n"
                        . $toc
                        . "</ul>\n</div>\n";
        }
index 10a338e..078de3c 100644 (file)
@@ -3114,10 +3114,29 @@ class Parser {
                                        throw $ex;
                                }
 
-                               # The interface for parser functions allows for extracting
-                               # flags into the local scope. Extract any forwarded flags
-                               # here.
-                               extract( $result );
+                               // Extract any forwarded flags
+                               if ( isset( $result['found'] ) ) {
+                                       $found = $result['found'];
+                               }
+                               if ( array_key_exists( 'text', $result ) ) {
+                                       // a string or null
+                                       $text = $result['text'];
+                               }
+                               if ( isset( $result['nowiki'] ) ) {
+                                       $nowiki = $result['nowiki'];
+                               }
+                               if ( isset( $result['isHTML'] ) ) {
+                                       $isHTML = $result['isHTML'];
+                               }
+                               if ( isset( $result['forceRawInterwiki'] ) ) {
+                                       $forceRawInterwiki = $result['forceRawInterwiki'];
+                               }
+                               if ( isset( $result['isChildObj'] ) ) {
+                                       $isChildObj = $result['isChildObj'];
+                               }
+                               if ( isset( $result['isLocalObj'] ) ) {
+                                       $isLocalObj = $result['isLocalObj'];
+                               }
                        }
                }
 
@@ -3862,11 +3881,12 @@ class Parser {
                        }
 
                        if ( is_array( $output ) ) {
-                               # Extract flags to local scope (to override $markerType)
+                               // Extract flags
                                $flags = $output;
                                $output = $flags[0];
-                               unset( $flags[0] );
-                               extract( $flags );
+                               if ( isset( $flags['markerType'] ) ) {
+                                       $markerType = $flags['markerType'];
+                               }
                        }
                } else {
                        if ( is_null( $attrText ) ) {
index 2588962..5368125 100644 (file)
@@ -559,8 +559,16 @@ class Preprocessor_DOM extends Preprocessor {
                                                'count' => $count ];
                                        $stack->push( $piece );
                                        $accum =& $stack->getAccum();
-                                       $flags = $stack->getFlags();
-                                       extract( $flags );
+                                       $stackFlags = $stack->getFlags();
+                                       if ( isset( $stackFlags['findEquals'] ) ) {
+                                               $findEquals = $stackFlags['findEquals'];
+                                       }
+                                       if ( isset( $stackFlags['findPipe'] ) ) {
+                                               $findPipe = $stackFlags['findPipe'];
+                                       }
+                                       if ( isset( $stackFlags['inHeading'] ) ) {
+                                               $inHeading = $stackFlags['inHeading'];
+                                       }
                                        $i += $count;
                                }
                        } elseif ( $found == 'line-end' ) {
@@ -610,8 +618,16 @@ class Preprocessor_DOM extends Preprocessor {
                                // Unwind the stack
                                $stack->pop();
                                $accum =& $stack->getAccum();
-                               $flags = $stack->getFlags();
-                               extract( $flags );
+                               $stackFlags = $stack->getFlags();
+                               if ( isset( $stackFlags['findEquals'] ) ) {
+                                       $findEquals = $stackFlags['findEquals'];
+                               }
+                               if ( isset( $stackFlags['findPipe'] ) ) {
+                                       $findPipe = $stackFlags['findPipe'];
+                               }
+                               if ( isset( $stackFlags['inHeading'] ) ) {
+                                       $inHeading = $stackFlags['inHeading'];
+                               }
 
                                // Append the result to the enclosing accumulator
                                $accum .= $element;
@@ -640,8 +656,16 @@ class Preprocessor_DOM extends Preprocessor {
 
                                        $stack->push( $piece );
                                        $accum =& $stack->getAccum();
-                                       $flags = $stack->getFlags();
-                                       extract( $flags );
+                                       $stackFlags = $stack->getFlags();
+                                       if ( isset( $stackFlags['findEquals'] ) ) {
+                                               $findEquals = $stackFlags['findEquals'];
+                                       }
+                                       if ( isset( $stackFlags['findPipe'] ) ) {
+                                               $findPipe = $stackFlags['findPipe'];
+                                       }
+                                       if ( isset( $stackFlags['inHeading'] ) ) {
+                                               $inHeading = $stackFlags['inHeading'];
+                                       }
                                } else {
                                        # Add literal brace(s)
                                        $accum .= htmlspecialchars( str_repeat( $curChar, $count ) );
@@ -748,8 +772,16 @@ class Preprocessor_DOM extends Preprocessor {
                                                $accum .= $s;
                                        }
                                }
-                               $flags = $stack->getFlags();
-                               extract( $flags );
+                               $stackFlags = $stack->getFlags();
+                               if ( isset( $stackFlags['findEquals'] ) ) {
+                                       $findEquals = $stackFlags['findEquals'];
+                               }
+                               if ( isset( $stackFlags['findPipe'] ) ) {
+                                       $findPipe = $stackFlags['findPipe'];
+                               }
+                               if ( isset( $stackFlags['inHeading'] ) ) {
+                                       $inHeading = $stackFlags['inHeading'];
+                               }
 
                                # Add XML element to the enclosing accumulator
                                $accum .= $element;
index 735c33a..145fbbc 100644 (file)
@@ -497,7 +497,16 @@ class Preprocessor_Hash extends Preprocessor {
                                                'count' => $count ];
                                        $stack->push( $piece );
                                        $accum =& $stack->getAccum();
-                                       extract( $stack->getFlags() );
+                                       $stackFlags = $stack->getFlags();
+                                       if ( isset( $stackFlags['findEquals'] ) ) {
+                                               $findEquals = $stackFlags['findEquals'];
+                                       }
+                                       if ( isset( $stackFlags['findPipe'] ) ) {
+                                               $findPipe = $stackFlags['findPipe'];
+                                       }
+                                       if ( isset( $stackFlags['inHeading'] ) ) {
+                                               $inHeading = $stackFlags['inHeading'];
+                                       }
                                        $i += $count;
                                }
                        } elseif ( $found == 'line-end' ) {
@@ -554,7 +563,16 @@ class Preprocessor_Hash extends Preprocessor {
                                // Unwind the stack
                                $stack->pop();
                                $accum =& $stack->getAccum();
-                               extract( $stack->getFlags() );
+                               $stackFlags = $stack->getFlags();
+                               if ( isset( $stackFlags['findEquals'] ) ) {
+                                       $findEquals = $stackFlags['findEquals'];
+                               }
+                               if ( isset( $stackFlags['findPipe'] ) ) {
+                                       $findPipe = $stackFlags['findPipe'];
+                               }
+                               if ( isset( $stackFlags['inHeading'] ) ) {
+                                       $inHeading = $stackFlags['inHeading'];
+                               }
 
                                // Append the result to the enclosing accumulator
                                array_splice( $accum, count( $accum ), 0, $element );
@@ -584,7 +602,16 @@ class Preprocessor_Hash extends Preprocessor {
 
                                        $stack->push( $piece );
                                        $accum =& $stack->getAccum();
-                                       extract( $stack->getFlags() );
+                                       $stackFlags = $stack->getFlags();
+                                       if ( isset( $stackFlags['findEquals'] ) ) {
+                                               $findEquals = $stackFlags['findEquals'];
+                                       }
+                                       if ( isset( $stackFlags['findPipe'] ) ) {
+                                               $findPipe = $stackFlags['findPipe'];
+                                       }
+                                       if ( isset( $stackFlags['inHeading'] ) ) {
+                                               $inHeading = $stackFlags['inHeading'];
+                                       }
                                } else {
                                        # Add literal brace(s)
                                        self::addLiteral( $accum, str_repeat( $curChar, $count ) );
@@ -695,7 +722,16 @@ class Preprocessor_Hash extends Preprocessor {
                                        }
                                }
 
-                               extract( $stack->getFlags() );
+                               $stackFlags = $stack->getFlags();
+                               if ( isset( $stackFlags['findEquals'] ) ) {
+                                       $findEquals = $stackFlags['findEquals'];
+                               }
+                               if ( isset( $stackFlags['findPipe'] ) ) {
+                                       $findPipe = $stackFlags['findPipe'];
+                               }
+                               if ( isset( $stackFlags['inHeading'] ) ) {
+                                       $inHeading = $stackFlags['inHeading'];
+                               }
 
                                # Add XML element to the enclosing accumulator
                                array_splice( $accum, count( $accum ), 0, $element );
index 20fee2d..b570a43 100644 (file)
@@ -477,7 +477,16 @@ class Sanitizer {
        public static function removeHTMLtags( $text, $processCallback = null,
                $args = [], $extratags = [], $removetags = [], $warnCallback = null
        ) {
-               extract( self::getRecognizedTagData( $extratags, $removetags ) );
+               $tagData = self::getRecognizedTagData( $extratags, $removetags );
+               $htmlpairs = $tagData['htmlpairs'];
+               $htmlsingle = $tagData['htmlsingle'];
+               $htmlsingleonly = $tagData['htmlsingleonly'];
+               $htmlnest = $tagData['htmlnest'];
+               $tabletags = $tagData['tabletags'];
+               $htmllist = $tagData['htmllist'];
+               $listtags = $tagData['listtags'];
+               $htmlsingleallowed = $tagData['htmlsingleallowed'];
+               $htmlelements = $tagData['htmlelements'];
 
                # Remove HTML comments
                $text = self::removeHTMLcomments( $text );
index 832da4d..ffb8cb3 100644 (file)
@@ -26,7 +26,9 @@
  * @ingroup Benchmark
  */
 
+// @codeCoverageIgnoreStart
 require_once __DIR__ . '/../Maintenance.php';
+// @codeCoverageIgnoreEnd
 
 /**
  * Base class for benchmark scripts.
index 2b79b54..0604f48 100644 (file)
@@ -25,6 +25,7 @@
  */
 
 require_once __DIR__ . '/backup.inc';
+require_once __DIR__ . '/7zip.inc';
 require_once __DIR__ . '/../includes/export/WikiExporter.php';
 
 use Wikimedia\Rdbms\IMaintainableDatabase;
index 72ee550..840c74d 100644 (file)
@@ -16578,7 +16578,7 @@ Section headings with TOC
 Some text
 ===Another headline===
 !! html
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Headline_1"><span class="tocnumber">1</span> <span class="toctext">Headline 1</span></a>
 <ul>
@@ -16621,7 +16621,7 @@ __FORCETOC__
 == Headline 2 ==
 == Headline ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Headline_2"><span class="tocnumber">1</span> <span class="toctext">Headline 2</span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#Headline"><span class="tocnumber">2</span> <span class="toctext">Headline</span></a></li>
@@ -16655,7 +16655,7 @@ parsoid=wt2html
 ========= Level 9 Heading=========
 ========== Level 10 Heading==========
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Level_1_Heading"><span class="tocnumber">1</span> <span class="toctext">Level 1 Heading</span></a>
 <ul>
@@ -16719,7 +16719,7 @@ TOC regression (T11764)
 == title 2 ==
 === title 2.1 ===
 !! html
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
 <ul>
@@ -16754,7 +16754,7 @@ TOC for heading containing <span id="..."></span> (T96153)
 __FORCETOC__
 ==<span id="old-anchor"></span>New title==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#New_title"><span class="tocnumber">1</span> <span class="toctext">New title</span></a></li>
 </ul>
@@ -16776,7 +16776,7 @@ wgMaxTocLevel=3
 == title 2 ==
 === title 2.1 ===
 !! html
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
 <ul>
@@ -16812,7 +16812,7 @@ wgMaxTocLevel=3
 ====Section 1.1.1.1====
 ==Section 2==
 !! html
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a>
 <ul>
@@ -16905,7 +16905,7 @@ __TOC__
 === title 1.1 ===
 == title 2 ==
 !! html
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
 <ul>
@@ -16981,7 +16981,7 @@ section 5
 !! html/php
 <p>The tooltips shall not show entities to the user (ie. be double escaped)
 </p>
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#text_.3E_text"><span class="tocnumber">1</span> <span class="toctext">text &gt; text</span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#text_.3C_text"><span class="tocnumber">2</span> <span class="toctext">text &lt; text</span></a></li>
@@ -17057,7 +17057,7 @@ section 6
 !! html/php
 <p>Id should not contain + for spaces
 </p>
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Space_between_Text"><span class="tocnumber">1</span> <span class="toctext">Space between Text</span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#Space-Entity_between_Text"><span class="tocnumber">2</span> <span class="toctext">Space-Entity&#32;between&#32;Text</span></a></li>
@@ -17133,7 +17133,7 @@ parsoid=wt2html,wt2wt,html2html
 =''italic'' heading==
 ==''italic'' heading=
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#foo.3D"><span class="tocnumber">1</span> <span class="toctext">foo=</span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#.3Dfoo"><span class="tocnumber">2</span> <span class="toctext">=foo</span></a></li>
@@ -17168,7 +17168,7 @@ HTML headers vs TOC (T25393)
 == Header 2.2 ==
 __NOEDITSECTION__
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1"><a href="#Header_1"><span class="tocnumber">1</span> <span class="toctext">Header 1</span></a>
 <ul>
@@ -19081,7 +19081,7 @@ Fuzz testing: Parser14
 http://__TOC__
 !! html/php
 <h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-http://<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+http://<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
 </ul>
@@ -19092,7 +19092,7 @@ http://<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
 <h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
 <p>http://</p>
 <div id="toc" class="toc">
-<div class="toctitle">
+<div class="toctitle" lang="en" dir="ltr" xml:lang="en">
 <h2>Contents</h2>
 </div>
 <ul>
@@ -21608,7 +21608,7 @@ Out-of-order TOC heading levels
 =====5=====
 ==2==
 !! html
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#2"><span class="tocnumber">1</span> <span class="toctext">2</span></a>
 <ul>
@@ -24242,7 +24242,7 @@ title=[[Main Page]]
 __TOC__
 == ''Lost'' episodes ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Lost_episodes"><span class="tocnumber">1</span> <span class="toctext"><i>Lost</i> episodes</span></a></li>
 </ul>
@@ -24263,7 +24263,7 @@ title=[[Main Page]]
 __TOC__
 == '''should be bold''' then normal text ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#should_be_bold_then_normal_text"><span class="tocnumber">1</span> <span class="toctext"><b>should be bold</b> then normal text</span></a></li>
 </ul>
@@ -24284,7 +24284,7 @@ title=[[Main Page]]
 __TOC__
 == Image [[Image:foobar.jpg]] ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Image"><span class="tocnumber">1</span> <span class="toctext">Image</span></a></li>
 </ul>
@@ -24305,7 +24305,7 @@ title=[[Main Page]]
 __TOC__
 == <blockquote>Quote</blockquote> ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
 </ul>
@@ -24316,7 +24316,7 @@ __TOC__
 !! html/php+tidy
 <p></p>
 <div id="toc" class="toc">
-<div class="toctitle">
+<div class="toctitle" lang="en" dir="ltr" xml:lang="en">
 <h2>Contents</h2>
 </div>
 <ul>
@@ -24346,7 +24346,7 @@ __TOC__
 <small>Hanc marginis exiguitas non caperet.</small>
 QED
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Proof:_2_&lt;_3"><span class="tocnumber">1</span> <span class="toctext">Proof: 2 &lt; 3</span></a></li>
 </ul>
@@ -24371,7 +24371,7 @@ __TOC__
 
 == <i>Foo</i> <blockquote>Bar</blockquote> ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
@@ -24384,7 +24384,7 @@ __TOC__
 !! html/php+tidy
 <p></p>
 <div id="toc" class="toc">
-<div class="toctitle">
+<div class="toctitle" lang="en" dir="ltr" xml:lang="en">
 <h2>Contents</h2>
 </div>
 <ul>
@@ -24418,7 +24418,7 @@ __TOC__
 
 == <sup class="a > b">Evilbye</sup> ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Hello"><span class="tocnumber">1</span> <span class="toctext"><sup>Hello</sup></span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#b.22.3EEvilbye"><span class="tocnumber">2</span> <span class="toctext"><sup> b"&gt;Evilbye</sup></span></a></li>
@@ -24449,7 +24449,7 @@ __TOC__
 
 == <span dir="ltr" style="font-style: italic">Attributes after dir on these span tags must be deleted from the TOC</span> ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#C.2B.2B"><span class="tocnumber">1</span> <span class="toctext"><span dir="ltr">C++</span></span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#.D7.96.D7.91.D7.A0.D7.92.21"><span class="tocnumber">2</span> <span class="toctext"><span dir="rtl">זבנג!</span></span></a></li>
@@ -24480,7 +24480,7 @@ T74884: bdi element in ToC
 __TOC__
 == <bdi>test</bdi> ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#test"><span class="tocnumber">1</span> <span class="toctext"><bdi>test</bdi></span></a></li>
 </ul>
@@ -24499,7 +24499,7 @@ T35715: s/strike element in ToC
 __TOC__
 == <s>test</s> test <strike>test</strike> ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#test_test_test"><span class="tocnumber">1</span> <span class="toctext"><s>test</s> test <strike>test</strike></span></a></li>
 </ul>
@@ -24521,7 +24521,7 @@ Empty <p> tag in TOC, removed by Sanitizer (T92892)
 __TOC__
 == x ==
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#x"><span class="tocnumber">1</span> <span class="toctext">x</span></a></li>
 </ul>
@@ -24532,7 +24532,7 @@ __TOC__
 !! html/php+tidy
 <p></p>
 <div id="toc" class="toc">
-<div class="toctitle">
+<div class="toctitle" lang="en" dir="ltr" xml:lang="en">
 <h2>Contents</h2>
 </div>
 <ul>
@@ -29955,7 +29955,7 @@ wgFragmentMode=[ 'html5', 'legacy' ]
 [[#啤酒]] [[#%E5%95%A4%E9%85%92]]
 
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
@@ -30021,7 +30021,7 @@ wgFragmentMode=[ 'legacy', 'html5' ]
 [[#啤酒]] [[#%E5%95%A4%E9%85%92]]
 
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
@@ -30069,7 +30069,7 @@ wgFragmentMode=[ 'html5' ]
 [[#啤酒]] [[#%E5%95%A4%E9%85%92]]
 
 !! html/php
-<div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
+<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
 <ul>
 <li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
 <li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
index 498532f..91101bd 100644 (file)
@@ -7,7 +7,6 @@
 
 /**
  * Test class for MWNamespace.
- * @todo covers tags
  * @todo FIXME: this test file is a mess
  */
 class MWNamespaceTest extends MediaWikiTestCase {
index c161f85..4a803e6 100644 (file)
@@ -2,6 +2,7 @@
 
 /**
  * @group Templates
+ * @covers TemplateParser
  */
 class TemplateParserTest extends MediaWikiTestCase {
 
@@ -19,9 +20,6 @@ class TemplateParserTest extends MediaWikiTestCase {
 
        /**
         * @dataProvider provideProcessTemplate
-        * @covers TemplateParser::processTemplate
-        * @covers TemplateParser::getTemplate
-        * @covers TemplateParser::getTemplateFilename
         */
        public function testProcessTemplate( $name, $args, $result, $exception = false ) {
                if ( $exception ) {
diff --git a/tests/phpunit/maintenance/BenchmarkerTest.php b/tests/phpunit/maintenance/BenchmarkerTest.php
new file mode 100644 (file)
index 0000000..69f98bd
--- /dev/null
@@ -0,0 +1,135 @@
+<?php
+
+use Wikimedia\TestingAccessWrapper;
+
+/**
+ * @covers Benchmarker
+ */
+class BenchmarkerTest extends PHPUnit_Framework_TestCase {
+       public function testBenchSimple() {
+               $bench = $this->getMockBuilder( Benchmarker::class )
+                       ->setMethods( [ 'execute', 'output' ] )
+                       ->getMock();
+               $benchProxy = TestingAccessWrapper::newFromObject( $bench );
+               $benchProxy->defaultCount = 3;
+
+               $count = 0;
+               $bench->bench( [
+                       'test' => function () use ( &$count ) {
+                                       $count++;
+                       }
+               ] );
+
+               $this->assertSame( 3, $count );
+       }
+
+       public function testBenchSetup() {
+               $bench = $this->getMockBuilder( Benchmarker::class )
+                       ->setMethods( [ 'execute', 'output' ] )
+                       ->getMock();
+               $benchProxy = TestingAccessWrapper::newFromObject( $bench );
+               $benchProxy->defaultCount = 2;
+
+               $buffer = [];
+               $bench->bench( [
+                       'test' => [
+                               'setup' => function () use ( &$buffer ) {
+                                               $buffer[] = 'setup';
+                               },
+                               'function' => function () use ( &$buffer ) {
+                                               $buffer[] = 'run';
+                               }
+                       ]
+               ] );
+
+               $this->assertSame( [ 'setup', 'run', 'run' ], $buffer );
+       }
+
+       public function testBenchVerbose() {
+               $bench = $this->getMockBuilder( Benchmarker::class )
+                       ->setMethods( [ 'execute', 'output', 'hasOption', 'verboseRun' ] )
+                       ->getMock();
+               $benchProxy = TestingAccessWrapper::newFromObject( $bench );
+               $benchProxy->defaultCount = 1;
+
+               $bench->expects( $this->exactly( 2 ) )->method( 'hasOption' )
+                       ->will( $this->returnValueMap( [
+                                       [ 'verbose', true ],
+                                       [ 'count', false ],
+                               ] ) );
+
+               $bench->expects( $this->once() )->method( 'verboseRun' )
+                       ->with( 0 )
+                       ->willReturn( null );
+
+               $bench->bench( [
+                       'test' => function () {
+                       }
+               ] );
+       }
+
+       public function noop() {
+       }
+
+       public function testBenchName_method() {
+               $bench = $this->getMockBuilder( Benchmarker::class )
+                       ->setMethods( [ 'execute', 'output', 'addResult' ] )
+                       ->getMock();
+               $benchProxy = TestingAccessWrapper::newFromObject( $bench );
+               $benchProxy->defaultCount = 1;
+
+               $bench->expects( $this->once() )->method( 'addResult' )
+                       ->with( $this->callback( function ( $res ) {
+                               return isset( $res['name'] ) && $res['name'] === __CLASS__ . '::noop()';
+                       } ) );
+
+               $bench->bench( [
+                       [ 'function' => [ $this, 'noop' ] ]
+               ] );
+       }
+
+       public function testBenchName_string() {
+               $bench = $this->getMockBuilder( Benchmarker::class )
+                       ->setMethods( [ 'execute', 'output', 'addResult' ] )
+                       ->getMock();
+               $benchProxy = TestingAccessWrapper::newFromObject( $bench );
+               $benchProxy->defaultCount = 1;
+
+               $bench->expects( $this->once() )->method( 'addResult' )
+                       ->with( $this->callback( function ( $res ) {
+                               return 'strtolower(A)';
+                       } ) );
+
+               $bench->bench( [ [
+                       'function' => 'strtolower',
+                       'args' => [ 'A' ],
+               ] ] );
+       }
+
+       /**
+        * @covers Benchmarker::verboseRun
+        */
+       public function testVerboseRun() {
+               $bench = $this->getMockBuilder( Benchmarker::class )
+                       ->setMethods( [ 'execute', 'output', 'hasOption', 'startBench', 'addResult' ] )
+                       ->getMock();
+               $benchProxy = TestingAccessWrapper::newFromObject( $bench );
+               $benchProxy->defaultCount = 1;
+
+               $bench->expects( $this->exactly( 2 ) )->method( 'hasOption' )
+                       ->will( $this->returnValueMap( [
+                                       [ 'verbose', true ],
+                                       [ 'count', false ],
+                               ] ) );
+
+               $bench->expects( $this->once() )->method( 'output' )
+                       ->with( $this->callback( function ( $out ) {
+                               return preg_match( '/memory.+ peak/', $out ) === 1;
+                       } ) );
+
+               $bench->bench( [
+                       'test' => function () {
+                       }
+               ] );
+       }
+}
index b20b68f..6a1b83c 100644 (file)
@@ -12,7 +12,7 @@
                assert.strictEqual( $( '.toc' ).length, 0, 'There is no table of contents on the page at the beginning' );
 
                tocHtml = '<div id="toc" class="toc">' +
-                       '<div class="toctitle">' +
+                       '<div class="toctitle" lang="en" dir="ltr">' +
                        '<h2>Contents</h2>' +
                        '</div>' +
                        '<ul><li></li></ul>' +