mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-25 00:38:33 +00:00
Merge "Add some tests covering ThreadItem::getHTML() and related methods"
This commit is contained in:
commit
8581e4d3d7
209
tests/cases/ckb-big-oldparser/ckb-big-oldparser-getHTML.json
Normal file
209
tests/cases/ckb-big-oldparser/ckb-big-oldparser-getHTML.json
Normal file
File diff suppressed because one or more lines are too long
209
tests/cases/ckb-big-oldparser/ckb-big-oldparser-getText.json
Normal file
209
tests/cases/ckb-big-oldparser/ckb-big-oldparser-getText.json
Normal file
File diff suppressed because one or more lines are too long
209
tests/cases/ckb-big-parsoid/ckb-big-parsoid-getHTML.json
Normal file
209
tests/cases/ckb-big-parsoid/ckb-big-parsoid-getHTML.json
Normal file
File diff suppressed because one or more lines are too long
209
tests/cases/ckb-big-parsoid/ckb-big-parsoid-getText.json
Normal file
209
tests/cases/ckb-big-parsoid/ckb-big-parsoid-getText.json
Normal file
File diff suppressed because one or more lines are too long
1283
tests/cases/en-big-oldparser/en-big-oldparser-getHTML.json
Normal file
1283
tests/cases/en-big-oldparser/en-big-oldparser-getHTML.json
Normal file
File diff suppressed because one or more lines are too long
1283
tests/cases/en-big-oldparser/en-big-oldparser-getText.json
Normal file
1283
tests/cases/en-big-oldparser/en-big-oldparser-getText.json
Normal file
File diff suppressed because one or more lines are too long
1283
tests/cases/en-big-parsoid/en-big-parsoid-getHTML.json
Normal file
1283
tests/cases/en-big-parsoid/en-big-parsoid-getHTML.json
Normal file
File diff suppressed because one or more lines are too long
1283
tests/cases/en-big-parsoid/en-big-parsoid-getText.json
Normal file
1283
tests/cases/en-big-parsoid/en-big-parsoid-getText.json
Normal file
File diff suppressed because one or more lines are too long
44
tests/cases/getHTML.json
Normal file
44
tests/cases/getHTML.json
Normal 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
44
tests/cases/getText.json
Normal 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"
|
||||
}
|
||||
]
|
206
tests/cases/pl-big-oldparser/pl-big-oldparser-getHTML.json
Normal file
206
tests/cases/pl-big-oldparser/pl-big-oldparser-getHTML.json
Normal file
File diff suppressed because one or more lines are too long
206
tests/cases/pl-big-oldparser/pl-big-oldparser-getText.json
Normal file
206
tests/cases/pl-big-oldparser/pl-big-oldparser-getText.json
Normal file
File diff suppressed because one or more lines are too long
206
tests/cases/pl-big-parsoid/pl-big-parsoid-getHTML.json
Normal file
206
tests/cases/pl-big-parsoid/pl-big-parsoid-getHTML.json
Normal file
File diff suppressed because one or more lines are too long
206
tests/cases/pl-big-parsoid/pl-big-parsoid-getText.json
Normal file
206
tests/cases/pl-big-parsoid/pl-big-parsoid-getText.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -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' );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue