mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-18 11:02:57 +00:00
70022c4cee
Instead of setting global configuration variables, we create a custom config object and all the other dependencies and pass them to the CommentParser instead of the defaults. Depends-On: I8d374b51511a2873dce646aa453c5e0e2c076a14 Change-Id: I9dfccc833d3e2695cf1d1f7bbee4b68eae9a8c25
65 lines
2.3 KiB
PHP
65 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
use MediaWiki\Config\GlobalVarConfig;
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
|
|
|
/**
|
|
* @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" );
|
|
$title = $this->createTitleParser( $config )->parseTitle( $title );
|
|
$parser = $this->createParser( $config, $data );
|
|
|
|
$threadItemSet = $parser->parse( $container, $title );
|
|
$isSigned = CommentUtils::isSingleCommentSignedBy( $threadItemSet, $username, $container );
|
|
static::assertEquals( $expected, $isSigned, $msg );
|
|
}
|
|
|
|
public static 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 static 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 ];
|
|
}
|
|
}
|