Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4146422
CommentUtilsTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
CommentUtilsTest.php
View Options
<?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
Details
Attached
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)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment