mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
PHP: Use DOMUtils::parseHTML
Change-Id: Ifed0ab99b3da9f8b35ca815ada45f804a8756c1b
This commit is contained in:
parent
58f6d8ca56
commit
3e6ab2c4d2
|
@ -27,7 +27,7 @@ class CommentModifierTest extends CommentTestCase {
|
|||
$this->setupEnv( $config, $data );
|
||||
|
||||
$doc = self::createDocument( $dom );
|
||||
$container = $doc->documentElement->firstChild;
|
||||
$container = $doc->getElementsByTagName( 'body' )->item( 0 )->firstChild;
|
||||
|
||||
$parser = self::createParser( $data );
|
||||
$comments = $parser->getComments( $container );
|
||||
|
@ -68,7 +68,7 @@ class CommentModifierTest extends CommentTestCase {
|
|||
$this->setupEnv( $config, $data );
|
||||
|
||||
$doc = self::createDocument( $dom );
|
||||
$container = $doc->documentElement->firstChild;
|
||||
$container = $doc->getElementsByTagName( 'body' )->item( 0 )->firstChild;
|
||||
|
||||
$parser = self::createParser( $data );
|
||||
$comments = $parser->getComments( $container );
|
||||
|
@ -99,7 +99,7 @@ class CommentModifierTest extends CommentTestCase {
|
|||
public function testUnwrapList( string $name, string $html, int $index, string $expected ) : void {
|
||||
$doc = self::createDocument( '<div>' . $html . '</div>' );
|
||||
$expectedDoc = self::createDocument( '<div>' . $expected . '</div>' );
|
||||
$container = $doc->documentElement->firstChild->firstChild;
|
||||
$container = $doc->getElementsByTagName( 'body' )->item( 0 )->firstChild;
|
||||
|
||||
CommentModifier::unwrapList( $container->childNodes[$index] );
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace MediaWiki\Extension\DiscussionTools\Tests;
|
|||
use DateTimeImmutable;
|
||||
use DOMElement;
|
||||
use DOMNode;
|
||||
use Error;
|
||||
use MediaWiki\Extension\DiscussionTools\CommentItem;
|
||||
use MediaWiki\Extension\DiscussionTools\CommentParser;
|
||||
use MediaWiki\Extension\DiscussionTools\CommentUtils;
|
||||
|
@ -248,15 +249,15 @@ class CommentParserTest extends CommentTestCase {
|
|||
$parser = self::createParser( $data );
|
||||
|
||||
$doc = self::createDocument( $dom );
|
||||
$container = $doc->documentElement->firstChild;
|
||||
$body = $doc->getElementsByTagName( 'body' )->item( 0 );
|
||||
|
||||
$comments = $parser->getComments( $container );
|
||||
$comments = $parser->getComments( $body );
|
||||
$threads = $parser->groupThreads( $comments );
|
||||
|
||||
$processedThreads = [];
|
||||
|
||||
foreach ( $threads as $i => $thread ) {
|
||||
$thread = self::serializeComments( $thread, $container );
|
||||
$thread = self::serializeComments( $thread, $body );
|
||||
$thread = json_decode( json_encode( $thread ), true );
|
||||
$processedThreads[] = $thread;
|
||||
self::assertEquals( $expected[$i], $processedThreads[$i], $name . ' section ' . $i );
|
||||
|
@ -285,9 +286,9 @@ class CommentParserTest extends CommentTestCase {
|
|||
$parser = self::createParser( $data );
|
||||
|
||||
$doc = self::createDocument( $dom );
|
||||
$container = $doc->documentElement->firstChild;
|
||||
$container = $doc->getElementsByTagName( 'body' )->item( 0 )->firstChild;
|
||||
|
||||
CommentUtils::unwrapParsoidSections( $doc->documentElement );
|
||||
CommentUtils::unwrapParsoidSections( $container );
|
||||
|
||||
$comments = $parser->getComments( $container );
|
||||
$threads = $parser->groupThreads( $comments );
|
||||
|
|
|
@ -6,6 +6,7 @@ use DOMDocument;
|
|||
use MediaWiki\Extension\DiscussionTools\CommentParser;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWikiTestCase;
|
||||
use Wikimedia\Parsoid\Utils\DOMUtils;
|
||||
|
||||
abstract class CommentTestCase extends MediaWikiTestCase {
|
||||
|
||||
|
@ -16,9 +17,8 @@ abstract class CommentTestCase extends MediaWikiTestCase {
|
|||
* @return DOMDocument
|
||||
*/
|
||||
protected static function createDocument( string $html ) : DOMDocument {
|
||||
$doc = new DOMDocument();
|
||||
$doc = DOMUtils::parseHTML( $html );
|
||||
$doc->preserveWhiteSpace = false;
|
||||
$doc->loadHTML( '<?xml encoding="utf-8" ?>' . $html, LIBXML_NOERROR );
|
||||
return $doc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue