| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\DiscussionTools\Tests; |
| 4 |
|
| 5 |
use MediaWiki\Extension\DiscussionTools\ApiDiscussionToolsPageInfo; |
| 6 |
use MediaWiki\Tests\Api\ApiTestCase; |
| 7 |
use Wikimedia\TestingAccessWrapper; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class ApiDiscussionToolsPageInfoTest extends ApiTestCase { |
| 15 |
|
| 16 |
use TestUtils; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function testGetThreadItemsHtml( |
| 22 |
string $name, string $title, string $dom, string $expected, string $config, string $data |
| 23 |
): void { |
| 24 |
$dom = static::getHtml( $dom ); |
| 25 |
$expectedPath = $expected; |
| 26 |
$expected = static::getJson( $expected ); |
| 27 |
$config = static::getJson( $config ); |
| 28 |
$data = static::getJson( $data ); |
| 29 |
|
| 30 |
$doc = static::createDocument( $dom ); |
| 31 |
$container = static::getThreadContainer( $doc ); |
| 32 |
|
| 33 |
$title = $this->getServiceContainer()->getTitleParser()->parseTitle( $title ); |
| 34 |
$threadItemSet = $this->createParser( $config, $data )->parse( $container, $title ); |
| 35 |
|
| 36 |
$pageInfo = TestingAccessWrapper::newFromClass( ApiDiscussionToolsPageInfo::class ); |
| 37 |
|
| 38 |
$threadItemsHtml = $pageInfo->getThreadItemsHtml( $threadItemSet, false ); |
| 39 |
|
| 40 |
|
| 41 |
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) { |
| 42 |
static::overwriteJsonFile( $expectedPath, $threadItemsHtml ); |
| 43 |
} |
| 44 |
|
| 45 |
static::assertEquals( $expected, $threadItemsHtml, $name ); |
| 46 |
} |
| 47 |
|
| 48 |
public static function provideGetThreadItemsHtml(): array { |
| 49 |
return static::getJson( '../cases/threaditemshtml.json' ); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function testExecuteApiDiscussionToolsPageInfo() { |
| 56 |
$page = $this->getNonexistingTestPage( __METHOD__ ); |
| 57 |
$this->editPage( $page, 'add DT pageinfo content' ); |
| 58 |
|
| 59 |
$params = [ |
| 60 |
'action' => 'discussiontoolspageinfo', |
| 61 |
'page' => $page->getTitle()->getText(), |
| 62 |
]; |
| 63 |
|
| 64 |
$result = $this->doApiRequestWithToken( $params ); |
| 65 |
|
| 66 |
$this->assertNotEmpty( $result[0]['discussiontoolspageinfo'] ); |
| 67 |
$this->assertArrayHasKey( 'transcludedfrom', $result[0]['discussiontoolspageinfo'] ); |
| 68 |
} |
| 69 |
|
| 70 |
} |