From: jenkins-bot Date: Thu, 28 Dec 2017 11:05:51 +0000 (+0000) Subject: Merge "tests: Complete test coverage of HtmlArmor" X-Git-Tag: 1.31.0-rc.0~1065 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=5d743b03814d2e36abc45f0d9e048d6390b01084;hp=bb9e1c1aa906b3c6c2c19eb48c33b635dee6af20 Merge "tests: Complete test coverage of HtmlArmor" --- diff --git a/includes/Linker.php b/includes/Linker.php index 48be3bfe7a..84e3103c65 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1595,7 +1595,12 @@ class Linker { $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped(); return '
' - . '

' . $title . "

\n" + . Html::openElement( 'div', [ + 'class' => 'toctitle', + 'lang' => $lang->getHtmlCode(), + 'dir' => $lang->getDir(), + ] ) + . '

' . $title . "

\n" . $toc . "\n\n"; } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 10a338ed01..078de3c601 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 ) ) { diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 2588962604..5368125f35 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -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; diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 735c33a4fe..145fbbc592 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -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 ); diff --git a/includes/parser/Sanitizer.php b/includes/parser/Sanitizer.php index 20fee2db29..b570a43c06 100644 --- a/includes/parser/Sanitizer.php +++ b/includes/parser/Sanitizer.php @@ -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 ); diff --git a/maintenance/benchmarks/Benchmarker.php b/maintenance/benchmarks/Benchmarker.php index 832da4db79..ffb8cb353f 100644 --- a/maintenance/benchmarks/Benchmarker.php +++ b/maintenance/benchmarks/Benchmarker.php @@ -26,7 +26,9 @@ * @ingroup Benchmark */ +// @codeCoverageIgnoreStart require_once __DIR__ . '/../Maintenance.php'; +// @codeCoverageIgnoreEnd /** * Base class for benchmark scripts. diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 2b79b546d4..0604f4886b 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -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; diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 72ee550109..840c74dbb9 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -16578,7 +16578,7 @@ Section headings with TOC Some text ===Another headline=== !! html -

Contents

+

Contents

  • 1 Headline 1
      @@ -16621,7 +16621,7 @@ __FORCETOC__ == Headline 2 == == Headline == !! html/php -

      Contents

      +

      Contents

      • 1 Headline 2
      • 2 Headline
      • @@ -16655,7 +16655,7 @@ parsoid=wt2html ========= Level 9 Heading========= ========== Level 10 Heading========== !! html/php -

        Contents

        +

        Contents

        • 1 Level 1 Heading
            @@ -16719,7 +16719,7 @@ TOC regression (T11764) == title 2 == === title 2.1 === !! html -

            Contents

            +

            Contents

            • 1 title 1
                @@ -16754,7 +16754,7 @@ TOC for heading containing (T96153) __FORCETOC__ ==New title== !! html/php -

                Contents

                +

                Contents

                @@ -16776,7 +16776,7 @@ wgMaxTocLevel=3 == title 2 == === title 2.1 === !! html -

                Contents

                +

                Contents

                • 1 title 1
                    @@ -16812,7 +16812,7 @@ wgMaxTocLevel=3 ====Section 1.1.1.1==== ==Section 2== !! html -

                    Contents

                    +

                    Contents

                    • 1 Section 1
                        @@ -16905,7 +16905,7 @@ __TOC__ === title 1.1 === == title 2 == !! html -

                        Contents

                        +

                        Contents

                        • 1 title 1
                            @@ -16981,7 +16981,7 @@ section 5 !! html/php

                            The tooltips shall not show entities to the user (ie. be double escaped)

                            -

                            Contents

                            +

                            Contents

                            • 1 text > text
                            • 2 text < text
                            • @@ -17057,7 +17057,7 @@ section 6 !! html/php

                              Id should not contain + for spaces

                              -

                              Contents

                              +

                              Contents

                              • 1 Space between Text
                              • 2 Space-Entity between Text
                              • @@ -17133,7 +17133,7 @@ parsoid=wt2html,wt2wt,html2html =''italic'' heading== ==''italic'' heading= !! html/php -

                                Contents

                                +

                                Contents

                                • 1 foo=
                                • 2 =foo
                                • @@ -17168,7 +17168,7 @@ HTML headers vs TOC (T25393) == Header 2.2 == __NOEDITSECTION__ !! html/php -

                                  Contents

                                  +

                                  Contents

                                  • 1 Header 1
                                      @@ -19081,7 +19081,7 @@ Fuzz testing: Parser14 http://__TOC__ !! html/php

                                      onmouseover=[edit]

                                      -http://

                                      Contents

                                      +http://

                                      Contents

                                      @@ -19092,7 +19092,7 @@ http://

                                      Contents

                                      onmouseover=[edit]

                                      http://

                                      -
                                      +

                                      Contents

                                        @@ -21608,7 +21608,7 @@ Out-of-order TOC heading levels =====5===== ==2== !! html -

                                        Contents

                                        +

                                        Contents

                                        • 1 2
                                            @@ -24242,7 +24242,7 @@ title=[[Main Page]] __TOC__ == ''Lost'' episodes == !! html/php -

                                            Contents

                                            +

                                            Contents

                                            @@ -24263,7 +24263,7 @@ title=[[Main Page]] __TOC__ == '''should be bold''' then normal text == !! html/php -

                                            Contents

                                            +

                                            Contents

                                            @@ -24284,7 +24284,7 @@ title=[[Main Page]] __TOC__ == Image [[Image:foobar.jpg]] == !! html/php -

                                            Contents

                                            +

                                            Contents

                                            @@ -24305,7 +24305,7 @@ title=[[Main Page]] __TOC__ ==
                                            Quote
                                            == !! html/php -

                                            Contents

                                            +

                                            Contents

                                            @@ -24316,7 +24316,7 @@ __TOC__ !! html/php+tidy

                                            -
                                            +

                                            Contents

                                              @@ -24346,7 +24346,7 @@ __TOC__ Hanc marginis exiguitas non caperet. QED !! html/php -

                                              Contents

                                              +

                                              Contents

                                              @@ -24371,7 +24371,7 @@ __TOC__ == Foo
                                              Bar
                                              == !! html/php -

                                              Contents

                                              +

                                              Contents

                                              • 1 Foo Bar
                                              • 2 Foo Bar
                                              • @@ -24384,7 +24384,7 @@ __TOC__ !! html/php+tidy

                                                -
                                                +

                                                Contents

                                                  @@ -24418,7 +24418,7 @@ __TOC__ == Evilbye == !! html/php -

                                                  Contents

                                                  +

                                                  Contents

                                                  • 1 Hello
                                                  • 2 b">Evilbye
                                                  • @@ -24449,7 +24449,7 @@ __TOC__ == Attributes after dir on these span tags must be deleted from the TOC == !! html/php -

                                                    Contents

                                                    +

                                                    Contents

                                                    • 1 C++
                                                    • 2 זבנג!
                                                    • @@ -24480,7 +24480,7 @@ T74884: bdi element in ToC __TOC__ == test == !! html/php -

                                                      Contents

                                                      +

                                                      Contents

                                                      @@ -24499,7 +24499,7 @@ T35715: s/strike element in ToC __TOC__ == test test test == !! html/php -

                                                      Contents

                                                      +

                                                      Contents

                                                      @@ -24521,7 +24521,7 @@ Empty

                                                      tag in TOC, removed by Sanitizer (T92892) __TOC__ == x == !! html/php -

                                                      Contents

                                                      +

                                                      Contents

                                                      @@ -24532,7 +24532,7 @@ __TOC__ !! html/php+tidy

                                                      -
                                                      +

                                                      Contents

                                                        @@ -29955,7 +29955,7 @@ wgFragmentMode=[ 'html5', 'legacy' ] [[#啤酒]] [[#%E5%95%A4%E9%85%92]] !! html/php -

                                                        Contents

                                                        +

                                                        Contents

                                                        • 1 Foo bar
                                                        • 2 foo Bar
                                                        • @@ -30021,7 +30021,7 @@ wgFragmentMode=[ 'legacy', 'html5' ] [[#啤酒]] [[#%E5%95%A4%E9%85%92]] !! html/php -

                                                          Contents

                                                          +

                                                          Contents

                                                          • 1 Foo bar
                                                          • 2 foo Bar
                                                          • @@ -30069,7 +30069,7 @@ wgFragmentMode=[ 'html5' ] [[#啤酒]] [[#%E5%95%A4%E9%85%92]] !! html/php -

                                                            Contents

                                                            +

                                                            Contents

                                                            • 1 Foo bar
                                                            • 2 foo Bar
                                                            • diff --git a/tests/phpunit/includes/MWNamespaceTest.php b/tests/phpunit/includes/MWNamespaceTest.php index 498532f76c..91101bd975 100644 --- a/tests/phpunit/includes/MWNamespaceTest.php +++ b/tests/phpunit/includes/MWNamespaceTest.php @@ -7,7 +7,6 @@ /** * Test class for MWNamespace. - * @todo covers tags * @todo FIXME: this test file is a mess */ class MWNamespaceTest extends MediaWikiTestCase { diff --git a/tests/phpunit/includes/StatusTest.php b/tests/phpunit/includes/StatusTest.php index 7e56ebf20b..ae23a4343e 100644 --- a/tests/phpunit/includes/StatusTest.php +++ b/tests/phpunit/includes/StatusTest.php @@ -5,11 +5,6 @@ */ class StatusTest extends MediaWikiLangTestCase { - public function testCanConstruct() { - new Status(); - $this->assertTrue( true ); - } - /** * @dataProvider provideValues * @covers Status::newGood diff --git a/tests/phpunit/includes/TemplateParserTest.php b/tests/phpunit/includes/TemplateParserTest.php index c161f85306..4a803e6374 100644 --- a/tests/phpunit/includes/TemplateParserTest.php +++ b/tests/phpunit/includes/TemplateParserTest.php @@ -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 index 0000000000..69f98bdd00 --- /dev/null +++ b/tests/phpunit/maintenance/BenchmarkerTest.php @@ -0,0 +1,135 @@ +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 () { + } + ] ); + } +} diff --git a/tests/qunit/suites/resources/mediawiki/mediawiki.toc.test.js b/tests/qunit/suites/resources/mediawiki/mediawiki.toc.test.js index b20b68f5d6..6a1b83cf12 100644 --- a/tests/qunit/suites/resources/mediawiki/mediawiki.toc.test.js +++ b/tests/qunit/suites/resources/mediawiki/mediawiki.toc.test.js @@ -12,7 +12,7 @@ assert.strictEqual( $( '.toc' ).length, 0, 'There is no table of contents on the page at the beginning' ); tocHtml = '
                                                              ' + - '
                                                              ' + + '
                                                              ' + '

                                                              Contents

                                                              ' + '
                                                              ' + '
                                                              ' +