",
'multiple-unclosed-formatting-tags' );
}
/**
* @covers \Wikimedia\Parsoid\Wt2Html\ParserPipeline
*/
public function testUnclosedIBTagsInHeadings(): void {
$desc = "should detect unclosed wikitext i tags in headings";
$result = $this->parseWT( "==foo
''a==\nx" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'unclosed-quotes-in-heading', $result[0]['type'], $desc );
$this->assertEquals( 'i', $result[0]['params']['name'], $desc );
$this->assertEquals( 'h2', $result[0]['params']['ancestorName'], $desc );
$desc = "should detect unclosed wikitext b tags in headings";
$result = $this->parseWT( "==foo
'''a==\nx" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'unclosed-quotes-in-heading', $result[0]['type'], $desc );
$this->assertEquals( 'b', $result[0]['params']['name'], $desc );
$this->assertEquals( 'h2', $result[0]['params']['ancestorName'], $desc );
$desc = "should not detect unclosed HTML i/b tags in headings";
$result = $this->parseWT( "==foo
a==\nx\n==foo
a==\ny" );
$this->assertEquals( 2, count( $result ), $desc );
$this->assertEquals( 'missing-end-tag', $result[0]['type'], $desc );
$this->assertEquals( 'missing-end-tag', $result[1]['type'], $desc );
}
/**
* @covers \Wikimedia\Parsoid\Wt2Html\ParserPipeline
*/
public function testMultilineHtmlTablesInLists(): void {
$desc = "should detect multiline HTML tables in lists (li)";
$result = $this->parseWT( "*
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'multiline-html-table-in-list', $result[0]['type'], $desc );
$this->assertEquals( 'table', $result[0]['params']['name'], $desc );
$this->assertEquals( 'li', $result[0]['params']['ancestorName'], $desc );
$desc = "should detect multiline HTML tables in lists (table in div)";
$result = $this->parseWT( "*
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'multiline-html-table-in-list', $result[0]['type'], $desc );
$this->assertEquals( 'table', $result[0]['params']['name'], $desc );
$this->assertEquals( 'li', $result[0]['params']['ancestorName'], $desc );
$desc = "should detect multiline HTML tables in lists (dt)";
$result = $this->parseWT( ";
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'multiline-html-table-in-list', $result[0]['type'], $desc );
$this->assertEquals( 'table', $result[0]['params']['name'], $desc );
$this->assertEquals( 'dt', $result[0]['params']['ancestorName'], $desc );
$desc = "should detect multiline HTML tables in lists (dd)";
$result = $this->parseWT( ":
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'multiline-html-table-in-list', $result[0]['type'], $desc );
$this->assertEquals( 'table', $result[0]['params']['name'], $desc );
$this->assertEquals( 'dd', $result[0]['params']['ancestorName'], $desc );
$desc = "should not detect multiline HTML tables in HTML lists";
$this->expectEmptyResults( $desc, "
" );
$desc = "should not detect single-line HTML tables in lists";
$this->expectEmptyResults( $desc, "*
" );
$desc = "should not detect multiline HTML tables in ref tags";
$this->expectEmptyResults( $desc,
"a
" );
}
/**
* @covers \Wikimedia\Parsoid\Wt2Html\ParserPipeline
*/
public function testLintIssueInRefTags(): void {
$desc = "should attribute linter issues to the ref tag";
$result = $this->parseWT( "a
[x] " );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'missing-end-tag', $result[0]['type'], $desc );
$this->assertEquals( [ 7, 11, 3, 0 ], $result[0]['dsr'], $desc );
$this->assertTrue( isset( $result[0]['params'] ), $desc );
$this->assertEquals( 'b', $result[0]['params']['name'], $desc );
$desc = "should attribute linter issues to the ref tag even if references is templated";
$result = $this->parseWT( "a
[x] {{1x|
}}" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'missing-end-tag', $result[0]['type'], $desc );
$this->assertEquals( [ 7, 11, 3, 0 ], $result[0]['dsr'], $desc );
$this->assertTrue( isset( $result[0]['params'] ), $desc );
$this->assertEquals( 'b', $result[0]['params']['name'], $desc );
$desc = "should attribute linter issues to the ref tag even when " .
"ref and references are both templated";
$wt = "a
[x] b
[{{1x|x}}] " .
"{{1x|c
[y]}} {{1x|
}}";
$result = $this->parseWT( $wt );
$this->assertEquals( 3, count( $result ), $desc );
$this->assertEquals( 'missing-end-tag', $result[0]['type'], $desc );
$this->assertEquals( [ 7, 11, 3, 0 ], $result[0]['dsr'], $desc );
$this->assertTrue( isset( $result[0]['params'] ), $desc );
$this->assertEquals( 'b', $result[0]['params']['name'], $desc );
$this->assertEquals( 'missing-end-tag', $result[1]['type'], $desc );
$this->assertEquals( [ 25, 36, null, null ], $result[1]['dsr'], $desc );
$this->assertTrue( isset( $result[1]['params'] ), $desc );
$this->assertEquals( 'b', $result[1]['params']['name'], $desc );
$this->assertTrue( isset( $result[1]['templateInfo'] ), $desc );
$this->assertEquals( '1x', $result[1]['templateInfo']['name'], $desc );
$this->assertEquals( 'missing-end-tag', $result[2]['type'], $desc );
$this->assertEquals( [ 43, 67, null, null ], $result[2]['dsr'], $desc );
$this->assertTrue( isset( $result[2]['params'] ), $desc );
$this->assertEquals( 'b', $result[2]['params']['name'], $desc );
$this->assertTrue( isset( $result[2]['templateInfo'] ), $desc );
$this->assertEquals( '1x', $result[2]['templateInfo']['name'], $desc );
$desc = "should attribute linter issues properly when ref " .
"tags are in non-templated references tag";
$wt = "a
x b
" .
"[{{1x|boo}}] ";
$result = $this->parseWT( $wt );
$this->assertEquals( 2, count( $result ), $desc );
$this->assertEquals( 'missing-end-tag', $result[0]['type'], $desc );
$this->assertEquals( [ 7, 11, 3, 0 ], $result[0]['dsr'], $desc );
$this->assertTrue( isset( $result[0]['params'] ), $desc );
$this->assertEquals( 's', $result[0]['params']['name'], $desc );
$this->assertEquals( 'missing-end-tag', $result[1]['type'], $desc );
$this->assertEquals( [ 64, 77, null, null ], $result[1]['dsr'], $desc );
$this->assertTrue( isset( $result[1]['params'] ), $desc );
$this->assertEquals( 'b', $result[1]['params']['name'], $desc );
$this->assertTrue( isset( $result[1]['templateInfo'] ), $desc );
$this->assertEquals( '1x', $result[1]['templateInfo']['name'], $desc );
// PORT-FIXME this code is not yet supported
// $desc = "should not get into a cycle trying to lint ref in ref";
// return parseWT(
// "{{#tag:ref|
|name='x'}}{{#tag:ref|" .
// "
|name='y'}}
" );
// .then(function() {
// return parseWT("{{#tag:ref|
|name=x}}");
}
/**
* @covers \Wikimedia\Parsoid\Wt2Html\ParserPipeline
*/
public function testDivSpanFlipTidyBug(): void {
$desc = "should not trigger this lint when there are no style or class attributes";
$this->expectEmptyResults( $desc, "
x
" );
$desc = "should trigger this lint when there is a style or class attribute (1)";
$result = $this->parseWT( "
x
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'misc-tidy-replacement-issues', $result[0]['type'], $desc );
$this->assertEquals( 'div-span-flip', $result[0]['params']['subtype'], $desc );
$desc = "should trigger this lint when there is a style or class attribute (2)";
$result = $this->parseWT( "
x
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'misc-tidy-replacement-issues', $result[0]['type'], $desc );
$this->assertEquals( 'div-span-flip', $result[0]['params']['subtype'], $desc );
$desc = "should trigger this lint when there is a style or class attribute (3)";
$result = $this->parseWT( "
x
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'misc-tidy-replacement-issues', $result[0]['type'], $desc );
$this->assertEquals( 'div-span-flip', $result[0]['params']['subtype'], $desc );
$desc = "should trigger this lint when there is a style or class attribute (4)";
$result = $this->parseWT( "
x
" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'misc-tidy-replacement-issues', $result[0]['type'], $desc );
$this->assertEquals( 'div-span-flip', $result[0]['params']['subtype'], $desc );
}
/**
* @covers \Wikimedia\Parsoid\Wt2Html\ParserPipeline
*/
public function testWikilinkInExternalLink(): void {
$desc = "should lint wikilink in external link correctly";
$result = $this->parseWT( "[http://google.com This is [[Google]]'s search page]" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'wikilink-in-extlink', $result[0]['type'], $desc );
$this->assertEquals( [ 0, 52, 19, 1 ], $result[0]['dsr'], $desc );
$desc = "should lint wikilink in external link correctly";
$result = $this->parseWT(
"[http://stackexchange.com is the official website for [[Stack Exchange]]]" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'wikilink-in-extlink', $result[0]['type'], $desc );
$this->assertEquals( [ 0, 73, 26, 1 ], $result[0]['dsr'], $desc );
$desc = "should lint wikilink in external link correctly";
$result = $this->parseWT(
"{{1x|foo
and [http://google.com [[Google]] bar] baz
}}" );
$this->assertSame( 1, count( $result ), $desc );
$this->assertEquals( 'wikilink-in-extlink', $result[0]['type'], $desc );
$this->assertEquals( [ 0, 66, null, null ], $result[0]['dsr'], $desc );
$this->assertTrue( isset( $result[0]['templateInfo'] ), $desc );
$this->assertEquals( '1x', $result[0]['templateInfo']['name'], $desc );
}
}