2022-02-04 21:58:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
|
2022-11-29 18:35:04 +00:00
|
|
|
use GlobalVarConfig;
|
2022-02-04 21:58:20 +00:00
|
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
2022-02-21 22:07:38 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2022-02-04 21:58:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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-02-04 21:58:20 +00:00
|
|
|
$this->setupEnv( $config, $data );
|
2022-02-21 22:07:38 +00:00
|
|
|
$title = MediaWikiServices::getInstance()->getTitleParser()->parseTitle( $title );
|
2022-06-09 13:51:33 +00:00
|
|
|
$parser = static::createParser( $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
|
|
|
}
|
|
|
|
|
|
|
|
public 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 )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideGetTitleFromUrl() {
|
|
|
|
// 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
|
|
|
}
|