mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-25 00:38:33 +00:00
Merge "Load site config data in CommentFormatter tests"
This commit is contained in:
commit
81cb4e8fe8
|
@ -9,6 +9,18 @@ use Wikimedia\Parsoid\Utils\DOMUtils;
|
||||||
|
|
||||||
class CommentFormatter {
|
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
|
* Add reply links to some HTML
|
||||||
*
|
*
|
||||||
|
@ -29,7 +41,7 @@ class CommentFormatter {
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parser = CommentParser::newFromGlobalState( $container );
|
$parser = static::getParser( $container );
|
||||||
$threadItems = $parser->getThreadItems();
|
$threadItems = $parser->getThreadItems();
|
||||||
|
|
||||||
foreach ( $threadItems as $threadItem ) {
|
foreach ( $threadItems as $threadItem ) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
||||||
|
|
||||||
use MediaWiki\Extension\DiscussionTools\CommentFormatter;
|
|
||||||
use RequestContext;
|
use RequestContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,8 +24,9 @@ class CommentFormatterTest extends CommentTestCase {
|
||||||
$data = self::getJson( $data );
|
$data = self::getJson( $data );
|
||||||
|
|
||||||
$this->setupEnv( $config, $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 );
|
$doc = self::createDocument( $actual );
|
||||||
$expectedDoc = self::createDocument( $expected );
|
$expectedDoc = self::createDocument( $expected );
|
||||||
|
|
|
@ -105,7 +105,7 @@ abstract class CommentTestCase extends MediaWikiTestCase {
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @return CommentParser
|
* @return CommentParser
|
||||||
*/
|
*/
|
||||||
protected static function createParser( DOMElement $rootNode, array $data ) : CommentParser {
|
public static function createParser( DOMElement $rootNode, array $data ) : CommentParser {
|
||||||
$services = MediaWikiServices::getInstance();
|
$services = MediaWikiServices::getInstance();
|
||||||
return new CommentParser(
|
return new CommentParser(
|
||||||
$rootNode,
|
$rootNode,
|
||||||
|
|
21
tests/phpunit/MockCommentFormatter.php
Normal file
21
tests/phpunit/MockCommentFormatter.php
Normal 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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue