2022-06-07 15:09:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
|
|
|
|
use MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo;
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group medium
|
|
|
|
*
|
|
|
|
* @covers \MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo
|
|
|
|
*/
|
|
|
|
class ApiDiscussionToolsPageInfoTest extends IntegrationTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideGetThreadItemsHtml
|
|
|
|
* @covers \MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo::getThreadItemsHtml
|
|
|
|
*/
|
|
|
|
public function testGetThreadItemsHtml(
|
|
|
|
string $name, string $title, string $dom, string $expected, string $config, string $data
|
|
|
|
): void {
|
2022-06-14 21:53:00 +00:00
|
|
|
$dom = static::getHtml( $dom );
|
2022-06-07 15:09:04 +00:00
|
|
|
$expectedPath = $expected;
|
2022-06-14 21:53:00 +00:00
|
|
|
$expected = static::getJson( $expected );
|
|
|
|
$config = static::getJson( $config );
|
|
|
|
$data = static::getJson( $data );
|
2022-06-07 15:09:04 +00:00
|
|
|
|
2022-06-14 21:53:00 +00:00
|
|
|
$doc = static::createDocument( $dom );
|
|
|
|
$container = static::getThreadContainer( $doc );
|
2022-06-07 15:09:04 +00:00
|
|
|
|
|
|
|
$this->setupEnv( $config, $data );
|
|
|
|
$title = MediaWikiServices::getInstance()->getTitleParser()->parseTitle( $title );
|
2022-06-14 21:53:00 +00:00
|
|
|
$threadItemSet = static::createParser( $data )->parse( $container, $title );
|
2022-06-07 15:09:04 +00:00
|
|
|
|
|
|
|
$pageInfo = TestingAccessWrapper::newFromClass( ApiDiscussionToolsPageInfo::class );
|
|
|
|
|
|
|
|
$threadItemsHtml = $pageInfo->getThreadItemsHtml( $threadItemSet );
|
|
|
|
|
|
|
|
// Optionally write updated content to the JSON files
|
|
|
|
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
2022-06-14 21:53:00 +00:00
|
|
|
static::overwriteJsonFile( $expectedPath, $threadItemsHtml );
|
2022-06-07 15:09:04 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 21:53:00 +00:00
|
|
|
static::assertEquals( $expected, $threadItemsHtml, $name );
|
2022-06-07 15:09:04 +00:00
|
|
|
|
|
|
|
$processedThreads = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideGetThreadItemsHtml(): array {
|
2022-06-14 21:53:00 +00:00
|
|
|
return static::getJson( '../cases/threaditemshtml.json' );
|
2022-06-07 15:09:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|