2020-10-19 20:59:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
|
2021-06-02 19:42:45 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2022-01-11 15:50:44 +00:00
|
|
|
use Title;
|
2021-01-29 18:31:27 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
2020-10-19 20:59:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \MediaWiki\Extension\DiscussionTools\CommentFormatter
|
|
|
|
*/
|
2021-02-02 14:12:51 +00:00
|
|
|
class CommentFormatterTest extends IntegrationTestCase {
|
2020-10-19 20:59:55 +00:00
|
|
|
|
|
|
|
/**
|
2021-04-19 18:34:55 +00:00
|
|
|
* @dataProvider provideAddDiscussionToolsInternal
|
|
|
|
* @covers ::addDiscussionToolsInternal
|
2020-10-19 20:59:55 +00:00
|
|
|
*/
|
2021-04-19 18:34:55 +00:00
|
|
|
public function testAddDiscussionToolsInternal(
|
2022-01-11 15:45:55 +00:00
|
|
|
string $name, string $title, string $dom, string $expected, string $config, string $data
|
2021-07-22 07:25:13 +00:00
|
|
|
): void {
|
2022-01-11 15:50:44 +00:00
|
|
|
$title = Title::newFromText( $title );
|
2020-10-19 20:59:55 +00:00
|
|
|
$dom = self::getHtml( $dom );
|
|
|
|
$expectedPath = $expected;
|
2021-02-27 00:15:42 +00:00
|
|
|
$expected = self::getText( $expected );
|
2020-10-19 20:59:55 +00:00
|
|
|
$config = self::getJson( $config );
|
|
|
|
$data = self::getJson( $data );
|
|
|
|
|
|
|
|
$this->setupEnv( $config, $data );
|
2021-01-08 22:19:20 +00:00
|
|
|
MockCommentFormatter::$data = $data;
|
2020-10-19 20:59:55 +00:00
|
|
|
|
2021-01-29 18:31:27 +00:00
|
|
|
$commentFormatter = TestingAccessWrapper::newFromClass( MockCommentFormatter::class );
|
|
|
|
|
2022-01-11 15:50:44 +00:00
|
|
|
$actual = $commentFormatter->addDiscussionToolsInternal( $dom, $title );
|
2021-01-06 17:06:27 +00:00
|
|
|
|
2021-04-19 19:42:53 +00:00
|
|
|
$mockSubStore = new MockSubscriptionStore();
|
2021-06-02 19:42:45 +00:00
|
|
|
$qqxLang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'qqx' );
|
|
|
|
|
2021-04-19 19:42:53 +00:00
|
|
|
$actual = MockCommentFormatter::postprocessTopicSubscription(
|
2021-06-02 19:42:45 +00:00
|
|
|
$actual, $qqxLang, $mockSubStore, self::getTestUser()->getUser()
|
2021-04-19 19:42:53 +00:00
|
|
|
);
|
|
|
|
|
2021-04-15 21:09:55 +00:00
|
|
|
$actual = MockCommentFormatter::postprocessReplyTool(
|
2021-06-02 19:42:45 +00:00
|
|
|
$actual, $qqxLang
|
2021-04-15 21:09:55 +00:00
|
|
|
);
|
|
|
|
|
2020-10-19 20:59:55 +00:00
|
|
|
// Optionally write updated content to the "reply HTML" files
|
|
|
|
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
2021-02-27 00:15:42 +00:00
|
|
|
self::overwriteTextFile( $expectedPath, $actual );
|
2020-10-19 20:59:55 +00:00
|
|
|
}
|
|
|
|
|
2021-02-27 00:15:42 +00:00
|
|
|
self::assertEquals( $expected, $actual, $name );
|
2020-10-19 20:59:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 07:25:13 +00:00
|
|
|
public function provideAddDiscussionToolsInternal(): array {
|
2020-10-19 20:59:55 +00:00
|
|
|
return self::getJson( '../cases/formattedreply.json' );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|