Jdlrobson has uploaded a new change for review. https://gerrit.wikimedia.org/r/277313
Change subject: WIP: Mobile Formatter PHPUnit tests ...................................................................... WIP: Mobile Formatter PHPUnit tests * Rename provider to have provider prefix for clarity * Copy over some test cases by our own phuedx from https://github.com/phuedx/mobile-formatter * Update tests to use in-block (not sure why these were not reporting as failing) Change-Id: I9b8edc6dca8da181b535c85e05e64788007a38f4 --- M tests/phpunit/MobileFormatterTest.php 1 file changed, 89 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend refs/changes/13/277313/1 diff --git a/tests/phpunit/MobileFormatterTest.php b/tests/phpunit/MobileFormatterTest.php index 5372e37..effe746 100644 --- a/tests/phpunit/MobileFormatterTest.php +++ b/tests/phpunit/MobileFormatterTest.php @@ -5,11 +5,12 @@ */ class MobileFormatterTest extends MediaWikiTestCase { /** - * @dataProvider getHtmlData + * @dataProvider provideHtmlTransform * * @param $input * @param $expected * @param callable|bool $callback + * @covers MobileFormatter::filterContent */ public function testHtmlTransform( $input, $expected, $callback = false ) { $t = Title::newFromText( 'Mobile' ); @@ -23,11 +24,12 @@ $this->assertEquals( str_replace( "\n", '', $expected ), str_replace( "\n", '', $html ) ); } - public function getHtmlData() { + public function provideHtmlTransform() { $enableSections = function ( MobileFormatter $mf ) { $mf->enableExpandableSections(); }; $longLine = "\n" . str_repeat( 'A', 5000 ); + $longLine = "\nA"; $removeImages = function( MobileFormatter $f ) { $f->setRemoveMedia(); }; @@ -62,7 +64,7 @@ . '<a class="edit-page" href="#editor/2">Edit</a></h2>' . $longLine, '<div class="mf-section-0"></div>' - . '<h2><span class="mw-headline" id="Forty-niners">Forty-niners</span>' + . '<h2 class="in-block"><span class="mw-headline" id="Forty-niners">Forty-niners</span>' . '<a class="edit-page" href="#editor/2">Edit</a></h2>' . '<div class="mf-section-1">' . $longLine . '</div>', $enableSections @@ -74,7 +76,7 @@ . '<h4><span>h4</span></h4>' . 'h4 text.', '<div class="mf-section-0"></div>' - . '<h3><span>h3</span></h3>' + . '<h3 class="in-block"><span>h3</span></h3>' . '<div class="mf-section-1">' . $longLine . '<h4 class="in-block"><span>h4</span></h4>' @@ -87,7 +89,7 @@ '<h6><span>h6</span></h6>' . $longLine, '<div class="mf-section-0"></div>' - . '<h6><span>h6</span></h6>' + . '<h6 class="in-block"><span>h6</span></h6>' . '<div class="mf-section-1">' . $longLine . '</div>', $enableSections ), @@ -96,7 +98,7 @@ '<h2><span class="mw-headline" id="History"><span id="Overview"></span>' . 'History</span><a class="edit-page" href="#editor/2">Edit</a></h2>' . $longLine, - '<div class="mf-section-0"></div><h2>' . + '<div class="mf-section-0"></div><h2 class="in-block">' . '<span class="mw-headline" id="History"><span id="Overview"></span>' . 'History</span><a class="edit-page" href="#editor/2">Edit</a></h2>' . '<div class="mf-section-1">' . $longLine . '</div>', @@ -154,4 +156,85 @@ ), ); } + + /** + * @dataProvider provideHeadingTransform + * @covers MobileFormatter::makeSections + * @covers MobileFormatter::enableExpandableSections + * @covers MobileFormatter::setTopHeadingTags + * @covers MobileFormatter::filterContent + */ + public function testHeadingTransform( array $topHeadingTags, $input, $expectedOutput ) { + $t = Title::newFromText( 'Mobile' ); + $formatter = new MobileFormatter( $input, $t ); + + // If MobileFormatter#enableExpandableSections isn't called, then headings + // won't be transformed. + $formatter->enableExpandableSections( true ); + + $formatter->topHeadingTags = $topHeadingTags; + $formatter->filterContent(); + + $this->assertEquals( $expectedOutput, $formatter->getText() ); + } + + public function provideHeadingTransform() { + return array( + + // The "in-block" class is added to a subheading. + array( + array( 'h1', 'h2' ), + '<h1>Foo</h1><h2>Bar</h2>', + '<div class="mf-section-0"></div><h1>Foo</h1><div class="mf-section-1"><h2 class="in-block">Bar</h2></div>', + ), + + // The "in-block" class is added to a subheading + // without overwriting the existing attribute. + array( + array( 'h1', 'h2' ), + '<h1>Foo</h1><h2 class="baz">Bar</h2>', + '<div class="mf-section-0"></div><h1>Foo</h1><div class="mf-section-1"><h2 class="baz in-block">Bar</h2></div>', + ), + + // The "in-block" class is added to all subheadings. + array( + array( 'h1', 'h2', 'h3' ), + '<h1>Foo</h1><h2>Bar</h2><h3>Qux</h3>', + '<div class="mf-section-0"></div><h1>Foo</h1><div class="mf-section-1"><h2 class="in-block">Bar</h2><h3 class="in-block">Qux</h3></div>', + ), + + // The first heading found is the highest ranked + // subheading. + array( + array( 'h1', 'h2', 'h3' ), + '<h2>Bar</h2><h3>Qux</h3>', + '<div class="mf-section-0"></div><h2>Bar</h2><div class="mf-section-1"><h3 class="in-block">Qux</h3></div>', + ), + + // Unenclosed text is appended to the expandable container. + array( + array( 'h1', 'h2' ), + '<h1>Foo</h1><h2>Bar</h2>A', + '<div class="mf-section-0"></div><h1>Foo</h1><div class="mf-section-1"><h2 class="in-block">Bar</h2>A</div>', + ), + + // Unencloded text that appears before the first + // heading is appended to a container. + // + // FIXME: This behaviour was included for backwards + // compatibility but mightn't be necessary. + array( + array( 'h1', 'h2' ), + 'A<h1>Foo</h1><h2>Bar</h2>', + '<div class="mf-section-0"><p>A</p></div><h1>Foo</h1><div class="mf-section-1"><h2 class="in-block">Bar</h2></div>', + ), + + // Multiple headings are handled identically. + array( + array( 'h1', 'h2' ), + '<h1>Foo</h1><h2>Bar</h2>Baz<h1>Qux</h1>Quux', + '<div class="mf-section-0"></div><h1>Foo</h1><div class="mf-section-1"><h2 class="in-block">Bar</h2>Baz</div><h1>Qux</h1><div class="mf-section-2">Quux</div>', + ), + ); + } } -- To view, visit https://gerrit.wikimedia.org/r/277313 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9b8edc6dca8da181b535c85e05e64788007a38f4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Jdlrobson <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
