Page MenuHomeWickedGov Phorge

CommentUtilsTest.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

CommentUtilsTest.php

<?php
namespace MediaWiki\Extension\DiscussionTools\Tests\Unit;
use MediaWiki\Extension\DiscussionTools\CommentUtils;
use MediaWiki\Extension\DiscussionTools\Tests\TestUtils;
use MediaWikiUnitTestCase;
/**
* @group DiscussionTools
* @covers \MediaWiki\Extension\DiscussionTools\CommentUtils
*/
class CommentUtilsTest extends MediaWikiUnitTestCase {
use TestUtils;
/**
* @dataProvider provideLinearWalk
*/
public function testLinearWalk( string $name, string $htmlPath, string $expectedPath ) {
$html = static::getHtml( $htmlPath );
$doc = static::createDocument( $html );
$expected = static::getJson( $expectedPath );
$actual = [];
CommentUtils::linearWalk( $doc, static function ( $event, $node ) use ( &$actual ) {
$actual[] = "$event {$node->nodeName}({$node->nodeType})";
} );
$actualBackwards = [];
CommentUtils::linearWalkBackwards( $doc, static function ( $event, $node ) use ( &$actualBackwards ) {
$actualBackwards[] = "$event {$node->nodeName}({$node->nodeType})";
} );
// Optionally write updated content to the JSON files
if ( getenv( 'DISCUSSIONTOOLS_OVERWRITE_TESTS' ) ) {
static::overwriteJsonFile( $expectedPath, $actual );
}
static::assertEquals( $expected, $actual, $name );
$expectedBackwards = array_map(
static fn ( $a ) => ( $a[0] === 'e' ? 'leave' : 'enter' ) . substr( $a, 5 ),
array_reverse( $expected )
);
static::assertEquals( $expectedBackwards, $actualBackwards, $name . ' (backwards)' );
}
public static function provideLinearWalk(): array {
return static::getJson( '../cases/linearWalk.json' );
}
}

File Metadata

Mime Type
text/x-php
Expires
Aug 19 2026, 18:01 (5 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
90/58/01e10f62c2996fc2c5dbb36716d7
Default Alt Text
CommentUtilsTest.php (1 KB)

Event Timeline