mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-30 19:16:39 +00:00
672ca86016
ApiDiscussionToolsPageInfo and ApiDiscussionToolsCompare in direct parsoid or VRS modes tries to fetch HTML using VisualEditor thus stashing the HTML gotten which we don't want, we only need it for viewing in these cases. This seems like something that was/is already happening in RESTBase. So for APIs in DiscussionTools that need the HTML for viewing, just get it from parser cache and not stash it. Bug: T323357 Change-Id: I101c1e84739a2ac1f562f2f7bdc4b8f53d9f3b23
96 lines
3 KiB
PHP
96 lines
3 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
use ApiTestCase;
|
|
use MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo;
|
|
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->setMwGlobals( $config );
|
|
$this->setMwGlobals( [
|
|
'wgArticlePath' => $config['wgArticlePath'],
|
|
'wgNamespaceAliases' => $config['wgNamespaceIds'],
|
|
'wgMetaNamespace' => strtr( $config['wgFormattedNamespaces'][NS_PROJECT], ' ', '_' ),
|
|
'wgMetaNamespaceTalk' => strtr( $config['wgFormattedNamespaces'][NS_PROJECT_TALK], ' ', '_' ),
|
|
// TODO: Move this to $config
|
|
'wgLocaltimezone' => $data['localTimezone'],
|
|
// Data used for the tests assumes there are no variants for English.
|
|
// Language variants are tested using other languages.
|
|
'wgUsePigLatinVariant' => false,
|
|
] );
|
|
$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 );
|
|
|
|
// Optionally write updated content to the JSON files
|
|
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
|
static::overwriteJsonFile( $expectedPath, $threadItemsHtml );
|
|
}
|
|
|
|
static::assertEquals( $expected, $threadItemsHtml, $name );
|
|
}
|
|
|
|
public 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'] );
|
|
}
|
|
|
|
}
|