mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-25 08:50:22 +00:00
ccd9e411d2
This is similar to the code we already have in JS tests, but instead of printing to the console where you have to copy-paste from, it just overwrites the files. Also, update all of the expected results by this method. Changes in the expected outputs: * In JSON files, the "warnings" are now always in the same place regardless of the type of the warning. * In all HTML files, self-closing tags now include the trailing slash, some characters are no longer encoded as entities when not necessary, and attributes may be single-quoted when that makes them shorter. * In Parsoid HTML files, the header is no longer terribly mangled. Other notes: * CommentParserTest.php: Change the output of serializeComments() to be in similar order as in JS, to reduce the diffs in this commit and because it's a better order for humans. * modifier.test.js: Remove some hacks that were working around small inconsistencies between the previous expected outputs and the actual outputs. Change-Id: I9f764640dae823321c0ac35898fa4db03f1ca364
92 lines
2.5 KiB
PHP
92 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|
|
|
use MediaWiki\Extension\DiscussionTools\CommentItem;
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
|
use MediaWiki\Extension\DiscussionTools\HeadingItem;
|
|
use MediaWiki\Extension\DiscussionTools\ImmutableRange;
|
|
use MediaWiki\Extension\DiscussionTools\ThreadItem;
|
|
|
|
/**
|
|
* @coversDefaultClass \MediaWiki\Extension\DiscussionTools\ThreadItem
|
|
*
|
|
* @group DiscussionTools
|
|
*/
|
|
class ThreadItemTest extends CommentTestCase {
|
|
/**
|
|
* @dataProvider provideAuthors
|
|
* @covers ::getAuthorsBelow
|
|
*/
|
|
public function testGetAuthorsBelow( array $thread, array $expected ) : void {
|
|
$doc = $this->createDocument( '' );
|
|
$node = $doc->createElement( 'div' );
|
|
$range = new ImmutableRange( $node, 0, $node, 0 );
|
|
|
|
$makeThreadItem = function ( array $arr ) use ( &$makeThreadItem, $range ) : ThreadItem {
|
|
if ( $arr['type'] === 'comment' ) {
|
|
$item = new CommentItem( 1, $range );
|
|
$item->setAuthor( $arr['author'] );
|
|
} else {
|
|
$item = new HeadingItem( $range );
|
|
}
|
|
foreach ( $arr['replies'] as $reply ) {
|
|
$item->addReply( $makeThreadItem( $reply ) );
|
|
}
|
|
return $item;
|
|
};
|
|
|
|
$threadItem = $makeThreadItem( $thread );
|
|
|
|
self::assertEquals( $expected, $threadItem->getAuthorsBelow() );
|
|
}
|
|
|
|
public function provideAuthors() : array {
|
|
return self::getJson( '../cases/authors.json' );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideTranscludedFrom
|
|
* @covers ::getTranscludedFrom
|
|
* @covers \MediaWiki\Extension\DiscussionTools\CommentUtils::unwrapParsoidSections
|
|
*/
|
|
public function testGetTranscludedFrom(
|
|
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 );
|
|
|
|
$this->setupEnv( $config, $data );
|
|
|
|
$doc = self::createDocument( $dom );
|
|
$container = $doc->getElementsByTagName( 'body' )->item( 0 );
|
|
|
|
CommentUtils::unwrapParsoidSections( $container );
|
|
|
|
$parser = self::createParser( $container, $data );
|
|
$comments = $parser->getCommentItems();
|
|
|
|
$transcludedFrom = [];
|
|
foreach ( $comments as $comment ) {
|
|
$transcludedFrom[ $comment->getId() ] = $comment->getTranscludedFrom();
|
|
}
|
|
|
|
self::assertEquals(
|
|
$expected,
|
|
$transcludedFrom,
|
|
$name
|
|
);
|
|
|
|
// Uncomment this to write updated content to the JSON files:
|
|
// self::overwriteJsonFile( $expectedPath, $transcludedFrom );
|
|
}
|
|
|
|
public function provideTranscludedFrom() : array {
|
|
return self::getJson( '../cases/transcluded.json' );
|
|
}
|
|
|
|
}
|