mediawiki-extensions-Discus.../tests/phpunit/ThreadItemTest.php
Ed Sanders 7ae5bbf384 Move #getAuthors from parser to ThreadItem
Change-Id: I16e513000e5366b3044b17a99da07d8d0f47a61f
2020-07-20 15:13:59 +01:00

48 lines
1.3 KiB
PHP

<?php
namespace MediaWiki\Extension\DiscussionTools\Tests;
use MediaWiki\Extension\DiscussionTools\CommentItem;
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' );
}
}