Merge "Set relevant title on Special:RecentChangesLinked"
[lhc/web/wiklou.git] / tests / phpunit / includes / HtmlFormatterTest.php
index 10ccc4f..9dbfa45 100644 (file)
@@ -6,7 +6,11 @@
 class HtmlFormatterTest extends MediaWikiTestCase {
        /**
         * @dataProvider getHtmlData
-        * @covers HtmlFormatter::getText
+        *
+        * @param string $input
+        * @param string $expectedText
+        * @param array $expectedRemoved
+        * @param callable|bool $callback
         */
        public function testTransform( $input, $expectedText,
                $expectedRemoved = array(), $callback = false
@@ -36,16 +40,16 @@ class HtmlFormatterTest extends MediaWikiTestCase {
        }
 
        public function getHtmlData() {
-               $removeImages = function( HtmlFormatter $f ) {
+               $removeImages = function ( HtmlFormatter $f ) {
                        $f->setRemoveMedia();
                };
-               $removeTags = function( HtmlFormatter $f ) {
+               $removeTags = function ( HtmlFormatter $f ) {
                        $f->remove( array( 'table', '.foo', '#bar', 'div.baz' ) );
                };
-               $flattenSomeStuff = function( HtmlFormatter $f ) {
+               $flattenSomeStuff = function ( HtmlFormatter $f ) {
                        $f->flatten( array( 's', 'div' ) );
                };
-               $flattenEverything = function( HtmlFormatter $f ) {
+               $flattenEverything = function ( HtmlFormatter $f ) {
                        $f->flattenAllTags();
                };
                return array(
@@ -93,6 +97,8 @@ class HtmlFormatterTest extends MediaWikiTestCase {
                        array(
                                '<span title="&quot; \' &amp;">&lt;Тест!&gt;</span> &amp;&lt;&#38;&#0038;&#x26;&#x026;',
                                '<span title="&quot; \' &amp;">&lt;Тест!&gt;</span> &amp;&lt;&amp;&amp;&amp;&amp;',
+                               array(),
+                               $removeTags, // Have some rules to trigger a DOM parse
                        ),
                        // https://bugzilla.wikimedia.org/show_bug.cgi?id=53086
                        array(
@@ -103,4 +109,19 @@ class HtmlFormatterTest extends MediaWikiTestCase {
                        ),
                );
        }
+
+       public function testQuickProcessing() {
+               $f = new MockHtmlFormatter( 'foo' );
+               $f->filterContent();
+               $this->assertFalse( $f->hasDoc, 'HtmlFormatter should not needlessly parse HTML' );
+       }
+}
+
+class MockHtmlFormatter extends HtmlFormatter {
+       public $hasDoc = false;
+
+       public function getDoc() {
+               $this->hasDoc = true;
+               return parent::getDoc();
+       }
 }