Merge "Load site config data in CommentFormatter tests"

This commit is contained in:
jenkins-bot 2021-01-09 15:39:52 +00:00 committed by Gerrit Code Review
commit 81cb4e8fe8
5 changed files with 212 additions and 179 deletions

View file

@ -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 ) {

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,6 @@
namespace MediaWiki\Extension\DiscussionTools\Tests;
use MediaWiki\Extension\DiscussionTools\CommentFormatter;
use RequestContext;
/**
@ -25,8 +24,9 @@ class CommentFormatterTest extends CommentTestCase {
$data = self::getJson( $data );
$this->setupEnv( $config, $data );
MockCommentFormatter::$data = $data;
$actual = CommentFormatter::addReplyLinks( $dom, RequestContext::getMain()->getLanguage() );
$actual = MockCommentFormatter::addReplyLinks( $dom, RequestContext::getMain()->getLanguage() );
$doc = self::createDocument( $actual );
$expectedDoc = self::createDocument( $expected );

View file

@ -105,7 +105,7 @@ abstract class CommentTestCase extends MediaWikiTestCase {
* @param array $data
* @return CommentParser
*/
protected static function createParser( DOMElement $rootNode, array $data ) : CommentParser {
public static function createParser( DOMElement $rootNode, array $data ) : CommentParser {
$services = MediaWikiServices::getInstance();
return new CommentParser(
$rootNode,

View file

@ -0,0 +1,21 @@
<?php
namespace MediaWiki\Extension\DiscussionTools\Tests;
use DOMElement;
use MediaWiki\Extension\DiscussionTools\CommentFormatter;
use MediaWiki\Extension\DiscussionTools\CommentParser;
class MockCommentFormatter extends CommentFormatter {
public static $data;
/**
* @param DOMElement $container
* @return CommentParser
*/
protected static function getParser( DOMElement $container ) : CommentParser {
return CommentTestCase::createParser( $container, static::$data );
}
}