mediawiki-extensions-Discus.../tests/phpunit/CommentFormatterTest.php
Ed Sanders 34011b7a07 Parser: Pass in title of page being parsed
Will be used to parse selflinks in the future.

Change-Id: I2bc29d1c5c69cb6309f582f162f9af7d96ce8913
2022-01-12 21:17:59 +00:00

59 lines
1.7 KiB
PHP

<?php
namespace MediaWiki\Extension\DiscussionTools\Tests;
use MediaWiki\MediaWikiServices;
use Title;
use Wikimedia\TestingAccessWrapper;
/**
* @coversDefaultClass \MediaWiki\Extension\DiscussionTools\CommentFormatter
*/
class CommentFormatterTest extends IntegrationTestCase {
/**
* @dataProvider provideAddDiscussionToolsInternal
* @covers ::addDiscussionToolsInternal
*/
public function testAddDiscussionToolsInternal(
string $name, string $title, string $dom, string $expected, string $config, string $data
): void {
$title = Title::newFromText( $title );
$dom = self::getHtml( $dom );
$expectedPath = $expected;
$expected = self::getText( $expected );
$config = self::getJson( $config );
$data = self::getJson( $data );
$this->setupEnv( $config, $data );
MockCommentFormatter::$data = $data;
$commentFormatter = TestingAccessWrapper::newFromClass( MockCommentFormatter::class );
$actual = $commentFormatter->addDiscussionToolsInternal( $dom, $title );
$mockSubStore = new MockSubscriptionStore();
$qqxLang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'qqx' );
$actual = MockCommentFormatter::postprocessTopicSubscription(
$actual, $qqxLang, $mockSubStore, self::getTestUser()->getUser()
);
$actual = MockCommentFormatter::postprocessReplyTool(
$actual, $qqxLang
);
// Optionally write updated content to the "reply HTML" files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteTextFile( $expectedPath, $actual );
}
self::assertEquals( $expected, $actual, $name );
}
public function provideAddDiscussionToolsInternal(): array {
return self::getJson( '../cases/formattedreply.json' );
}
}