2020-10-19 20:59:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
|
2021-01-06 17:06:27 +00:00
|
|
|
use RequestContext;
|
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-01-29 18:31:27 +00:00
|
|
|
* @dataProvider provideAddReplyLinksInternal
|
|
|
|
* @covers ::addReplyLinksInternal
|
2020-10-19 20:59:55 +00:00
|
|
|
*/
|
2021-01-29 18:31:27 +00:00
|
|
|
public function testAddReplyLinksInternal(
|
2020-10-19 20:59:55 +00:00
|
|
|
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 );
|
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 );
|
|
|
|
|
|
|
|
$actual = $commentFormatter->addReplyLinksInternal( $dom, RequestContext::getMain()->getLanguage() );
|
2021-01-06 17:06:27 +00:00
|
|
|
|
|
|
|
$doc = self::createDocument( $actual );
|
2020-10-19 20:59:55 +00:00
|
|
|
$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 );
|
|
|
|
}
|
|
|
|
|
2021-01-29 18:31:27 +00:00
|
|
|
public function provideAddReplyLinksInternal() : array {
|
2020-10-19 20:59:55 +00:00
|
|
|
return self::getJson( '../cases/formattedreply.json' );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|