mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-18 02:51:26 +00:00
7017acaf1d
Change-Id: Idb44d7890b05e0d9d90fdabe46f295b80996f60c
67 lines
2.4 KiB
PHP
67 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
use GlobalVarConfig;
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* @group DiscussionTools
|
|
* @covers \MediaWiki\Extension\DiscussionTools\CommentUtils
|
|
*/
|
|
class CommentUtilsTest extends IntegrationTestCase {
|
|
/**
|
|
* @dataProvider provideIsSingleCommentSignedBy
|
|
*/
|
|
public function testIsSingleCommentSignedBy(
|
|
string $msg, string $title, string $username, string $html, bool $expected
|
|
) {
|
|
$doc = static::createDocument( $html );
|
|
$container = static::getThreadContainer( $doc );
|
|
|
|
$config = static::getJson( "../data/enwiki-config.json" );
|
|
$data = static::getJson( "../data/enwiki-data.json" );
|
|
$this->setupEnv( $config, $data );
|
|
$title = MediaWikiServices::getInstance()->getTitleParser()->parseTitle( $title );
|
|
$parser = static::createParser( $data );
|
|
|
|
$threadItemSet = $parser->parse( $container, $title );
|
|
$isSigned = CommentUtils::isSingleCommentSignedBy( $threadItemSet, $username, $container );
|
|
static::assertEquals( $expected, $isSigned, $msg );
|
|
}
|
|
|
|
public function provideIsSingleCommentSignedBy(): array {
|
|
return static::getJson( '../cases/isSingleCommentSignedBy.json' );
|
|
}
|
|
|
|
/**
|
|
* @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 ];
|
|
}
|
|
}
|