Merge "Add some tests covering ThreadItem::getHTML() and related methods"

This commit is contained in:
jenkins-bot 2021-09-13 16:12:55 +00:00 committed by Gerrit Code Review
commit 8581e4d3d7
15 changed files with 6970 additions and 0 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

44
tests/cases/getHTML.json Normal file
View file

@ -0,0 +1,44 @@
[
{
"name": "plwiki oldparser",
"dom": "cases/pl-big-oldparser/pl-big-oldparser.html",
"expected": "../cases/pl-big-oldparser/pl-big-oldparser-getHTML.json",
"config": "../data/plwiki-config.json",
"data": "../data/plwiki-data.json"
},
{
"name": "plwiki parsoid",
"dom": "cases/pl-big-parsoid/pl-big-parsoid.html",
"expected": "../cases/pl-big-parsoid/pl-big-parsoid-getHTML.json",
"config": "../data/plwiki-config.json",
"data": "../data/plwiki-data.json"
},
{
"name": "enwiki oldparser",
"dom": "cases/en-big-oldparser/en-big-oldparser.html",
"expected": "../cases/en-big-oldparser/en-big-oldparser-getHTML.json",
"config": "../data/enwiki-config.json",
"data": "../data/enwiki-data.json"
},
{
"name": "enwiki parsoid",
"dom": "cases/en-big-parsoid/en-big-parsoid.html",
"expected": "../cases/en-big-parsoid/en-big-parsoid-getHTML.json",
"config": "../data/enwiki-config.json",
"data": "../data/enwiki-data.json"
},
{
"name": "ckbwiki oldparser",
"dom": "cases/ckb-big-oldparser/ckb-big-oldparser.html",
"expected": "../cases/ckb-big-oldparser/ckb-big-oldparser-getHTML.json",
"config": "../data/ckbwiki-config.json",
"data": "../data/ckbwiki-data.json"
},
{
"name": "ckbwiki parsoid",
"dom": "cases/ckb-big-parsoid/ckb-big-parsoid.html",
"expected": "../cases/ckb-big-parsoid/ckb-big-parsoid-getHTML.json",
"config": "../data/ckbwiki-config.json",
"data": "../data/ckbwiki-data.json"
}
]

44
tests/cases/getText.json Normal file
View file

@ -0,0 +1,44 @@
[
{
"name": "plwiki oldparser",
"dom": "cases/pl-big-oldparser/pl-big-oldparser.html",
"expected": "../cases/pl-big-oldparser/pl-big-oldparser-getText.json",
"config": "../data/plwiki-config.json",
"data": "../data/plwiki-data.json"
},
{
"name": "plwiki parsoid",
"dom": "cases/pl-big-parsoid/pl-big-parsoid.html",
"expected": "../cases/pl-big-parsoid/pl-big-parsoid-getText.json",
"config": "../data/plwiki-config.json",
"data": "../data/plwiki-data.json"
},
{
"name": "enwiki oldparser",
"dom": "cases/en-big-oldparser/en-big-oldparser.html",
"expected": "../cases/en-big-oldparser/en-big-oldparser-getText.json",
"config": "../data/enwiki-config.json",
"data": "../data/enwiki-data.json"
},
{
"name": "enwiki parsoid",
"dom": "cases/en-big-parsoid/en-big-parsoid.html",
"expected": "../cases/en-big-parsoid/en-big-parsoid-getText.json",
"config": "../data/enwiki-config.json",
"data": "../data/enwiki-data.json"
},
{
"name": "ckbwiki oldparser",
"dom": "cases/ckb-big-oldparser/ckb-big-oldparser.html",
"expected": "../cases/ckb-big-oldparser/ckb-big-oldparser-getText.json",
"config": "../data/ckbwiki-config.json",
"data": "../data/ckbwiki-data.json"
},
{
"name": "ckbwiki parsoid",
"dom": "cases/ckb-big-parsoid/ckb-big-parsoid.html",
"expected": "../cases/ckb-big-parsoid/ckb-big-parsoid-getText.json",
"config": "../data/ckbwiki-config.json",
"data": "../data/ckbwiki-data.json"
}
]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -90,4 +90,94 @@ class ThreadItemTest extends IntegrationTestCase {
return self::getJson( '../cases/transcluded.json' );
}
/**
* @dataProvider provideGetText
* @covers ::getText
* @covers \MediaWiki\Extension\DiscussionTools\CommentItem::getBodyText
* @covers \MediaWiki\Extension\DiscussionTools\ImmutableRange::cloneContents
*/
public function testGetText(
string $name, string $dom, string $expected, string $config, string $data
): void {
$dom = self::getHtml( $dom );
$expectedPath = $expected;
$expected = self::getJson( $expected );
$config = self::getJson( $config );
$data = self::getJson( $data );
$doc = self::createDocument( $dom );
$body = DOMCompat::getBody( $doc );
$this->setupEnv( $config, $data );
$parser = self::createParser( $body, $data );
$items = $parser->getThreadItems();
$output = [];
foreach ( $items as $item ) {
$output[ $item->getId() ] = CommentUtils::htmlTrim(
$item instanceof CommentItem ? $item->getBodyText( true ) : $item->getText()
);
}
// Optionally write updated content to the JSON files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteJsonFile( $expectedPath, $output );
}
self::assertEquals(
$expected,
$output,
$name
);
}
public function provideGetText(): array {
return self::getJson( '../cases/getText.json' );
}
/**
* @dataProvider provideGetHTML
* @covers ::getHTML
* @covers \MediaWiki\Extension\DiscussionTools\CommentItem::getBodyHTML
* @covers \MediaWiki\Extension\DiscussionTools\ImmutableRange::cloneContents
*/
public function testGetHTML(
string $name, string $dom, string $expected, string $config, string $data
): void {
$dom = self::getHtml( $dom );
$expectedPath = $expected;
$expected = self::getJson( $expected );
$config = self::getJson( $config );
$data = self::getJson( $data );
$doc = self::createDocument( $dom );
$body = DOMCompat::getBody( $doc );
$this->setupEnv( $config, $data );
$parser = self::createParser( $body, $data );
$items = $parser->getThreadItems();
$output = [];
foreach ( $items as $item ) {
$output[ $item->getId() ] = CommentUtils::htmlTrim(
$item instanceof CommentItem ? $item->getBodyHTML( true ) : $item->getHTML()
);
}
// Optionally write updated content to the JSON files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
self::overwriteJsonFile( $expectedPath, $output );
}
self::assertEquals(
$expected,
$output,
$name
);
}
public function provideGetHTML(): array {
return self::getJson( '../cases/getHTML.json' );
}
}