X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/tests/phpunit/includes/tidy/RemexDriverTest.php diff --git a/tests/phpunit/includes/tidy/RemexDriverTest.php b/tests/phpunit/includes/tidy/RemexDriverTest.php new file mode 100644 index 00000000..6b16cbf6 --- /dev/null +++ b/tests/phpunit/includes/tidy/RemexDriverTest.php @@ -0,0 +1,297 @@ +x

" + ], + [ + 'No p-wrap of blank node', + " ", + " " + ], + [ + 'p-wrap terminated by div', + "x
", + "

x

" + ], + [ + 'p-wrap not terminated by span', + "x", + "

x

" + ], + [ + 'An element is non-blank and so gets p-wrapped', + "", + "

" + ], + [ + 'The blank flag is set after a block-level element', + "
", + "
" + ], + [ + 'Blank detection between two block-level elements', + "
", + "
" + ], + [ + 'But p-wrapping of non-blank content works after an element', + "
x", + "

x

" + ], + [ + 'p-wrapping between two block-level elements', + "
x
", + "

x

" + ], + [ + 'p-wrap inside blockquote', + "
x
", + "

x

" + ], + [ + 'A comment is blank for p-wrapping purposes', + "", + "" + ], + [ + 'A comment is blank even when a p-wrap was opened by a text node', + " ", + " " + ], + [ + 'A comment does not open a p-wrap', + "x", + "

x

" + ], + [ + 'A comment does not close a p-wrap', + "x", + "

x

" + ], + [ + 'Empty li', + "", + "" + ], + [ + 'li with element', + "", + "" + ], + [ + 'li with text', + "", + "" + ], + [ + 'Empty tr', + "
", + "
" + ], + [ + 'Empty p', + "

\n

", + "

\n

" + ], + [ + 'No p-wrapping of an inline element which contains a block element (T150317)', + "
x
", + "
x
" + ], + [ + 'p-wrapping of an inline element which contains an inline element', + "x", + "

x

" + ], + [ + 'p-wrapping is enabled in a blockquote in an inline element', + "
x
", + "

x

" + ], + [ + 'All bare text should be p-wrapped even when surrounded by block tags', + "
x
y
z", + "

x

y

z

" + ], + [ + 'Split tag stack 1', + "x
y
z
", + "

x

y

z

" + ], + [ + 'Split tag stack 2', + "
y
z
", + "
y

z

" + ], + [ + 'Split tag stack 3', + "x
y
", + "

x

y
" + ], + [ + 'Split tag stack 4 (modified to use splittable tag)', + "abc
d
e
", + "

abc

d

e

" + ], + [ + "Split tag stack regression check 1", + "x
y
", + "

x

y
" + ], + [ + "Split tag stack regression check 2 (modified to use splittable tag)", + "a
d
e
", + "

a

d

e

" + ], + // Simple tests from pwrap.js + [ + 'Simple pwrap test 1', + 'a', + '

a

' + ], + [ + ' is not a splittable tag, but gets p-wrapped in simple wrapping scenarios', + 'a', + '

a

' + ], + [ + 'Simple pwrap test 3', + 'x
a
b
y', + '

x

a
b

y

' + ], + [ + 'Simple pwrap test 4', + 'x
a
b
y', + '

x

a
b

y

' + ], + // Complex tests from pwrap.js + [ + 'Complex pwrap test 1', + 'x
a
y
', + '

x

a

y

' + ], + [ + 'Complex pwrap test 2', + 'abc
d
e
f', + '

abc

d

ef

' + ], + [ + 'Complex pwrap test 3', + 'abc
d
e
', + '

abc

d

e

' + ], + [ + 'Complex pwrap test 4', + 'x
y
', + '

x

y
' + ], + [ + 'Complex pwrap test 5', + 'a
d
e
', + '

a

d

e

' + ], + [ + 'Complex pwrap test 6', + 'a
b
cd
e
f
g
', + // @codingStandardsIgnoreStart Generic.Files.LineLength.TooLong + // PHP 5 does not allow concatenation in initialisation of a class static variable + '

a

b

cd

e

fg

' + // @codingStandardsIgnoreEnd + ], + /* FIXME the second causes a stack split which clones the even + * though no

is actually generated + [ + 'Complex pwrap test 7', + '

x
y
z
', + '
x
y
z
' + ], + */ + // New local tests + [ + 'Blank text node after block end', + 'x
y
z
', + '

x

y

z

' + ], + [ + 'Text node fostering (FIXME: wrap missing)', + 'x
', + 'x
' + ], + [ + 'Blockquote fostering', + '
x
', + '

x

' + ], + [ + 'Block element fostering', + '
x', + '
x
' + ], + [ + 'Formatting element fostering (FIXME: wrap missing)', + 'x', + 'x
' + ], + [ + 'AAA clone of p-wrapped element (FIXME: empty b)', + 'x

yz

', + '

x

yz

', + ], + [ + 'AAA with fostering (FIXME: wrap missing)', + '1

23

', + '1

23

' + ], + ]; + + public function provider() { + return self::$remexTidyTestData; + } + + /** + * @dataProvider provider + * @covers MediaWiki\Tidy\RemexCompatFormatter + * @covers MediaWiki\Tidy\RemexCompatMunger + * @covers MediaWiki\Tidy\RemexDriver + * @covers MediaWiki\Tidy\RemexMungerData + */ + public function testTidy( $desc, $input, $expected ) { + $r = new MediaWiki\Tidy\RemexDriver( [] ); + $result = $r->tidy( $input ); + $this->assertEquals( $expected, $result, $desc ); + } + + public function html5libProvider() { + $files = json_decode( file_get_contents( __DIR__ . '/html5lib-tests.json' ), true ); + $tests = []; + foreach ( $files as $file => $fileTests ) { + foreach ( $fileTests as $i => $test ) { + $tests[] = [ "$file:$i", $test['data'] ]; + } + } + return $tests; + } + + /** + * This is a quick and dirty test to make sure none of the html5lib tests + * generate exceptions. We don't really know what the expected output is. + * + * @dataProvider html5libProvider + * @coversNothing + */ + public function testHtml5Lib( $desc, $input ) { + $r = new MediaWiki\Tidy\RemexDriver( [] ); + $result = $r->tidy( $input ); + $this->assertTrue( true, $desc ); + } +}