2022-02-04 21:58:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
|
2023-12-11 15:38:02 +00:00
|
|
|
use MediaWiki\Config\GlobalVarConfig;
|
2022-02-04 21:58:20 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DiscussionTools
|
2022-09-15 12:08:30 +00:00
|
|
|
* @covers \MediaWiki\Extension\DiscussionTools\CommentUtils
|
2022-02-04 21:58:20 +00:00
|
|
|
*/
|
|
|
|
class CommentUtilsTest extends IntegrationTestCase {
|
|
|
|
/**
|
|
|
|
* @dataProvider provideIsSingleCommentSignedBy
|
|
|
|
*/
|
|
|
|
public function testIsSingleCommentSignedBy(
|
|
|
|
string $msg, string $title, string $username, string $html, bool $expected
|
|
|
|
) {
|
2022-06-09 13:51:33 +00:00
|
|
|
$doc = static::createDocument( $html );
|
|
|
|
$container = static::getThreadContainer( $doc );
|
2022-02-04 21:58:20 +00:00
|
|
|
|
2022-06-09 13:51:33 +00:00
|
|
|
$config = static::getJson( "../data/enwiki-config.json" );
|
|
|
|
$data = static::getJson( "../data/enwiki-data.json" );
|
2022-03-11 23:42:25 +00:00
|
|
|
$title = $this->createTitleParser( $config )->parseTitle( $title );
|
|
|
|
$parser = $this->createParser( $config, $data );
|
2022-02-04 21:58:20 +00:00
|
|
|
|
2022-03-09 19:32:51 +00:00
|
|
|
$threadItemSet = $parser->parse( $container, $title );
|
|
|
|
$isSigned = CommentUtils::isSingleCommentSignedBy( $threadItemSet, $username, $container );
|
2022-06-09 13:51:33 +00:00
|
|
|
static::assertEquals( $expected, $isSigned, $msg );
|
2022-02-04 21:58:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 13:57:13 +00:00
|
|
|
public static function provideIsSingleCommentSignedBy(): array {
|
2022-06-09 13:51:33 +00:00
|
|
|
return static::getJson( '../cases/isSingleCommentSignedBy.json' );
|
2022-02-04 21:58:20 +00:00
|
|
|
}
|
2022-11-29 18:35:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\DiscussionTools\CommentUtils::getTitleFromUrl
|
|
|
|
* @dataProvider provideGetTitleFromUrl
|
|
|
|
*/
|
|
|
|
public function testGetTitleFromUrl( $expected, $input, $config ) {
|
|
|
|
static::assertEquals(
|
|
|
|
$expected,
|
|
|
|
CommentUtils::getTitleFromUrl( $input, $config )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-05-20 13:57:13 +00:00
|
|
|
public static function provideGetTitleFromUrl() {
|
2022-11-29 18:35:04 +00:00
|
|
|
// TODO: Test with different configs.
|
|
|
|
$config = new GlobalVarConfig();
|
|
|
|
$GLOBALS['wgArticlePath'] = '/wiki/$1';
|
|
|
|
|
|
|
|
yield 'null-string' => [ null, 'Foo', $config ];
|
|
|
|
yield 'null-path' => [ null, 'path/Foo', $config ];
|
|
|
|
yield 'null-wiki-path' => [ null, 'wiki/Foo', $config ];
|
|
|
|
yield 'simple-path' => [ 'Foo', 'site/wiki/Foo', $config ];
|
|
|
|
yield 'simple-cgi' => [ 'Foo', 'site/w/index.php?title=Foo', $config ];
|
|
|
|
yield 'viewing-path' => [ 'Foo', 'site/wiki/Foo?action=view', $config ];
|
|
|
|
yield 'viewing-cgi' => [ 'Foo', 'site/w/index.php?title=Foo&action=view', $config ];
|
|
|
|
yield 'editing-path' => [ 'Foo', 'site/wiki/Foo?action=edit', $config ];
|
|
|
|
yield 'editing-cgi' => [ 'Foo', 'site/w/index.php?title=Foo&action=edit', $config ];
|
|
|
|
|
|
|
|
yield 'repeated question-mark' => [ 'Foo', 'site/wiki/Foo?Gosh?This?Path?Is?Bad', $config ];
|
|
|
|
}
|
2022-02-04 21:58:20 +00:00
|
|
|
}
|