mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-17 21:21:35 +00:00
efe95494a8
Now it detect signatures generated by en.wp's {{Undated}} template, and signatures of people who do weird stuff to the timestamps. Bug: T275938 Change-Id: I27b07f6786ca5433a3c02a5fe68e4716d41401bb
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DiscussionTools\Tests\Unit;
|
|
|
|
use DOMDocument;
|
|
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
|
use MediaWiki\Extension\DiscussionTools\Tests\TestUtils;
|
|
use MediaWikiUnitTestCase;
|
|
|
|
/**
|
|
* @coversDefaultClass \MediaWiki\Extension\DiscussionTools\CommentUtils
|
|
*
|
|
* @group DiscussionTools
|
|
*/
|
|
class CommentUtilsTest extends MediaWikiUnitTestCase {
|
|
|
|
use TestUtils;
|
|
|
|
/**
|
|
* @dataProvider provideLinearWalk
|
|
* @covers ::linearWalk
|
|
*/
|
|
public function testLinearWalk( string $name, string $htmlPath, string $expectedPath ) {
|
|
$html = self::getHtml( $htmlPath );
|
|
// Slightly awkward to get the same output as in the JS version
|
|
$fragment = ( new DOMDocument() )->createDocumentFragment();
|
|
$fragment->appendXML( trim( $html ) );
|
|
$expected = self::getJson( $expectedPath );
|
|
|
|
$actual = [];
|
|
CommentUtils::linearWalk( $fragment, function ( $event, $node ) use ( &$actual ) {
|
|
$actual[] = "$event {$node->nodeName}({$node->nodeType})";
|
|
} );
|
|
|
|
$actualBackwards = [];
|
|
CommentUtils::linearWalkBackwards( $fragment, function ( $event, $node ) use ( &$actualBackwards ) {
|
|
$actualBackwards[] = "$event {$node->nodeName}({$node->nodeType})";
|
|
} );
|
|
|
|
// Optionally write updated content to the JSON files
|
|
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
|
|
self::overwriteJsonFile( $expectedPath, $actual );
|
|
}
|
|
|
|
self::assertEquals( $expected, $actual, $name );
|
|
|
|
$expectedBackwards = array_map( function ( $a ) {
|
|
return ( substr( $a, 0, 5 ) === 'enter' ? 'leave' : 'enter' ) . substr( $a, 5 );
|
|
}, array_reverse( $expected ) );
|
|
self::assertEquals( $expectedBackwards, $actualBackwards, $name . ' (backwards)' );
|
|
}
|
|
|
|
public function provideLinearWalk() : array {
|
|
return self::getJson( '../cases/linearWalk.json' );
|
|
}
|
|
|
|
}
|