<?php
class BalancerTest extends MediaWikiTestCase {
- private $balancer;
/**
* Anything that needs to happen before your tests should go here.
// This makes sure that all the various cleanup and restorations
// happen as they should (including the restoration for setMwGlobals).
parent::setUp();
- $this->balancer = new MediaWiki\Tidy\Balancer( [
- 'strict' => false, /* not strict */
- 'allowedHtmlElements' => null, /* no sanitization */
- 'tidyCompat' => false, /* standard parser */
- 'allowComments' => true, /* comment parsing */
- ] );
}
/**
* @covers MediaWiki\Tidy\Balancer::balance
* @dataProvider provideBalancerTests
*/
- public function testBalancer( $description, $input, $expected ) {
- $output = $this->balancer->balance( $input );
+ public function testBalancer( $description, $input, $expected, $useTidy ) {
+ $balancer = new MediaWiki\Tidy\Balancer( [
+ 'strict' => false, /* not strict */
+ 'allowedHtmlElements' => null, /* no sanitization */
+ 'tidyCompat' => $useTidy, /* standard parser */
+ 'allowComments' => true, /* comment parsing */
+ ] );
+ $output = $balancer->balance( $input );
// Ignore self-closing tags
$output = preg_replace( '/\s*\/>/', '>', $output );
// Skip tests involving unusual doctypes.
continue;
}
- $literalre = "~ <rdar: | <isindex | < /? (
+ $literalre = "~ <rdar: | < /? (
html | head | body | frame | frameset | plaintext
) > ~xi";
if ( preg_match( $literalre, $case['data'] ) ) {
$tests[] = [
$filename, # use better description?
$data,
- $html
+ $html,
+ false # strict HTML5 compat mode, no tidy
];
}
}
+
+ # Some additional tests for mediawiki-specific features
+ $tests[] = [
+ 'Round-trip serialization for <pre>/<listing>/<textarea>',
+ "<pre>\n\na</pre><listing>\n\nb</listing><textarea>\n\nc</textarea>",
+ "<pre>\n\na</pre><listing>\n\nb</listing><textarea>\n\nc</textarea>",
+ true # use the tidy-compatible mode
+ ];
+
return $tests;
}
}