mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-12-24 22:04:51 +00:00
a14474ed76
Tests would fail if your wiki's config was different than this.
Change-Id: I148851a9d7b777f1fad5f17b01b835b0b9384a80
(cherry picked from commit cf9f11167d
)
97 lines
3.1 KiB
PHP
97 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
use ApiTestCase;
|
|
use MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo;
|
|
use MediaWiki\MainConfigNames;
|
|
use MediaWiki\MediaWikiServices;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* @group medium
|
|
* @group Database
|
|
* @covers \MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo
|
|
*/
|
|
class ApiDiscussionToolsPageInfoTest extends ApiTestCase {
|
|
|
|
use TestUtils;
|
|
|
|
/**
|
|
* Setup the MW environment
|
|
*
|
|
* @param array $config
|
|
* @param array $data
|
|
*/
|
|
protected function setupEnv( array $config, array $data ): void {
|
|
$this->overrideConfigValues( [
|
|
MainConfigNames::NamespaceAliases => $config['wgNamespaceIds'],
|
|
MainConfigNames::MetaNamespace => strtr( $config['wgFormattedNamespaces'][NS_PROJECT], ' ', '_' ),
|
|
MainConfigNames::MetaNamespaceTalk =>
|
|
strtr( $config['wgFormattedNamespaces'][NS_PROJECT_TALK], ' ', '_' ),
|
|
// TODO: Move this to $config
|
|
MainConfigNames::Localtimezone => $data['localTimezone'],
|
|
// Data used for the tests assumes there are no variants for English.
|
|
// Language variants are tested using other languages.
|
|
MainConfigNames::UsePigLatinVariant => false,
|
|
MainConfigNames::ArticlePath => '/wiki/$1',
|
|
] + $config );
|
|
$this->setUserLang( $config['wgContentLanguage'] );
|
|
$this->setContentLang( $config['wgContentLanguage'] );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideGetThreadItemsHtml
|
|
*/
|
|
public function testGetThreadItemsHtml(
|
|
string $name, string $title, string $dom, string $expected, string $config, string $data
|
|
): void {
|
|
$dom = static::getHtml( $dom );
|
|
$expectedPath = $expected;
|
|
$expected = static::getJson( $expected );
|
|
$config = static::getJson( $config );
|
|
$data = static::getJson( $data );
|
|
|
|
$doc = static::createDocument( $dom );
|
|
$container = static::getThreadContainer( $doc );
|
|
|
|
$this->setupEnv( $config, $data );
|
|
$title = MediaWikiServices::getInstance()->getTitleParser()->parseTitle( $title );
|
|
$threadItemSet = static::createParser( $data )->parse( $container, $title );
|
|
|
|
$pageInfo = TestingAccessWrapper::newFromClass( ApiDiscussionToolsPageInfo::class );
|
|
|
|
$threadItemsHtml = $pageInfo->getThreadItemsHtml( $threadItemSet, false );
|
|
|
|
// Optionally write updated content to the JSON files
|
|
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
|
static::overwriteJsonFile( $expectedPath, $threadItemsHtml );
|
|
}
|
|
|
|
static::assertEquals( $expected, $threadItemsHtml, $name );
|
|
}
|
|
|
|
public static function provideGetThreadItemsHtml(): array {
|
|
return static::getJson( '../cases/threaditemshtml.json' );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo::execute
|
|
*/
|
|
public function testExecuteApiDiscussionToolsPageInfo() {
|
|
$page = $this->getNonexistingTestPage( __METHOD__ );
|
|
$this->editPage( $page, 'add DT pageinfo content' );
|
|
|
|
$params = [
|
|
'action' => 'discussiontoolspageinfo',
|
|
'page' => $page->getTitle()->getText(),
|
|
];
|
|
|
|
$result = $this->doApiRequestWithToken( $params );
|
|
|
|
$this->assertNotEmpty( $result[0]['discussiontoolspageinfo'] );
|
|
$this->assertArrayHasKey( 'transcludedfrom', $result[0]['discussiontoolspageinfo'] );
|
|
}
|
|
|
|
}
|