mediawiki-extensions-Discus.../tests/phpunit/CommentFormatterTest.php
Ed Sanders 8b71a2b5dc Load site config data in CommentFormatter tests
This fixes missing reply links in arwiki test output.

Change-Id: I24d3b8371a8343c4445c716fadf0692be0924eed
2021-01-08 23:03:33 +00:00

48 lines
1.3 KiB
PHP

<?php
namespace MediaWiki\Extension\DiscussionTools\Tests;
use RequestContext;
/**
* @coversDefaultClass \MediaWiki\Extension\DiscussionTools\CommentFormatter
*/
class CommentFormatterTest extends CommentTestCase {
/**
* @dataProvider provideAddReplyLinks
* @covers ::addReplyLinks
*/
public function testAddReplyLinks(
string $name, string $dom, string $expected, string $config, string $data
) : void {
$origPath = $dom;
$dom = self::getHtml( $dom );
$expectedPath = $expected;
$expected = self::getHtml( $expected );
$config = self::getJson( $config );
$data = self::getJson( $data );
$this->setupEnv( $config, $data );
MockCommentFormatter::$data = $data;
$actual = MockCommentFormatter::addReplyLinks( $dom, RequestContext::getMain()->getLanguage() );
$doc = self::createDocument( $actual );
$expectedDoc = self::createDocument( $expected );
// Optionally write updated content to the "reply HTML" files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteHtmlFile( $expectedPath, $doc, $origPath );
}
// saveHtml is not dirty-diff safe, but for testing it is probably faster than DOMCompat::getOuterHTML
self::assertEquals( $expectedDoc->saveHtml(), $doc->saveHtml(), $name );
}
public function provideAddReplyLinks() : array {
return self::getJson( '../cases/formattedreply.json' );
}
}