From 8b71a2b5dc3fcbc1c4499ff05d216cae23d91592 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 8 Jan 2021 22:19:20 +0000 Subject: [PATCH] Load site config data in CommentFormatter tests This fixes missing reply links in arwiki test output. Change-Id: I24d3b8371a8343c4445c716fadf0692be0924eed --- includes/CommentFormatter.php | 14 +- ...no-paragraph-oldparser-formattedreply.html | 350 +++++++++--------- tests/phpunit/CommentFormatterTest.php | 4 +- tests/phpunit/CommentTestCase.php | 2 +- tests/phpunit/MockCommentFormatter.php | 21 ++ 5 files changed, 212 insertions(+), 179 deletions(-) create mode 100644 tests/phpunit/MockCommentFormatter.php diff --git a/includes/CommentFormatter.php b/includes/CommentFormatter.php index 85713068c..4e6fa0f25 100644 --- a/includes/CommentFormatter.php +++ b/includes/CommentFormatter.php @@ -9,6 +9,18 @@ use Wikimedia\Parsoid\Utils\DOMUtils; class CommentFormatter { + /** + * Get a comment parser object for a DOM element + * + * This method exists so it can mocked in tests. + * + * @param DOMElement $container + * @return CommentParser + */ + protected static function getParser( DOMElement $container ) : CommentParser { + return CommentParser::newFromGlobalState( $container ); + } + /** * Add reply links to some HTML * @@ -29,7 +41,7 @@ class CommentFormatter { return $html; } - $parser = CommentParser::newFromGlobalState( $container ); + $parser = static::getParser( $container ); $threadItems = $parser->getThreadItems(); foreach ( $threadItems as $threadItem ) { diff --git a/tests/cases/ar-no-paragraph-oldparser/ar-no-paragraph-oldparser-formattedreply.html b/tests/cases/ar-no-paragraph-oldparser/ar-no-paragraph-oldparser-formattedreply.html index f67df337d..99981af54 100644 --- a/tests/cases/ar-no-paragraph-oldparser/ar-no-paragraph-oldparser-formattedreply.html +++ b/tests/cases/ar-no-paragraph-oldparser/ar-no-paragraph-oldparser-formattedreply.html @@ -1,5 +1,5 @@ -