mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-15 20:10:02 +00:00
0ecc8a4c05
Previously, we required a signature at the end of the comment. This was a pretty rough heuristic that did not correctly handle many comments that we would consider entirely properly signed in CommentParser (e.g. comments wrapped in formatting like <small>…</small>, comments with a post-scriptum or in parentheses, or comments generated by various templates). Now we process the user input using the same code that adds reply links, and only add a signature when we detect that there really isn't a signature (including template-generated), or if the signature is in the wrong place and would result in the reply link showing up in the wrong place as well (not at the end of the comment). Bug: T278442 Bug: T268558 Bug: T278355 Bug: T291421 Bug: T282983 Change-Id: I46b6110af328ebdf93b7dfc2bd941e04391a1599
40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
|
use Title;
|
|
use Wikimedia\Parsoid\Utils\DOMCompat;
|
|
|
|
/**
|
|
* @coversDefaultClass \MediaWiki\Extension\DiscussionTools\CommentUtils
|
|
*
|
|
* @group DiscussionTools
|
|
*/
|
|
class CommentUtilsTest extends IntegrationTestCase {
|
|
/**
|
|
* @dataProvider provideIsSingleCommentSignedBy
|
|
* @covers ::isSingleCommentSignedBy
|
|
*/
|
|
public function testIsSingleCommentSignedBy(
|
|
string $msg, string $title, string $username, string $html, bool $expected
|
|
) {
|
|
$title = Title::newFromText( $title );
|
|
$doc = self::createDocument( $html );
|
|
$body = DOMCompat::getBody( $doc );
|
|
|
|
$config = self::getJson( "../data/enwiki-config.json" );
|
|
$data = self::getJson( "../data/enwiki-data.json" );
|
|
$this->setupEnv( $config, $data );
|
|
$parser = self::createParser( $data );
|
|
|
|
$threadItemSet = $parser->parse( $body, $title );
|
|
$isSigned = CommentUtils::isSingleCommentSignedBy( $threadItemSet, $username, $body );
|
|
self::assertEquals( $expected, $isSigned, $msg );
|
|
}
|
|
|
|
public function provideIsSingleCommentSignedBy(): array {
|
|
return self::getJson( '../cases/isSingleCommentSignedBy.json' );
|
|
}
|
|
}
|